Files
PyTaikoGreen/Scripts/background/bg_collabs/gb.lua
T
2026-10-09 10:39:08 -04:00

301 lines
12 KiB
Lua

local DonBGBase = require("background/bg_objects/donbg/base")
local BGNormal = require("background/bg_objects/bg_normal")
local Fever = require("background/bg_objects/fever")
local Dancer = require("background/bg_objects/dancer")
local RendaController = require("background/bg_objects/renda")
local ChibiController = require("background/bg_objects/chibi")
local BaseChibi = require("background/bg_objects/chibi/base")
local Timing = require("background/bg_objects/timing")
local COLLAB_PATH = "background/collab/gb"
local MAX_DANCERS = 5
local pose_at, steps = Timing.pose_at, Timing.steps
-- Don band: bomb tiles and the title strip scroll one tile left every 8 beats of Lumen's
-- clock (5.3 s); the clear set swaps in the gold tiles and title. Ambient, in ms.
local DONBG_SCROLL_MS = 5333
local DONBG_SPEC = { fade = 0.225, layers = {
{ key = "background", ms = DONBG_SCROLL_MS },
{ key = "overlay", ms = DONBG_SCROLL_MS, tile = 448 },
} }
-- Clear background: the stage comes up, the light-panel arch and the 金/爆 signs blink on
-- four times, then the arch cycles its four panels, the signs flicker between their two lit
-- frames and four spotlights per stand (gold, cyan, gold, cyan, staggered) swing out and back.
-- Losing the clear fades the arch and signs out; the stage stays a moment longer. Timed in beats.
local BLINK = steps({ { 0, 0.2 }, { 0, 0.175, hide = true } })
local BLINKS = 4
local LOOP_AT = 1.525
local PANELS = steps({ { 0, 0.3 }, { 1, 0.275 }, { 2, 0.275 }, { 3, 0.275 } })
local SIGN = steps({ { 1, 0.25 }, { 2, 0.25 } })
local FADE_OUT, STAGE_OUT = 0.65, 0.975
-- A spotlight is pinned at its lamp (the image's top corner): it opens from a sliver to its
-- full width, swings wider, then dims away and shrinks up; later it swings back the same way.
local RAY = {
{ 0, 0, 0, 0, sx = 0.03, alpha = 0, to = { 0, 0, sx = 1, alpha = 1 } },
{ 0.3, 0, to = { 0, 0, sx = 2.62 } },
{ 0.9, 0, sx = 2.62, to = { 0, 0, sx = 2.82, sy = 0.69, alpha = 0 } },
{ 1.05, 0, hide = true },
{ 2.3, 0, sx = 2.82, sy = 0.69, alpha = 0, to = { 0, 0, sx = 2.62, sy = 1, alpha = 1 } },
{ 2.45, 0, sx = 2.62, to = { 0, 0, sx = 1 } },
{ 3.075, 0, to = { 0, 0, sx = 0.03, alpha = 0 } },
{ 3.35, 0, hide = true },
length = 4.275,
}
local RAY_STAGGER = 0.375
-- texture.json indices: outer right, outer left, inner right, inner left (inner ones half width)
local RAY_STANDS = { { mirror = false, w = 312 }, { mirror = true, w = 312 },
{ mirror = false, w = 156 }, { mirror = true, w = 156 } }
local GbBGFever = {}
GbBGFever.__index = GbBGFever
function GbBGFever.new(bpm)
local self = setmetatable({}, GbBGFever)
self.name = "bg_fever_0"
tex.load_folder(COLLAB_PATH, "bg_fever/" .. self.name)
local function id(key) return tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. key) or 0 end
self._id_panels = id("background")
self._id_stage = id("footer")
self._id_kin = id("kin")
self._id_baku = id("baku")
self._id_rays = { id("ray_gold"), id("ray_cyan") }
self.beat = 60000 / bpm
self.now = 0
self.state = nil -- nil (hidden), "on", "off"
return self
end
function GbBGFever:start()
self.state, self.t0 = "on", self.now
end
function GbBGFever:stop()
if self.state == "on" then self.state, self.t_off = "off", self.now end
end
function GbBGFever:update(current_time_ms, bpm)
if bpm then self.beat = 60000 / bpm end
self.now = current_time_ms
if self.state == "off" and (self.now - self.t_off) / self.beat >= STAGE_OUT then self.state = nil end
end
function GbBGFever:draw_rays(t)
local scale = tex.get_screen_scale()
for k = 0, 3 do
local tk = t - k * RAY_STAGGER
local pose = tk >= 0 and pose_at(RAY, tk % RAY.length)
if pose then
for i, stand in ipairs(RAY_STANDS) do
local w = stand.w * scale
tex.draw_texture(self._id_rays[k % 2 + 1], {
index = i - 1,
x = stand.mirror and 0 or w * (1 - pose.sx),
x2 = w * (pose.sx - 1),
y2 = 312 * scale * (pose.sy - 1),
mirror = stand.mirror and "horizontal" or nil,
fade = pose.alpha,
blend = "additive",
})
end
end
end
end
function GbBGFever:draw()
if not self.state then return end
local t = (self.now - self.t0) / self.beat
local fade, panel, sign = 1, 0, 0
if self.state == "off" then fade = math.max(0, 1 - (self.now - self.t_off) / self.beat / FADE_OUT) end
if t < LOOP_AT then
if t >= BLINKS * BLINK.length or not pose_at(BLINK, t % BLINK.length) then fade = 0 end
else
local lt = t - LOOP_AT
panel = pose_at(PANELS, lt % PANELS.length).frame
sign = pose_at(SIGN, lt % SIGN.length).frame
end
if fade > 0 then
tex.draw_texture(self._id_panels, { frame = panel, fade = fade })
tex.draw_texture(self._id_panels, { frame = panel, fade = fade, index = 1, mirror = "horizontal" })
end
tex.draw_texture(self._id_stage)
if fade > 0 then
tex.draw_texture(self._id_kin, { frame = sign, fade = fade })
tex.draw_texture(self._id_baku, { frame = sign, fade = fade })
end
if self.state == "on" and t >= LOOP_AT then self:draw_rays(t - LOOP_AT) end
end
function GbBGFever:destroy() tex.unload_folder(COLLAB_PATH, "bg_fever/" .. self.name) end
-- Dancers
-- Timed in beats; poses are offsets from Lumen's dancer origin (texture.json y 516).
-- The four small dancers shoot up from below, land with a squash, then loop an 8-beat
-- routine of hops, one a beat, alternating two pose pairs. Leaving, they hop and drop off.
local function hop(up, top)
return {
{ up, 0.175, to = { 0, -20 } },
{ top, 0.175, to = { 0, -30 } },
{ top, 0.15, to = { 0, -20 } },
{ up, 0.225, to = { 0, 0 } },
{ 1, 0.275 },
}
end
local SMALL_ENTER = steps({
{ 0, 0.2, x = 0, y = 350 },
{ 0, 0.7, to = { 0, -30, "out" } }, -- shoots up from below
{ 0, 0.475, to = { 0, 0, "in" } },
{ 0, 0.075 },
{ 1, 0.175, to = { 0, 13, nil, sy = 0.91 } }, -- lands
{ 1, 0.15, sy = 0.91, to = { 0, 0, nil, sy = 1 } },
{ 1, 0.225 },
})
SMALL_ENTER.beats = 2
local SMALL_DANCE = steps({ { 1, 0, x = 0, y = 0 } },
hop(2, 3), hop(4, 5), hop(2, 3), hop(2, 3), hop(4, 5), hop(2, 3), hop(4, 5), hop(4, 5))
local SMALL_LEAVE = steps({
{ 1, 0.2, x = 0, y = 0, key = "loop" },
{ 6, 0.275, key = "loop", to = { 0, -20, "out" } }, -- hops
{ 6, 0.675, key = "loop", to = { 0, 350, "in" } }, -- and drops off
})
SMALL_LEAVE.beats = 1.15
-- The bomber in the middle rises in, lands with a squash and loops an 8-beat routine of
-- two 1-beat phrases (a punch and a turn), never leaving
local BIG_ENTER = steps({
{ 0, 0.25, x = 0, y = 350 },
{ 0, 0.775, to = { 0, -20, "out" } },
{ 0, 0.325, to = { 0, 0, "in" } },
{ 0, 0.25, to = { 0, 7, nil, sy = 0.95 } }, -- lands
{ 0, 0.225, sy = 0.95, to = { 0, 0, nil, sy = 1 } },
{ 0, 0.05 },
{ 1, 0.125 },
})
BIG_ENTER.beats = 2
local PUNCH = { { 2, 0.25 }, { 3, 0.25 }, { 4, 0.375 }, { 5, 0.125 } }
local TURN = { { 6, 0.25 }, { 0, 0.25 }, { 7, 0.375 }, { 1, 0.125 } }
local BIG_DANCE = steps({ { 2, 0, x = 0, y = 0 } },
PUNCH, TURN, { { 2, 0.25 }, { 3, 0.25 }, { 4, 0.5 } }, PUNCH, TURN,
PUNCH, { { 6, 0.25 }, { 0, 0.25 }, { 7, 0.5 } }, TURN)
local GB_DANCERS = Dancer.define({
[4] = { origin = { 140, 140 }, enter = BIG_ENTER, dance = BIG_DANCE },
default = { origin = { 140, 150 }, enter = SMALL_ENTER, dance = SMALL_DANCE, leave = SMALL_LEAVE },
})
-- Lumen's slots, left to right; the group fills centre, left, right, far-left, far-right,
-- which is Lumen's dancer1..5 (skin dancers 4, 3, 2, 1, 0)
local DANCER_CENTERS = { 173, 407, 640, 873, 1107 }
local DANCER_DRAW_ORDER = { 5, 1, 4, 2, 3 }
local DANCER_JOIN_ORDER = { 4, 3, 2, 1, 0 }
-- Chibis for good hits: one of the two bombers hops in and runs, a six-frame stride a beat
local RUN = {
{ 0, 0, 0, 0 }, { 0.175, 1, 0, -2 }, { 0.35, 2, 0, -3 },
{ 0.5, 3, 0, 0 }, { 0.675, 4, 0, -2 }, { 0.85, 5, 0, -3 },
}
local GB_CHIBIS = {
{ key = "0", run = { y = 1 }, period = 1, poses = RUN },
{ key = "1", run = { y = 1 }, period = 1, poses = RUN },
}
-- Background
local GbBackground = {}
GbBackground.__index = GbBackground
function GbBackground.new(player_num, bpm)
local self = setmetatable({}, GbBackground)
self.donbg = DonBGBase.new(1, player_num, COLLAB_PATH, DONBG_SPEC)
self.bg_normal = BGNormal.Base.new(0, COLLAB_PATH)
self.bg_fever = GbBGFever.new(bpm)
self.fever = Fever.new(bpm, COLLAB_PATH, { rise = 300, peak = 40, bounce = 40, drop = 340, poses = true })
self.dancer = Dancer.BaseDancerGroup.new(0, bpm, MAX_DANCERS, COLLAB_PATH, GB_DANCERS)
local by_index = {}
for _, d in ipairs(self.dancer.dancers) do by_index[d.index] = d end
for i, index in ipairs(DANCER_JOIN_ORDER) do self.dancer.dancers[i] = by_index[index] end
self.renda = RendaController.new("background", 0)
self.chibi = ChibiController.new(bpm, COLLAB_PATH, 1)
self.is_clear = false
self.is_rainbow = false
self.last_milestone = 1
return self
end
function GbBackground:update(current_ms, bpm)
self.donbg:update(current_ms, bpm)
self.bg_fever:update(current_ms, bpm)
self.fever:update(current_ms, bpm)
self.dancer:update(current_ms, bpm)
self.renda:update(current_ms)
self.chibi:update(current_ms, bpm)
end
function GbBackground:add_chibi(player_num)
BaseChibi.add(self.chibi, GB_CHIBIS[math.random(#GB_CHIBIS)], COLLAB_PATH, player_num)
end
function GbBackground:handle_good(player_num) self:add_chibi(player_num) end
function GbBackground:handle_ok(player_num) self:add_chibi(player_num) end
function GbBackground:handle_bad(player_num) self.chibi:add_chibi(player_num, true) end
function GbBackground:handle_drumroll(player_num) self.renda:add_renda() end
function GbBackground:handle_balloon(player_num) self.renda:add_renda() end
function GbBackground:handle_gauge(player_num, progress, is_clear, is_rainbow)
self.donbg:set_clear(is_clear)
if is_clear and not self.is_clear then self.bg_fever:start() end
if not is_clear and self.is_clear then self.bg_fever:stop() end
if is_rainbow and not self.is_rainbow then self.fever:start() end
if not is_rainbow and self.is_rainbow then self.fever:stop() end
self.is_clear = is_clear
self.is_rainbow = is_rainbow
local current_milestone
if is_clear then
current_milestone = MAX_DANCERS
else
current_milestone = math.min(MAX_DANCERS - 1, math.floor(progress * MAX_DANCERS))
end
if current_milestone > self.last_milestone then
for _ = 1, current_milestone - self.last_milestone do self.dancer:add_dancer() end
self.last_milestone = current_milestone
elseif current_milestone < self.last_milestone then
for _ = 1, self.last_milestone - current_milestone do self.dancer:leave_dancer() end
self.last_milestone = current_milestone
end
end
function GbBackground:draw_back()
self.bg_normal:draw()
self.bg_fever:draw()
self.donbg:draw()
self.renda:draw()
self.dancer:draw_slots(DANCER_CENTERS, DANCER_DRAW_ORDER)
self.fever:draw()
self.chibi:draw()
end
function GbBackground:draw_fore() end
function GbBackground:destroy()
self.donbg:destroy()
self.bg_normal:destroy()
self.bg_fever:destroy()
self.fever:destroy()
self.dancer:destroy()
self.renda:destroy()
self.chibi:destroy()
end
return GbBackground