232 lines
9.3 KiB
Lua
232 lines
9.3 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; poses are offsets from where each dancer stands, pivoting about its feet
|
|
-- (the bottom-left of its images). Each jumps up from below on its first entry frame, lands
|
|
-- through five more, loops an 8-beat routine, and leaving, rises and drops off the bottom.
|
|
|
|
-- 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 },
|
|
}
|
|
|
|
local ENTER = {
|
|
beats = 2,
|
|
{ 0, 0, 0, 396, to = { 0, -100, "out" } }, -- shoots up from below
|
|
{ 0.975, 0, 0, -100, to = { 0, -34, "in" } },
|
|
{ 1.4, 0, 0, -34 },
|
|
{ 1.425, 1, 0, -4 }, { 1.475, 2, 0, 19 }, { 1.525, 3, 0, 34 }, -- lands, sinking in
|
|
{ 1.6, 4, 0, 0 }, { 1.7, 5 }, { 1.8, 0, key = "loop" },
|
|
}
|
|
-- leaving: hops up, then drops off the bottom (the small ones from their last routine frame)
|
|
local function exit(first)
|
|
local leave = { beats = 1.725 }
|
|
if first then table.insert(leave, { 0, first, 0, 0, key = "loop" }) else table.insert(leave, { 0, 0, 0, 0 }) end
|
|
for _, p in ipairs({
|
|
{ 0.125, first and 0 or 1 },
|
|
{ 0.25, 1, 0, -36, to = { 0, -64 } }, { 0.5, 1, 0, -64 }, { 0.6, 2 },
|
|
{ 0.725, 3, 0, -64, to = { 0, 333 } },
|
|
{ 1.7, hide = true },
|
|
}) do table.insert(leave, p) end
|
|
return leave
|
|
end
|
|
|
|
-- h: image height, so the dancer pivots about its feet
|
|
local function animal_dancer(h, dance, first_out)
|
|
return { origin = { 0, h }, enter = ENTER, dance = Timing.steps(dance), leave = exit(first_out) }
|
|
end
|
|
local ANIMAL_DANCERS = Dancer.define({
|
|
[0] = animal_dancer(432, BIG_DANCE),
|
|
[1] = animal_dancer(432, SMALL_DANCE, 12),
|
|
default = animal_dancer(376, SMALL_DANCE, 12),
|
|
})
|
|
|
|
-- Fixed dancer 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
|