ExperimentalGear/scripts/gameplay/banner.lua

62 lines
1.4 KiB
Lua
Raw Normal View History

local bannerBaseImage = gfx.CreateSkinImage("gameplay/banner/base.png", 0)
local BANNER_W = 1080;
local BANNER_H = 368;
local drawScoreboard = function (users)
if (users == nil) then
return
end
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FontSize(32)
local x = 16;
local y = 500;
gfx.LoadSkinFont("Digital-Serial-Bold.ttf")
for i, u in ipairs(users) do
local y = y + 40;
gfx.FontSize(26)
gfx.Text(u.name, x, y)
gfx.FontSize(26)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.Text(string.format("%04d", math.floor(u.score/10000)), x+128, y)
local lastFourDigits = ((u.score / 10000) - math.floor(u.score / 10000))*10000
gfx.FontSize(22)
gfx.Text(string.format("%04d", math.floor(lastFourDigits)), x+186, y+1)
end
end
local render = function (deltaTime, users)
2021-11-25 18:49:50 +01:00
local resx, resy = game.GetResolution();
if (resx > resy) then
return
end
-- Get the banner downscaled in whatever resolution it is, while maintaining the aspect ratio
local tw,th = gfx.ImageSize(bannerBaseImage);
BANNER_H = th * (1080/tw);
gfx.BeginPath();
gfx.ImageRect(
0,
0,
BANNER_W,
BANNER_H,
bannerBaseImage,
1,
0
);
drawScoreboard(users);
end
return {
render=render
}