Files
YataiDONNijiiro/Scripts/result/high_score_indicator.lua
T
2026-11-23 11:20:21 -05:00

67 lines
2.5 KiB
Lua

HighScoreIndicator = {}
HighScoreIndicator.__index = HighScoreIndicator
-- `border` is already in 1080p stage px, so create_text wants border / screen_scale.
local function outline(border) return border / tex.get_screen_scale() end
local TEXT_CX_REL = 154.4
local TEXT_CY_REL = 31.6
local BAR_BASE_X = { [0] = 64, [1] = 1020 } -- texture.json high_score frame 0 (1P) / 1 (2P)
local BAR_BASE_Y = 266
function HighScoreIndicator.new(score_diff, is_2p)
local self = setmetatable({}, HighScoreIndicator)
self.start_ms = nil
self.y_offset = 24
self.fade_val = 0
self.score_diff = score_diff
self.is_2p = is_2p
self.t_label = tex.get_texture("result/score/high_score")
self.t_num = tex.get_texture("result/score/high_score_num")
self.sc_margin = 14
self.text = text.create_text("result_topscore_text", { 255, 255, 255, 255 }, { 70, 35, 10, 255 },
false, outline(4.0), 0)
return self
end
-- the bar drops in from 24 px below on 5 frames, overshoots 22 px up, settles through a dip of 7 px
local function bar_pose(f)
local a = 1 - (1 - math.min(f / 5, 1)) ^ 2
local y
if f < 5 then y = 24 - 46 * a
elseif f < 9 then y = -22 + 22 * ((f - 5) / 4) ^ 2
elseif f < 13 then y = 7 * (f - 9) / 4
else y = 7 * (1 - math.min((f - 13) / 5, 1)) ^ 2 end
return y, a
end
function HighScoreIndicator:update(current_ms)
if not self.start_ms then self.start_ms = current_ms end
local f = (current_ms - self.start_ms) * 0.06
self.y_offset, self.fade_val = bar_pose(f)
end
function HighScoreIndicator:draw()
local p_idx = self.is_2p and 1 or 0
local y = self.y_offset
local fade = self.fade_val
if self.t_label then tex.draw_texture(self.t_label, { y = y, fade = fade, index = p_idx }) end
-- Live caption, centred on the arcade's ink-centre target.
if self.text then
local cx = BAR_BASE_X[p_idx] + TEXT_CX_REL
local cy = BAR_BASE_Y + TEXT_CY_REL + y
self.text:draw({
x = math.floor(cx - self.text.width / 2 + 0.5),
y = math.floor(cy - self.text.height / 2 + 0.5),
fade = fade,
})
end
if self.t_num and self.score_diff > 0 then
local str = tostring(self.score_diff)
for i = 1, #str do
local d = tonumber(string.sub(str, #str - i + 1, #str - i + 1)) or 0
tex.draw_texture(self.t_num, { frame = d, x = -((i - 1) * self.sc_margin), y = y, fade = fade, index = p_idx })
end
end
end