295 lines
11 KiB
Lua
295 lines
11 KiB
Lua
local DonBGBase = require("background/bg_objects/donbg/base")
|
|
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 chain_moves, sum, steps = Timing.chain_moves, Timing.sum, Timing.steps
|
|
|
|
local COLLAB_PATH = "background/collab/ymck"
|
|
local MAX_DANCERS = 5
|
|
|
|
-- Don band: coloured stripes scrolling one tile every 5.3 s, a row of fans bobbing 16px over
|
|
-- them and a white shade along the bottom. The clear set is an orange band with waves rolling
|
|
-- over it (dipping 29px, quickest at the bottom). A miss streak greys the normal set to half.
|
|
-- Ambient, in ms. Tiles start 20px in, like the default bands.
|
|
local DONBG = {
|
|
dark = { min = 0.5, ms = 167 },
|
|
layers = {
|
|
{ key = "background", ms = 5333, x = 20 },
|
|
{ key = "overlay", ms = 4667, x = 20, bob = { { 1000, 16 }, { 1000, -16 } } },
|
|
{ key = "waves", ms = 4667, x = 20, clear_only = true, bob = { { 983, 29, "in" }, { 1017, -29, "out" } } },
|
|
{ key = "shade", tile = 0 },
|
|
},
|
|
}
|
|
|
|
-- Riverside: the river scrolls one 160px tile left every 5 s under a faint reflection of the
|
|
-- stone bank; the boats and statues stand in front. Ambient, in ms.
|
|
local WATER = { tile = 160, ms = 5000, x = -40 }
|
|
local REFLECTION_X, REFLECTION_ALPHA = -78, 0.3
|
|
|
|
local YmckBGNormal = {}
|
|
YmckBGNormal.__index = YmckBGNormal
|
|
|
|
function YmckBGNormal.new()
|
|
local self = setmetatable({}, YmckBGNormal)
|
|
self.name = "bg_0"
|
|
tex.load_folder(COLLAB_PATH, "bg_normal/" .. 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_water = id("water")
|
|
self._id_reflection = id("reflection")
|
|
self._id_overlay = id("overlay")
|
|
self.scroll = anim.move(WATER.ms, { total_distance = -math.floor(WATER.tile * tex.get_screen_scale()), loop = true })
|
|
self.scroll:start()
|
|
return self
|
|
end
|
|
|
|
function YmckBGNormal:update(current_time_ms) self.scroll:update(current_time_ms) end
|
|
|
|
local function tiled(id, x, fade)
|
|
local scale = tex.get_screen_scale()
|
|
repeat
|
|
tex.draw_texture(id, { x = x, fade = fade })
|
|
x = x + WATER.tile * scale
|
|
until x >= tex.get_screen_width()
|
|
end
|
|
|
|
function YmckBGNormal:draw()
|
|
local scale = tex.get_screen_scale()
|
|
tex.draw_texture(self._id_bg)
|
|
tiled(self._id_water, WATER.x * scale + self.scroll.attribute)
|
|
tiled(self._id_reflection, REFLECTION_X * scale, REFLECTION_ALPHA)
|
|
tex.draw_texture(self._id_overlay)
|
|
end
|
|
|
|
function YmckBGNormal:destroy() tex.unload_folder(COLLAB_PATH, "bg_normal/" .. self.name) end
|
|
|
|
-- Clear background: the shrine at night drops in over the riverside, bounces once and
|
|
-- settles. Its stars twinkle (a second sky with other stars shown on and off), a beat at a
|
|
-- time once it has settled. Losing the clear drops it out the bottom. In beats.
|
|
local DROP = { from = -380, beats = 1.2, bounce = 50, bounce_beats = 0.275 }
|
|
local FALL = { to = 408, beats = 0.975 }
|
|
|
|
local function stars_on(state, t)
|
|
if state == "out" then return t < 0.125 or t >= 0.75 end
|
|
if t < 2 then return t % 1.25 < 0.625 end -- dropping in: on and off every 0.625 beat
|
|
return t % 1 >= 0.5
|
|
end
|
|
|
|
local YmckBGFever = {}
|
|
YmckBGFever.__index = YmckBGFever
|
|
|
|
function YmckBGFever.new(bpm)
|
|
local self = setmetatable({}, YmckBGFever)
|
|
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_strip = id("strip")
|
|
self._id_overlay = id("overlay")
|
|
self.beat = 60000 / bpm
|
|
self.offset = 0
|
|
self.moves = {}
|
|
self.state = nil -- nil (hidden), "in", "out"
|
|
return self
|
|
end
|
|
|
|
function YmckBGFever:y() return self.offset + sum(self.moves) end
|
|
|
|
-- drops in from wherever it is (from above when hidden)
|
|
function YmckBGFever:start()
|
|
local scale = tex.get_screen_scale()
|
|
self.offset = self.state and self:y() or DROP.from * scale
|
|
self.state, self.t0 = "in", nil
|
|
self.moves = chain_moves({
|
|
{ DROP.beats, -self.offset / scale },
|
|
{ DROP.bounce_beats, -DROP.bounce, "out" },
|
|
{ DROP.bounce_beats, DROP.bounce, "in" },
|
|
}, self.beat, scale)
|
|
end
|
|
|
|
-- falls out the bottom from wherever it is
|
|
function YmckBGFever:stop()
|
|
if not self.state then return end
|
|
local scale = tex.get_screen_scale()
|
|
self.offset = self:y()
|
|
self.state, self.t0 = "out", nil
|
|
self.moves = chain_moves({ { FALL.beats, FALL.to - self.offset / scale } }, self.beat, scale)
|
|
end
|
|
|
|
function YmckBGFever:update(current_time_ms, bpm)
|
|
if bpm then self.beat = 60000 / bpm end
|
|
if not self.state then return end
|
|
self.t0 = self.t0 or current_time_ms
|
|
self.now = current_time_ms
|
|
for _, m in ipairs(self.moves) do m:update(current_time_ms) end
|
|
if self.state == "out" and (not self.moves[1] or self.moves[1].is_finished) then
|
|
self.state, self.moves, self.offset = nil, {}, 0
|
|
end
|
|
end
|
|
|
|
function YmckBGFever:draw()
|
|
if not self.state then return end
|
|
local y = self:y()
|
|
tex.draw_texture(self._id_bg, { y = y })
|
|
if stars_on(self.state, (self.now - self.t0) / self.beat) then tex.draw_texture(self._id_strip, { y = y }) end
|
|
tex.draw_texture(self._id_overlay, { y = y })
|
|
end
|
|
|
|
function YmckBGFever:destroy() tex.unload_folder(COLLAB_PATH, "bg_fever/" .. self.name) end
|
|
|
|
-- Fever: the two mikoshi line-ups (imas's motion), switching poses on every bounce
|
|
local FEVER = { rise = 210, bounce = 70, drop = 400, poses = true }
|
|
|
|
-- Dancers: three girls and two drums, all on one routine. Each jumps up from below the stage
|
|
-- and drops onto its spot, then dances four beats of poses (a long one and three quick ones
|
|
-- a beat), and leaves with a hop and a fall (the drums keep their last pose, the girls their
|
|
-- first). Timed in beats; y is the image top at rest.
|
|
local function member(leave_frame)
|
|
return {
|
|
enter = {
|
|
beats = 2, key = "loop",
|
|
{ 0, 0, 4, 280 },
|
|
{ 0.35, 0, 4, 280, to = { 4, -140, "out" } },
|
|
{ 0.925, 0, 4, -140, to = { 0, 3 } },
|
|
{ 1.2, 0, 0, 3 },
|
|
{ 1.225, 1, 0, -1 },
|
|
},
|
|
dance = steps(
|
|
{ { 2, 0.475, x = 0, y = 0 }, { 3, 0.175 }, { 4, 0.175 }, { 5, 0.175 } },
|
|
{ { 6, 0.475 }, { 7, 0.175 }, { 8, 0.175 }, { 0, 0.175 } },
|
|
{ { 9, 0.475 }, { 10, 0.175 }, { 11, 0.175 }, { 12, 0.175 } },
|
|
{ { 13, 0.475 }, { 14, 0.175 }, { 1, 0.175 }, { 15, 0.175 } }),
|
|
leave = {
|
|
beats = 1.5, key = "loop",
|
|
{ 0, 14, 0, 0 },
|
|
{ 0.1, leave_frame, 0, 0, to = { 0, -94, "out" } },
|
|
{ 0.625, leave_frame, 0, -94, to = { 0, 276, "in" } },
|
|
},
|
|
}
|
|
end
|
|
|
|
local DANCERS = Dancer.define({ [0] = member(14), [1] = member(14), default = member(0) })
|
|
local DANCER_CENTERS = { 170, 384, 637, 890, 1104 } -- katsu, blue, red, green, don
|
|
local DANCER_DRAW_ORDER = { 5, 1, 4, 2, 3 } -- outer pairs first, the centre on top
|
|
-- dancer index by join order: joins fill the centre, left, right, far-left, far-right slots
|
|
local DANCER_JOIN_ORDER = { 4, 3, 2, 1, 0 }
|
|
|
|
-- Chibis for good hits: one of three festival kids hops in and runs across, ten running
|
|
-- frames an eighth of a beat each
|
|
local CHIBI_POSES = {}
|
|
for f = 0, 9 do CHIBI_POSES[f + 1] = { f * 0.125, f, 0, 0 } end
|
|
local CHIBIS = {}
|
|
for key = 1, 3 do
|
|
CHIBIS[key] = { key = tostring(key), run = { y = -2, distance = 1241 }, period = 1.25, poses = CHIBI_POSES }
|
|
end
|
|
|
|
-- Drumroll: rabbits fly up and right from the bottom-left (lovelive's motion)
|
|
local RENDA = { ms = { 2000 }, dx = 1560, dy = -1648, x_range = 500, y_range = 20 }
|
|
|
|
-- Background
|
|
|
|
local YmckBackground = {}
|
|
YmckBackground.__index = YmckBackground
|
|
|
|
function YmckBackground.new(player_num, bpm)
|
|
local self = setmetatable({}, YmckBackground)
|
|
self.donbg = DonBGBase.new(1, player_num, COLLAB_PATH, DONBG)
|
|
self.bg_normal = YmckBGNormal.new()
|
|
self.bg_fever = YmckBGFever.new(bpm)
|
|
self.fever = Fever.new(bpm, COLLAB_PATH, FEVER)
|
|
self.dancer = Dancer.BaseDancerGroup.new(0, bpm, MAX_DANCERS, COLLAB_PATH, 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, RENDA)
|
|
self.chibi = ChibiController.new(bpm, COLLAB_PATH, 1)
|
|
self.is_clear = false
|
|
self.is_rainbow = false
|
|
self.miss_streak = false
|
|
self.last_milestone = 1
|
|
return self
|
|
end
|
|
|
|
function YmckBackground:update(current_ms, bpm)
|
|
self.donbg:update(current_ms, bpm)
|
|
self.bg_normal:update(current_ms)
|
|
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 YmckBackground:add_chibi(player_num)
|
|
BaseChibi.add(self.chibi, CHIBIS[math.random(#CHIBIS)], COLLAB_PATH, player_num)
|
|
end
|
|
|
|
function YmckBackground:handle_good(player_num) self:add_chibi(player_num) end
|
|
|
|
function YmckBackground:handle_ok(player_num) self:add_chibi(player_num) end
|
|
|
|
function YmckBackground:handle_bad(player_num) self.chibi:add_chibi(player_num, true) end
|
|
|
|
function YmckBackground:handle_drumroll(player_num) self.renda:add_renda() end
|
|
|
|
function YmckBackground:handle_balloon(player_num) self.renda:add_renda() end
|
|
|
|
-- the grey only shows on the normal set: the clear set covers it
|
|
function YmckBackground:handle_miss_streak(player_num, on)
|
|
self.miss_streak = on
|
|
self.donbg:set_dark(on and not self.is_clear)
|
|
end
|
|
|
|
function YmckBackground: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
|
|
self.donbg:set_dark(self.miss_streak and not is_clear)
|
|
|
|
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 YmckBackground: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 YmckBackground:draw_fore() end
|
|
|
|
function YmckBackground: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 YmckBackground
|