Files
PyTaikoGreen/Scripts/background/bg_collabs/oshiri.lua
T
2026-10-10 00:09:38 -04:00

245 lines
9.5 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/oshiri"
local MAX_DANCERS = 5
-- No footer: Lumen's dodai is drawn at alpha 0.
-- Don band: a two-colour band scrolling one 168px tile left every 5.3s, with a column of
-- three stars on every tile. Each star dims to half and back over a beat; the dip runs down
-- the column, top to bottom, every 1333ms. Clearing fades in the same band in other colours.
local STAR_DIP = { { 317, -500 }, { 317, 500 } }
local function star_row(y, delay)
local pulse = { { delay, 0 } }
for _, m in ipairs(STAR_DIP) do table.insert(pulse, m) end
return { key = "overlay", ms = 5333, dx = -168, tile = 168, x = 94, y = y, period = 1333, pulse = pulse }
end
local DONBG_SPEC = { layers = {
{ key = "background", ms = 5333, dx = -168, x = 84 },
star_row(-11, 0),
star_row(63, 333),
star_row(131, 667),
} }
-- Clear background: the stage with a banner along the bottom that changes colour every beat,
-- fading in over the normal stage over 1.75 beats and back out over a beat. Timed in beats.
local BG_FEVER_IN, BG_FEVER_OUT = 1.75, 1
local OshiriBGFever = {}
OshiriBGFever.__index = OshiriBGFever
function OshiriBGFever.new(bpm)
local self = setmetatable({}, OshiriBGFever)
self.name = "bg_fever_0"
tex.load_folder(COLLAB_PATH, "bg_fever/" .. self.name)
self._id_bg = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/background") or 0
self._id_overlay = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/overlay") or 0
self.beat = 60000 / bpm
self.alpha = 0
return self
end
-- fades towards `to` from wherever the fade is; the banner restarts when it was hidden
function OshiriBGFever:fade_to(to, beats)
if self.alpha <= 0 then self.restart = true end
self.fade = anim.fade(beats * self.beat, { initial_opacity = self.alpha, final_opacity = to })
self.fade:start()
end
function OshiriBGFever:start() self:fade_to(1, BG_FEVER_IN) end
function OshiriBGFever:stop() self:fade_to(0, BG_FEVER_OUT) end
function OshiriBGFever:update(current_time_ms, bpm)
if bpm then self.beat = 60000 / bpm end
self.now = current_time_ms
if self.restart then self.restart, self.t0 = nil, current_time_ms end
if self.fade then
self.fade:update(current_time_ms)
self.alpha = self.fade.attribute
end
end
function OshiriBGFever:draw()
if self.alpha <= 0 then return end
tex.draw_texture(self._id_bg, { fade = self.alpha })
local frame = math.floor((self.now - self.t0) / self.beat) % 3
tex.draw_texture(self._id_overlay, { frame = frame, fade = self.alpha })
end
function OshiriBGFever:destroy() tex.unload_folder(COLLAB_PATH, "bg_fever/" .. self.name) end
-- Fever line-up: jumps up 321px, drops 70px onto its line, bounces 70px a beat
local FEVER_SPEC = { rise = 251, peak = 70, bounce = 70 }
-- Dancers
-- Timed in beats. Index 0 is the big one in the centre, index 1 the four small ones. Both jump
-- up from below and drop onto the stage, loop an 8-beat routine and hop off when removed.
-- Lumen centres them 5px left of the slot and 111px above the stage line.
local BIG = {
origin = { 108, 279 },
enter = {
beats = 2, key = "loop",
{ 0, 0, 0, 338, to = { 0, -117, "out" } },
{ 1, 0, 0, -117, to = { 0, 0, "in" } },
{ 1.4, 0, 0, 0 },
},
dance = Timing.steps(
{ { 1, 0.5, x = 0, y = 0 }, { 2, 0.5 }, { 1, 0.5 }, { 2, 0.5 } },
{ { 0, 0.125 }, { 3, 0.375 }, { 4, 0.5 }, { 3, 0.5 }, { 4, 0.5 } },
{ { 5, 0.5 }, { 6, 0.5 }, { 5, 0.5 }, { 7, 0.5 } },
{ { 5, 0.5 }, { 6, 0.5 }, { 5, 0.5 }, { 7, 0.5 } }),
leave = {
beats = 1, key = "loop",
{ 0, 0, 0, 0, to = { -2, -35 } },
{ 0.125, 0, -2, -35, to = { 4, 322 } },
},
}
-- a two-beat kick: step, kick, step, kick with the other leg; `first` shortens the first step
local function kick(mirror, first)
return {
{ 1, first or 0.375, mirror = mirror }, { 2, 0.125, mirror = mirror }, { 3, 0.375, mirror = mirror },
{ 2, 0.125, mirror = mirror }, { 1, 0.375, mirror = mirror }, { 4, 0.125, mirror = mirror },
{ 5, 0.375, mirror = mirror }, { 4, 0.125, mirror = mirror },
}
end
-- turned round: arms up on every other half beat
local TURN = { { 6, 0.5, mirror = true }, { 0, 0.5, mirror = true }, { 7, 0.5, mirror = true }, { 0, 0.5, mirror = true } }
local FIRST_KICK = kick(true)
FIRST_KICK[1].x, FIRST_KICK[1].y = 0, 0
local SMALL = {
origin = { 92, 247 },
enter = {
beats = 2, key = "loop",
{ 0, 0, 7, 338, to = { 0, -117, "out" } },
{ 1, 0, 0, -117, to = { 0, 0, "in" } },
{ 1.4, 0, 0, 0 },
},
dance = Timing.steps(FIRST_KICK, { { 0, 0.125 } }, kick(false, 0.25),
{ { 0, 0.5 } }, TURN, { TURN[1], TURN[2], TURN[3] }),
leave = {
beats = 1, key = "loop",
{ 0, 0, 0, 0, mirror = true, to = { nil, -44, "out" } },
{ 0.15, 0, nil, -44, mirror = true, to = { nil, 338, "in" } },
},
}
local OSHIRI_DANCERS = Dancer.define({ [0] = BIG, [1] = SMALL })
-- Fixed slots (far-left .. far-right), from Lumen's dancer positions less the 5px
local DANCER_CENTERS = { 208, 422, 635, 848, 1062 }
local DANCER_DRAW_ORDER = { 5, 1, 4, 2, 3 } -- outer pairs first, the big one on top
-- dancer index by join order: the big one in the centre, then the small ones
local DANCER_JOIN_ORDER = { 0, 1, 1, 1, 1 }
-- Chibis for good hits: hop in growing from 70% size, then run along on a 1-beat cycle of
-- poses (key 1 = chibi1, key 0 = chibi2)
local CHIBIS = {
{ key = "1", period = 1, poses = { { 0, 1 }, { 0.25, 2 }, { 0.5, 1 }, { 0.75, 0 } } },
{ key = "0", period = 1, poses = { { 0, 1 }, { 0.25, 0 }, { 0.5, 1 }, { 0.75, 2 } } },
}
-- Background
local OshiriBackground = {}
OshiriBackground.__index = OshiriBackground
function OshiriBackground.new(player_num, bpm)
local self = setmetatable({}, OshiriBackground)
self.donbg = DonBGBase.new(1, player_num, COLLAB_PATH, DONBG_SPEC)
self.bg_normal = BGNormal.Base.new(0, COLLAB_PATH)
self.bg_fever = OshiriBGFever.new(bpm)
self.fever = Fever.new(bpm, COLLAB_PATH, FEVER_SPEC)
self.dancer = Dancer.BaseDancerGroup.new(0, bpm, MAX_DANCERS, COLLAB_PATH, OSHIRI_DANCERS)
for i, index in ipairs(DANCER_JOIN_ORDER) do
local dancer = OSHIRI_DANCERS.new(self.dancer.name, index, bpm, COLLAB_PATH)
dancer.group = self.dancer
self.dancer.dancers[i] = dancer
end
self.renda = RendaController.new(COLLAB_PATH, 0)
self.chibi = ChibiController.new(bpm, COLLAB_PATH, 0)
self.is_clear = false
self.is_rainbow = false
self.last_milestone = 1
return self
end
function OshiriBackground: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 OshiriBackground:add_chibi(player_num)
BaseChibi.add(self.chibi, CHIBIS[math.random(#CHIBIS)], COLLAB_PATH, player_num, nil, "chibi_0")
end
function OshiriBackground:handle_good(player_num) self:add_chibi(player_num) end
function OshiriBackground:handle_ok(player_num) self:add_chibi(player_num) end
function OshiriBackground:handle_bad(player_num) self.chibi:add_chibi(player_num, true) end
function OshiriBackground:handle_drumroll(player_num) self.renda:add_renda() end
function OshiriBackground:handle_balloon(player_num) self.renda:add_renda() end
function OshiriBackground: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 OshiriBackground: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 OshiriBackground:draw_fore() end
function OshiriBackground: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 OshiriBackground