ExperimentalGear/scripts/gameplay/score_panel.lua

96 lines
2.1 KiB
Lua

local bgImage = gfx.CreateSkinImage("gameplay/score_panel/bg.png", 0)
local desw = 1080;
local desh = 1920;
local isLandscape = false;
function load_number_image(path)
local images = {}
for i = 0, 9 do
images[i + 1] = gfx.CreateSkinImage(string.format("%s/%d.png", path, i), 0)
end
return images
end
local scoreNumbers = load_number_image('score_num')
function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern)
scale = scale or 1;
kern = kern or 1;
local tw, th = gfx.ImageSize(images[1])
tw = tw * scale;
th = th * scale;
x = x + (tw * (digits - 1)) / 2
y = y - th / 2
for i = 1, digits do
local mul = 10 ^ (i - 1)
local digit = math.floor(num / mul) % 10
local a = alpha
if is_dim and num < mul then
a = 0.4
end
gfx.BeginPath()
gfx.ImageRect(x, y, tw, th, images[digit + 1], a, 0)
x = x - (tw * kern)
end
end
local tickTransitions = function (deltaTime)
end
local render = function (deltaTime, score, maxChain)
gfx.Save();
local resx, resy = game.GetResolution();
isLandscape = resx > resy;
if (isLandscape) then
desw = 1920;
desh = 1080;
else
desw = 1080;
desh = 1920;
end
tickTransitions(deltaTime)
local x = desw;
local y = isLandscape and 5 or 330;
if (isLandscape) then
gfx.Translate(x, 0);
x=0
end
gfx.BeginPath();
gfx.ImageRect(
x-740*0.61, -- WHY IS THERE DIFFERENT SCALING FOR THIS TOO????
y,
740*0.61,
320*0.61,
bgImage,
1,
0
);
draw_number(x-309.4, y + 83, 1.0, score/10000, 4, scoreNumbers, true, 0.38, 1.12)
draw_number(x-113.4, y + 90, 1.0, score, 4, scoreNumbers, true, 0.28, 1.12)
-- Draw max chain
gfx.BeginPath();
gfx.LoadSkinFont('Digital-Serial-Bold.ttf')
gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(30);
gfx.FillColor(255,255,255,255);
gfx.Text(string.format("%04d", maxChain), x-281.4, y+155);
gfx.Restore();
end
return {
render=render
}