Files
PyTaikoGreen/Scripts/background/bg_collabs/animal.lua
T
2026-10-08 21:21:18 -04:00

231 lines
9.2 KiB
Lua

local DonBG = require("background/bg_objects/donbg")
local BGNormal = require("background/bg_objects/bg_normal")
local Fever = require("background/bg_objects/fever")
local Footer = require("background/bg_objects/footer")
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 ChibiWave = require("background/bg_objects/chibi/wave")
local Timing = require("background/bg_objects/timing")
local COLLAB_PATH = "background/collab/animal"
local MAX_DANCERS = 5
local chain_moves, sum = Timing.chain_moves, Timing.sum
-- Clear background: the stage flashes white over a beat, cuts to the clear savanna under
-- the flash, and the flash fades over 0.8 beat. Losing clear fades the savanna out over a
-- beat to the normal one, which stays underneath. Timed in beats.
local BG_FEVER_FLASH = { { 0.975, 1000 }, { 0.8, -1000 } }
local BG_FEVER_CUT = { { 0.975, 0 }, { 0, 1000 } }
local BG_FEVER_OUT = 1
local AnimalBGFever = {}
AnimalBGFever.__index = AnimalBGFever
function AnimalBGFever.new(bpm)
local self = setmetatable({}, AnimalBGFever)
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_bg = id("background")
self._id_flash = id("flash")
self.beat = 60000 / bpm
self.offset = 0
self.fade = {}
self.flash = {}
return self
end
function AnimalBGFever:opacity() return self.offset + sum(self.fade) end
function AnimalBGFever:start()
self.offset = 0
self.fade = chain_moves(BG_FEVER_CUT, self.beat, 1)
self.flash = chain_moves(BG_FEVER_FLASH, self.beat, 1)
end
-- fades out from wherever it is
function AnimalBGFever:stop()
local opacity = self:opacity()
self.offset = opacity
self.fade = chain_moves({ { BG_FEVER_OUT, -opacity } }, self.beat, 1)
self.flash = {}
end
function AnimalBGFever:update(current_time_ms, bpm)
if bpm then self.beat = 60000 / bpm end
for _, m in ipairs(self.fade) do m:update(current_time_ms) end
for _, m in ipairs(self.flash) do m:update(current_time_ms) end
end
function AnimalBGFever:draw()
local opacity = self:opacity() / 1000
if opacity > 0 then tex.draw_texture(self._id_bg, { fade = opacity }) end
local flash = sum(self.flash) / 1000
if flash > 0 then tex.draw_texture(self._id_flash, { fade = flash }) end
end
function AnimalBGFever:destroy() tex.unload_folder(COLLAB_PATH, "bg_fever/" .. self.name) end
-- Fever: the animals' line-up (one image) jumps up from below, bounces once a beat and
-- hops off when the rainbow gauge is lost
local ANIMAL_FEVER = { rise = 330, peak = 109, bounce = 70, drop = 400 }
-- Dancers
-- Timed in beats. Each jumps up from below on its first frame, lands through five frames,
-- then loops an 8-beat routine; leaving, it rises and drops off the bottom.
-- Each N_loop holds the routine's frames, then six entry frames, then four exit frames.
local IN_MOVES = {
{ 0.975, -496, "out" }, { 0.425, 66, "in" },
{ 0.025, 0 }, { 0, 30 }, { 0.05, 0 }, { 0, 23 }, { 0.05, 0 }, { 0, 15 }, { 0.075, 0 }, { 0, -34 },
}
local OUT_MOVES = { { 0.25, 0 }, { 0, -36 }, { 0.25, -28 }, { 0.225, 0 }, { 0.975, 397 } }
-- the routine's frames: big frames hold most of a beat, with two quick in-betweens
local SMALL_DANCE = {
{ 0, 0.125 }, { 1, 0.125 }, { 2, 0.125 }, { 3, 0.6 }, { 4, 0.125 }, { 5, 0.125 }, { 6, 0.75 },
{ 7, 0.125 }, { 8, 0.125 }, { 9, 0.75 }, { 10, 0.125 }, { 11, 0.125 }, { 12, 0.75 },
{ 0, 0.125 }, { 1, 0.125 }, { 2, 0.125 }, { 3, 0.625 }, { 4, 0.125 }, { 5, 0.125 }, { 6, 0.75 },
{ 7, 0.125 }, { 8, 0.125 }, { 9, 0.75 }, { 10, 0.125 }, { 11, 0.125 }, { 12, 0.775 },
}
local BIG_DANCE = {
{ 0, 0.125 }, { 1, 0.125 }, { 2, 0.125 }, { 3, 0.6 }, { 4, 0.125 }, { 5, 0.125 }, { 6, 0.1 },
{ 7, 0.775 }, { 8, 0.125 }, { 9, 0.125 }, { 10, 0.625 }, { 11, 0.125 }, { 12, 0.25 }, { 13, 0.1 },
{ 0, 0.65 }, { 1, 0.125 }, { 2, 0.125 }, { 3, 0.625 }, { 4, 0.125 }, { 5, 0.125 }, { 6, 0.1 },
{ 7, 0.775 }, { 8, 0.125 }, { 9, 0.125 }, { 10, 0.625 }, { 11, 0.125 }, { 12, 0.25 }, { 13, 0.1 },
{ 0, 0.55 },
}
-- n: routine frame count; the big dancer starts its exit one in-between earlier
local function animal_dancer(n, dance, out_frames)
local s = n -- entry frames
return {
start_offset = 396,
in_moves = IN_MOVES,
squash = {},
in_frames = {
{ s, 1.425 }, { s + 1, 0.05 }, { s + 2, 0.05 }, { s + 3, 0.075 }, { s + 4, 0.1 },
{ s + 5, 0.1 }, { 0, 0.2 },
},
dance = dance,
out_moves = OUT_MOVES,
out_frames = out_frames(n + 6),
}
end
local BIG_DANCER = animal_dancer(14, BIG_DANCE, function(e)
return { { e, 0.125 }, { e + 1, 0.475 }, { e + 2, 0.125 }, { e + 3, 1 } }
end)
local SMALL_DANCER = animal_dancer(13, SMALL_DANCE, function(e)
return { { 12, 0.125 }, { e, 0.125 }, { e + 1, 0.35 }, { e + 2, 0.125 }, { e + 3, 1 } }
end)
local ANIMAL_DANCERS = Dancer.lumen({ [0] = BIG_DANCER, default = SMALL_DANCER })
-- Lumen's fixed slots, left to right. Each slot always gets the same dancer: the group
-- fills slots centre, left, right, far-left, far-right, so dancers join in index order 4..0.
local DANCER_CENTERS = { 172, 426, 640, 874, 1108 }
local DANCER_DRAW_ORDER = { 5, 1, 4, 2, 3 }
local DANCER_JOIN_ORDER = { 4, 3, 2, 1, 0 }
-- Chibi for good hits: the bird hops in growing from 70% size, then bobs across the band
local ANIMAL_CHIBI = {
key = "1",
run = { y = -2 },
wave = { first = 18, height = 38, beats = 0.85 },
}
-- Background
local AnimalBackground = {}
AnimalBackground.__index = AnimalBackground
function AnimalBackground.new(player_num, bpm)
local self = setmetatable({}, AnimalBackground)
self.donbg = DonBG.create(player_num, "background", 5)
self.bg_normal = BGNormal.Base.new(0, COLLAB_PATH)
self.bg_fever = AnimalBGFever.new(bpm)
self.footer = Footer.new(COLLAB_PATH, 0)
self.fever = Fever.new(bpm, COLLAB_PATH, ANIMAL_FEVER)
self.dancer = Dancer.BaseDancerGroup.new(0, bpm, MAX_DANCERS, COLLAB_PATH, ANIMAL_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(COLLAB_PATH, 0, { ms = { 2000 } })
self.chibi = ChibiController.new(bpm, COLLAB_PATH, 1)
self.is_clear = false
self.is_rainbow = false
self.last_milestone = 1
return self
end
function AnimalBackground: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 AnimalBackground:handle_good(player_num) BaseChibi.add(self.chibi, ANIMAL_CHIBI, COLLAB_PATH, player_num, ChibiWave) end
function AnimalBackground:handle_ok(player_num) BaseChibi.add(self.chibi, ANIMAL_CHIBI, COLLAB_PATH, player_num, ChibiWave) end
function AnimalBackground:handle_bad(player_num) self.chibi:add_chibi(player_num, true) end
function AnimalBackground:handle_drumroll(player_num) self.renda:add_renda() end
function AnimalBackground:handle_balloon(player_num) self.renda:add_renda() end
function AnimalBackground: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 AnimalBackground:draw_back()
self.bg_normal:draw()
self.bg_fever:draw()
self.footer:draw()
self.donbg:draw()
self.renda:draw()
self.dancer:draw_slots(DANCER_CENTERS, DANCER_DRAW_ORDER)
self.fever:draw()
self.chibi:draw()
end
function AnimalBackground:draw_fore() end
function AnimalBackground:destroy()
self.donbg:destroy()
self.bg_normal:destroy()
self.bg_fever:destroy()
self.fever:destroy()
self.dancer:destroy()
self.footer:destroy()
self.renda:destroy()
self.chibi:destroy()
end
return AnimalBackground