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

133 lines
5.0 KiB
Lua

ResultCrown = {}
ResultCrown.__index = ResultCrown
local FRAME_MS = 1000 / 60 -- one arcade frame in ms
local CROWN_START_F = 5 -- t = 0 is this arcade frame
local CROWN_END_F = 120
local GL_SHINE = { 0, 1, 2 } -- gleam frames of the crown_loop sweep
local GL_BURST, GL_STARS = 3, 4
local CLOOP_LEN = 180
-- GL_SHINE index visible at loop-frame k: three sweep frames of 3 frames each, then idle
local function crown_loop_shine(k)
if k < 9 then return math.floor(k / 3) + 1 end
return nil
end
-- value between v0 at f0 and v1 at f1, held outside
local function ramp(f, f0, f1, v0, v1)
if f <= f0 then return v0 end
if f >= f1 then return v1 end
return v0 + (v1 - v0) * (f - f0) / (f1 - f0)
end
local function clamp01(v)
if v <= 0 then return 0 end
if v >= 1 then return 1 end
return v
end
local function lerp(a, b, p) return a + (b - a) * p end
function ResultCrown.new(crown_type, is_2p, has_2p)
local self = setmetatable({}, ResultCrown)
self.is_2p = is_2p
self.p_idx = is_2p and 1 or 0
self.t0 = tex.get_current_ms()
self.now = self.t0
self.sound_played = false
local crown_names = { [0] = "crown_clear", [1] = "crown_fc", [2] = "crown_dfc" }
self.t_crown = tex.get_texture("result/crown/" .. (crown_names[crown_type] or "crown_clear"))
self.t_crown_fade = tex.get_texture("result/crown/crown_fade")
self.t_gleam = tex.get_texture("result/crown/gleam")
-- crown_loop shine: each crown colour has its own three sweep frames, pieces of that crown's
-- art crossed by a diagonal light band
local shine_names = { [0] = "shine_clear", [1] = "shine_fc", [2] = "shine_dfc" }
self.t_shine = tex.get_texture("result/crown/" .. (shine_names[crown_type] or "shine_clear"))
local colours = { [0] = "silver", [1] = "gold", [2] = "rainbow" }
local seat = has_2p and (is_2p and "_r" or "_l") or "_c"
self.sound_name = "crown_" .. (colours[crown_type] or "silver") .. seat
return self
end
function ResultCrown:update(current_ms)
self.now = current_ms
if not self.sound_played and (current_ms - self.t0) / FRAME_MS >= 0 then
if not (self.is_2p and tex.ai_active and tex.ai_active()) then audio.play_sound(self.sound_name or "crown", "sound") end
self.sound_played = true
end
end
-- result_player.lua gates the 「クリア」 bubble on this: the crown has landed at scale 1.0.
function ResultCrown:is_settled()
return (self.now - self.t0) / FRAME_MS >= 17
end
function ResultCrown:draw()
local t = (self.now - self.t0) / FRAME_MS
if t < 0 then return end
local idx = self.p_idx
local f = CROWN_START_F + t -- absolute arcade frame on sprite 73
-- the crown drops in from 3x on a squared curve, then settles from 0.8 to 1
local c_scale, c_alpha
if f < 18 then
local u = clamp01((f - 5) / 13) ^ 2
c_scale, c_alpha = 3 - 2.2 * u, u
else
c_scale, c_alpha = ramp(f, 18, 22, 0.8, 1), 1.0
end
if self.t_crown then
tex.draw_texture(self.t_crown, { scale = c_scale, center = true, index = idx, fade = c_alpha })
end
if self.t_crown_fade and t >= 13 and t <= 42 then
local s = ramp(f, 18, 22, 0.8, 1) + ramp(f, 22, 47, 0, 1)
local a = ramp(f, 22, 47, 1, 0)
if a > 0.001 then
tex.draw_texture(self.t_crown_fade, { scale = s, center = true, index = idx, fade = a })
end
end
if not self.t_gleam then return end
-- radial burst: two equal copies, drawn twice for the doubled coverage
if t >= 13 and t <= 49 then
local a = ramp(f, 17, 18, 0, 0.63) + ramp(f, 18, 22, 0, 0.37) - ramp(f, 22, 54, 0, 1)
local s0 = ramp(f, 18, 22, 0.1, 0.31) + ramp(f, 22, 54, 0, 1.19)
if a > 0.001 then
-- the cabinet places both burst copies with the add blend mode
tex.draw_texture(self.t_gleam, { frame = GL_BURST, scale = s0, center = true, index = idx, fade = a, blend = "additive" })
tex.draw_texture(self.t_gleam, { frame = GL_BURST, scale = s0, center = true, index = idx, fade = a, blend = "additive" })
end
end
-- drifting star cluster
if t >= 17 and t <= 119 then
local s = ramp(f, 22, 59, 0.5, 1) + ramp(f, 59, 100, 0, 0.2)
local ox = ramp(f, 22, 59, 30.2, 63.25) + ramp(f, 59, 100, 0, 13.25)
local oy = ramp(f, 22, 59, -2.2, -17.05) + ramp(f, 59, 100, 0, -5.9)
local a = ramp(f, 21, 22, 0, 1) - ramp(f, 100, 119, 0, 0.91)
tex.draw_texture(self.t_gleam,
{ frame = GL_STARS, scale = s, center = true, index = idx, x = ox, y = oy, fade = clamp01(a) })
end
-- crown_loop shine sweep (180-frame loop from "end")
if f >= CROWN_END_F - 5 then
local k = (f - (CROWN_END_F - 5)) % CLOOP_LEN
local shine = crown_loop_shine(k)
if not self.t_shine then return end
if shine then
tex.draw_texture(self.t_shine,
{ frame = GL_SHINE[shine], center = true, index = idx })
end
end
end