219 lines
9.3 KiB
Lua
219 lines
9.3 KiB
Lua
local ResultBgLayers = {}
|
|
ResultBgLayers.__index = ResultBgLayers
|
|
|
|
local LOOP = 720 -- frames, sprite 83 / 87
|
|
local MS_TO_F = 0.06 -- 60 fps
|
|
|
|
-- cloud bars: drift linearly from x0 to x1 over `life` frames after `spawn`, fading in over `fade_in`
|
|
-- frames and out from out_a to out_b (frames since spawn); the 720 frame loop wraps around the spawn.
|
|
-- depth, cloud texture index, y, scale (|sx| == sy for every one of them), mirror, source width
|
|
-- (only a mirrored layer needs it -- and for both of those the base and clear bakes are the same
|
|
-- width), spawn, x0, x1, life, fade_in, out_a, out_b
|
|
local LAYERS = {
|
|
{ 3, 0, 162.60, 1.0, false, 592, 0, 1705.70, 1648.20, 586, 39, 506, 586 },
|
|
{ 4, 1, 905.25, 1.0, false, 960, 0, 1240.00, 935.45, 719, 60, 660, 719 },
|
|
{ 5, 1, 934.00, 1.2, true, 960, 0, 1106.30, 757.75, 644, 60, 585, 644 },
|
|
{ 6, 2, 622.00, 1.0, false, 840, 670, 1415.20, 1210.80, 651, 49, 607, 651 },
|
|
{ 7, 3, 873.25, 1.0, false, 824, 644, -235.30, -543.95, 677, 75, 583, 677 },
|
|
{ 8, 4, 873.25, 1.0, false, 800, 0, 668.65, 112.45, 719, 68, 660, 719 },
|
|
{ 9, 5, 595.25, 1.0, false, 848, 0, 468.00, 200.45, 704, 90, 624, 704 },
|
|
{ 10, 6, -17.70, 1.0, false, 616, 566, 1663.40, 1571.40, 634, 153, 575, 634 },
|
|
{ 11, 2, 75.10, 0.6, true, 840, 0, 346.40, -10.20, 719, 50, 660, 719 },
|
|
{ 12, 6, 214.30, 1.0, false, 616, 680, 786.20, 482.20, 650, 39, 591, 650 },
|
|
{ 13, 7, 400.75, 1.0, false, 600, 0, -190.35, -468.40, 719, 60, 660, 719 },
|
|
}
|
|
|
|
local function lerp(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 cloud_pose(L, f)
|
|
local t = (f - L[7]) % LOOP
|
|
return lerp(t, 0, L[10], L[8], L[9]), lerp(t, 0, L[11], 0, 1) * (1 - lerp(t, L[12], L[13], 0, 1))
|
|
end
|
|
|
|
-- Mt Fuji in the clear state: squashes, then swells and settles; its foot stays on y 1080.
|
|
-- Each leg is a squared curve, in (accelerating) or out (decelerating).
|
|
local FUJI_LEGS = {
|
|
{ 22, 1.0, 0.8, true }, { 35, 0.8, 1.2, false }, { 50, 1.2, 1.3, false },
|
|
{ 60, 1.3, 0.9, true }, { 74, 0.9, 1.1, false }, { 89, 1.1, 0.9, true },
|
|
}
|
|
local function fuji_pose(f)
|
|
local f0, sy = 0, 1.0
|
|
for i = 1, #FUJI_LEGS do
|
|
local leg = FUJI_LEGS[i]
|
|
if f < leg[1] then
|
|
local u = (f - f0) / (leg[1] - f0)
|
|
u = leg[4] and u * u or 1 - (1 - u) ^ 2
|
|
sy = leg[2] + (leg[3] - leg[2]) * u
|
|
return 1080 - 800 * sy, sy
|
|
end
|
|
f0, sy = leg[1], leg[3]
|
|
end
|
|
return 1080 - 800 * sy, sy
|
|
end
|
|
|
|
local FUJI_X = 583.00 -- shape 65, base
|
|
local FUJI_Y = 280.00
|
|
local FUJI_CLEAR_X = 584.65 -- shape 84 inside huji_1p_l_mc, clear
|
|
local FUJI_H = 800
|
|
|
|
function ResultBgLayers.new(player_num)
|
|
local self = setmetatable({}, ResultBgLayers)
|
|
self.player_num = player_num
|
|
-- player_num: P1=1 (solo P1), P2=2 (solo P2), TWO_PLAYER=3 (P1+P2)
|
|
self.t0 = nil
|
|
self.fuji_t0 = nil
|
|
|
|
-- solo P2 seat: full-screen P2 theme (teal plate, teal clouds, teal Fuji) + header
|
|
if player_num == 2 then
|
|
self.t_bg = tex.get_texture("result/background/background_2p")
|
|
self.t_header = tex.get_texture("result/background/bg_header")
|
|
self.t_fuji = tex.get_texture("result/background/bg_fuji_2p")
|
|
self.t_cloud = {}
|
|
for i = 0, 7 do
|
|
self.t_cloud[i] = tex.get_texture("result/background/bg_cloud_" .. i .. "_2p")
|
|
end
|
|
return self
|
|
end
|
|
|
|
-- P1 + P2: background_1p on the left half, background_2p on the right half, + header
|
|
if player_num == 3 then
|
|
self.t_bg_1p = tex.get_texture("result/background/background_1p")
|
|
self.t_bg_2p = tex.get_texture("result/background/background_2p")
|
|
self.t_header = tex.get_texture("result/background/bg_header")
|
|
return self
|
|
end
|
|
|
|
-- solo P1: animated sky / Fuji / clouds + header
|
|
self.t_sky = tex.get_texture("result/background/background_1p")
|
|
self.t_sky_clear = tex.get_texture("result/background/bg_sky_clear")
|
|
self.t_fuji = tex.get_texture("result/background/bg_fuji")
|
|
self.t_fuji_clear = tex.get_texture("result/background/bg_fuji_clear")
|
|
self.t_header = tex.get_texture("result/background/bg_header")
|
|
self.t_cloud, self.t_cloud_clear = {}, {}
|
|
for i = 0, 7 do
|
|
self.t_cloud[i] = tex.get_texture("result/background/bg_cloud_" .. i)
|
|
self.t_cloud_clear[i] = tex.get_texture("result/background/bg_cloud_clear_" .. i)
|
|
end
|
|
return self
|
|
end
|
|
|
|
-- arcade frame of the 720-frame loop, from the engine clock
|
|
function ResultBgLayers:frame()
|
|
local ms = tex.get_current_ms()
|
|
if not self.t0 then self.t0 = ms end
|
|
return math.fmod((ms - self.t0) * MS_TO_F, LOOP)
|
|
end
|
|
|
|
-- Mt Fuji runs on its own clock, zeroed when the clear state fires.
|
|
function ResultBgLayers:fuji_frame(clear)
|
|
if clear <= 0 then
|
|
self.fuji_t0 = nil -- re-arm: the next clear starts from rest again
|
|
return 0
|
|
end
|
|
local ms = tex.get_current_ms()
|
|
if not self.fuji_t0 then self.fuji_t0 = ms end
|
|
-- monotonic; fuji_pose parks it on its last leg forever after.
|
|
return (ms - self.fuji_t0) * MS_TO_F
|
|
end
|
|
|
|
local function draw_cloud(id, w, x, y, scale, mirror, a)
|
|
if not id or a <= 0.004 then return end
|
|
local left = mirror and (x - w * scale) or x
|
|
tex.draw_texture(id, {
|
|
x = left, y = y, scale = scale, fade = a,
|
|
mirror = mirror and "horizontal" or nil,
|
|
})
|
|
end
|
|
|
|
-- `fade` multiplies everything (the screen-entry wipe); `clear` is 0..1, the success cross-fade.
|
|
function ResultBgLayers:draw(fade, clear)
|
|
fade = fade or 1.0
|
|
clear = clear or 0.0
|
|
if fade <= 0 then return end
|
|
|
|
if self.player_num == 2 then
|
|
-- solo P2 seat: full-screen P2 theme -- P2's half upright on the right, mirrored on the left
|
|
if self.t_bg then
|
|
tex.draw_texture(self.t_bg, { index = 0, fade = fade, mirror = "horizontal" })
|
|
tex.draw_texture(self.t_bg, { index = 1, fade = fade })
|
|
end
|
|
|
|
local f = self:frame()
|
|
for i = 1, #LAYERS do
|
|
local L = LAYERS[i]
|
|
local idx, y, scale, mirror, w = L[2], L[3], L[4], L[5], L[6]
|
|
local tx, a = cloud_pose(L, f)
|
|
draw_cloud(self.t_cloud[idx], w, tx, y, scale, mirror, fade * a)
|
|
end
|
|
|
|
-- P2 Fuji (base, fades out as clear fades in)
|
|
if self.t_fuji and clear < 1.0 then
|
|
tex.draw_texture(self.t_fuji, { x = FUJI_X, y = FUJI_Y, fade = fade * (1.0 - clear) })
|
|
end
|
|
-- P2 clear Fuji (already teal in the source art)
|
|
if clear > 0 and self.t_fuji_clear then
|
|
local ty, sy = fuji_pose(self:fuji_frame(clear))
|
|
tex.draw_texture(self.t_fuji_clear, {
|
|
x = FUJI_CLEAR_X, y = ty, y2 = FUJI_H * sy - FUJI_H, fade = fade * clear,
|
|
})
|
|
end
|
|
|
|
if self.t_header then tex.draw_texture(self.t_header, { fade = fade }) end
|
|
return
|
|
end
|
|
|
|
if self.player_num == 3 then
|
|
-- P1 + P2: P1's half on the left, P2's half on the right, + header
|
|
if self.t_bg_1p then tex.draw_texture(self.t_bg_1p, { index = 0, fade = fade }) end
|
|
if self.t_bg_2p then tex.draw_texture(self.t_bg_2p, { index = 1, fade = fade }) end
|
|
if self.t_header then tex.draw_texture(self.t_header, { fade = fade }) end
|
|
return
|
|
end
|
|
|
|
local f = self:frame()
|
|
|
|
-- 1. sky. Base: shape 3 at x=0 and mirrored at x=960. Clear: shape 5 (gold, a different
|
|
-- atlas) the other way round -- x=960 upright, x=0 mirrored.
|
|
if self.t_sky then
|
|
tex.draw_texture(self.t_sky, { index = 0, fade = fade })
|
|
tex.draw_texture(self.t_sky, { index = 1, fade = fade, mirror = "horizontal" })
|
|
end
|
|
if clear > 0 and self.t_sky_clear then
|
|
tex.draw_texture(self.t_sky_clear, { index = 0, fade = fade * clear })
|
|
tex.draw_texture(self.t_sky_clear, { index = 1, fade = fade * clear, mirror = "horizontal" })
|
|
end
|
|
|
|
-- 2. Mt Fuji, pulsing only in the clear state (a 90-frame one-shot, held at the end).
|
|
if self.t_fuji and clear < 1.0 then
|
|
tex.draw_texture(self.t_fuji, { x = FUJI_X, y = FUJI_Y, fade = fade * (1.0 - clear) })
|
|
end
|
|
if clear > 0 and self.t_fuji_clear then
|
|
local ty, sy = fuji_pose(self:fuji_frame(clear))
|
|
tex.draw_texture(self.t_fuji_clear, {
|
|
x = FUJI_CLEAR_X, y = ty, y2 = FUJI_H * sy - FUJI_H, fade = fade * clear,
|
|
})
|
|
end
|
|
|
|
-- 3. the eleven cloud bars, one pose for both states.
|
|
for i = 1, #LAYERS do
|
|
local L = LAYERS[i]
|
|
local idx, y, scale, mirror, w = L[2], L[3], L[4], L[5], L[6]
|
|
local tx, a = cloud_pose(L, f)
|
|
if clear < 1.0 then
|
|
draw_cloud(self.t_cloud[idx], w, tx, y, scale, mirror, fade * a * (1.0 - clear))
|
|
end
|
|
if clear > 0 then
|
|
draw_cloud(self.t_cloud_clear[idx], w, tx, y, scale, mirror, fade * a * clear)
|
|
end
|
|
end
|
|
|
|
-- 4. header band, drawn last (above the clouds).
|
|
if self.t_header then tex.draw_texture(self.t_header, { fade = fade }) end
|
|
end
|
|
|
|
return ResultBgLayers
|