306 lines
12 KiB
Lua
306 lines
12 KiB
Lua
local SparkleDonBG = require("background/bg_objects/donbg/sparkle")
|
|
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")
|
|
|
|
-- THE IDOLM@STER SideM
|
|
local COLLAB_PATH = "background/collab/imas_sidem"
|
|
local MAX_DANCERS = 3
|
|
|
|
-- Don band: the base scrolls one tile left every 5.33s; the clear set scrolls with it under a
|
|
-- glow strip that pulses every second, and stars twinkle in clusters over it (still, not
|
|
-- scrolling). Ambient, in ms.
|
|
local SIDEM_DONBG = {
|
|
layers = {
|
|
{ key = "background", ms = 5333 },
|
|
{ key = "glow", clear_only = true, tile = 0, alpha = 0.148, blend = "additive",
|
|
period = 1000, pulse = { { 500, -1000 }, { 500, 1000, "out" } } },
|
|
},
|
|
}
|
|
|
|
-- star sizes for SparkleDonBG's clusters: { pop, life, x, y, from, to } in Lumen frames
|
|
local SIDEM_STARS = {
|
|
trio = {
|
|
{ 110, 34, 0, 0, 0.7, 1.3 }, { 45, 34, 0, 0, 0.7, 1.3 },
|
|
{ 106, 20, 50, -100, 0.5, 1 }, { 31, 20, 50, -100, 0.5, 1 },
|
|
{ 10, 20, 300, 0, 0.31, 1.09 }, { 50, 20, 300, 0, 0.43, 1.05 }, { 85, 19, 300, 0, 0.26, 1 },
|
|
},
|
|
pair = {
|
|
{ 11, 34, 0, 0, 0.68, 1.26 }, { 68, 34, 0, 0, 0.68, 1.26 },
|
|
{ 0, 19, 300, 0, 0.86, 1.04 }, { 38, 20, 50, -100, 0.5, 1 },
|
|
{ 64, 20, 300, 0, 0.65, 0.9 }, { 94, 20, 50, -100, 0.5, 1 },
|
|
},
|
|
}
|
|
|
|
-- Stage: two halves of a rig around a screen cycling the 315 Production logo and three units
|
|
-- (3 beats each), under a pair of white spotlights. Timed in beats.
|
|
local SCREEN_BEATS, SCREENS = 3, 4
|
|
|
|
local SidemBGNormal = {}
|
|
SidemBGNormal.__index = SidemBGNormal
|
|
|
|
function SidemBGNormal.new(bpm)
|
|
local self = setmetatable({}, SidemBGNormal)
|
|
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_screen = id("screen")
|
|
self._id_overlay = id("overlay")
|
|
self.beat = 60000 / bpm
|
|
self.t = 0
|
|
return self
|
|
end
|
|
|
|
function SidemBGNormal:update(current_time_ms, bpm)
|
|
if bpm then self.beat = 60000 / bpm end
|
|
self.t = self.t + (current_time_ms - (self.last_ms or current_time_ms)) / self.beat
|
|
self.last_ms = current_time_ms
|
|
end
|
|
|
|
-- the two spotlights (also drawn brighter by the clear stage)
|
|
function SidemBGNormal:draw_spots(fade)
|
|
tex.draw_texture(self._id_overlay, { index = 0, fade = fade, blend = "additive" })
|
|
tex.draw_texture(self._id_overlay, { index = 1, fade = fade, mirror = "horizontal", blend = "additive" })
|
|
end
|
|
|
|
function SidemBGNormal:draw()
|
|
tex.draw_texture(self._id_bg, { index = 0 })
|
|
tex.draw_texture(self._id_bg, { index = 1, mirror = "horizontal" })
|
|
tex.draw_texture(self._id_screen, { frame = math.floor(self.t / SCREEN_BEATS) % SCREENS })
|
|
self:draw_spots(0.5)
|
|
end
|
|
|
|
function SidemBGNormal:destroy() tex.unload_folder(COLLAB_PATH, "bg_normal/" .. self.name) end
|
|
|
|
-- Clear stage: over the normal one, cyan spotlights and brighter white ones fade in over a beat
|
|
-- while green lasers fan down from three points above the stage. Each point shows six of
|
|
-- twelve rays (35..145 degrees, 10 apart), a new set every 0.375 beat in a 1.5-beat cycle.
|
|
-- Losing clear cuts the lasers and fades the lights out over a beat. Timed in beats.
|
|
local FEVER_FADE = 1
|
|
local SPOT_ALPHA = 0.648
|
|
local WHITE_ALPHA = 0.352
|
|
local LASER_ALPHA = 0.488
|
|
local LASER_STEP = 0.375
|
|
local LASER_SETS = {
|
|
{ 35, 45, 75, 85, 115, 125 },
|
|
{ 45, 55, 85, 105, 115, 145 },
|
|
{ 55, 65, 95, 105, 135, 145 },
|
|
{ 35, 65, 75, 95, 125, 135 },
|
|
}
|
|
local LASER_ORIGINS = { -7.5, 632.5, 1272.5 }
|
|
local LASER_Y = 271.3
|
|
local LASER_PIVOT = 16 -- the ray's centre line in its image
|
|
|
|
local SidemBGFever = {}
|
|
SidemBGFever.__index = SidemBGFever
|
|
|
|
function SidemBGFever.new(bpm)
|
|
local self = setmetatable({}, SidemBGFever)
|
|
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_spotlight = id("spotlight")
|
|
self._id_laser = id("laser")
|
|
self.beat = 60000 / bpm
|
|
self.state = nil -- nil (hidden), "in", "out"
|
|
self.level = 0 -- 0..1 of the lights
|
|
return self
|
|
end
|
|
|
|
function SidemBGFever:start() self.state, self.t, self.from = "in", 0, self.level end
|
|
|
|
function SidemBGFever:stop()
|
|
if self.state ~= "in" then return end
|
|
self.state, self.t, self.from = "out", 0, self.level
|
|
end
|
|
|
|
function SidemBGFever:update(current_time_ms, bpm)
|
|
if bpm then self.beat = 60000 / bpm end
|
|
local dt = (current_time_ms - (self.last_ms or current_time_ms)) / self.beat
|
|
self.last_ms = current_time_ms
|
|
if not self.state then return end
|
|
self.t = self.t + dt
|
|
local k = math.min(1, self.t / FEVER_FADE)
|
|
if self.state == "in" then
|
|
self.level = self.from + (1 - self.from) * k
|
|
else
|
|
self.level = self.from * (1 - k)
|
|
if k >= 1 then self.state = nil end
|
|
end
|
|
end
|
|
|
|
function SidemBGFever:draw(bg_normal)
|
|
if not self.state then return end
|
|
local lv = self.level
|
|
tex.draw_texture(self._id_spotlight, { index = 0, fade = SPOT_ALPHA * lv, blend = "additive" })
|
|
tex.draw_texture(self._id_spotlight, { index = 1, fade = SPOT_ALPHA * lv, mirror = "horizontal", blend = "additive" })
|
|
bg_normal:draw_spots(WHITE_ALPHA * lv)
|
|
if self.state ~= "in" then return end
|
|
local set = LASER_SETS[math.floor(self.t / LASER_STEP) % #LASER_SETS + 1]
|
|
for _, x in ipairs(LASER_ORIGINS) do
|
|
for _, angle in ipairs(set) do
|
|
tex.draw_texture(self._id_laser, { x = x, y = LASER_Y, origin = { 0, LASER_PIVOT }, rotation = angle,
|
|
fade = LASER_ALPHA, blend = "additive" })
|
|
end
|
|
end
|
|
end
|
|
|
|
function SidemBGFever:destroy() tex.unload_folder(COLLAB_PATH, "bg_fever/" .. self.name) end
|
|
|
|
-- Line-up: jumps up, bounces 50px a beat swapping poses
|
|
local SIDEM_FEVER = { rise = 210, bounce = 50, drop = 380, poses = true }
|
|
|
|
-- Drumroll: notes fly up and to the right, the default renda_c flight
|
|
local RENDA = { ms = { 2000 }, dx = 1560, dy = -1648, x_range = 500, y_range = 20 }
|
|
|
|
-- Dancers: all three jump up from below, land with a squash, dance a 4-beat routine (two
|
|
-- 2-beat phrases: a half-beat pose, two 0.375s and three quarters) and squash, hop and drop
|
|
-- away when removed. Timed in beats; poses are offsets of Lumen's dancer origin (y 670), which
|
|
-- sits 312px down the images and is the pivot for the squash, so the feet stay put.
|
|
local SIDEM_DANCERS = Dancer.define({ default = {
|
|
origin = { 120, 312 },
|
|
enter = {
|
|
beats = 2,
|
|
{ 0, 0, 0, 312, to = { 0, -48, "out" } }, -- jumps up from below
|
|
{ 0.675, 0, 0, -48, to = { 0, 0, "in" } },
|
|
{ 0.925, 0, 0, 0, to = { nil, nil, nil, sx = 1.03, sy = 0.95 } }, -- lands with a squash
|
|
{ 1.025, 0, 0, 0, sx = 1.02, sy = 0.97, to = { nil, nil, nil, sx = 1, sy = 1 } },
|
|
{ 1.1, 0, 0, 0 },
|
|
},
|
|
dance = Timing.steps({
|
|
{ 0, 0.5, x = 0, y = 0 }, { 1, 0.375 }, { 2, 0.375 }, { 3, 0.25 }, { 4, 0.25 }, { 5, 0.25 },
|
|
{ 6, 0.5 }, { 7, 0.375 }, { 8, 0.375 }, { 9, 0.25 }, { 10, 0.25 }, { 11, 0.25 },
|
|
}),
|
|
leave = {
|
|
beats = 1.45,
|
|
{ 0, 0, 0, 0, to = { nil, nil, nil, sy = 0.95 } },
|
|
{ 0.125, 0, 0, 0, sy = 0.96, to = { 0, -40, "out", sy = 1 } }, -- hops up and drops away
|
|
{ 0.475, 0, 0, -40, to = { 0, 382, "in" } },
|
|
},
|
|
} })
|
|
|
|
-- Slots (left, centre, right) from Lumen's dancer positions; centre on top
|
|
local DANCER_CENTERS = { 427, 640, 853 }
|
|
local DANCER_DRAW_ORDER = { 3, 1, 2 }
|
|
local DANCER_SPAWN = { 1, 0, 2 } -- 0-indexed slots in join order: centre, left, right
|
|
-- dancer index by join order: dancer1 (centre), dancer2 (left), dancer3 (right)
|
|
local DANCER_JOIN_ORDER = { 2, 1, 0 }
|
|
|
|
-- Chibis for good hits: an energy drink or an AP bar hops in growing from 70% size, then bobs
|
|
-- across the don band in a zig-zag. They run 20px left of BaseChibi's run, which texture.json
|
|
-- takes (x 540, not 560), so the hop starts 20px right of Lumen's.
|
|
local SIDEM_CHIBIS = {}
|
|
for key = 0, 1 do
|
|
SIDEM_CHIBIS[key + 1] = {
|
|
key = tostring(key),
|
|
hop = { from = { -408, 13 }, peak = { -338, -36 }, up = 0.25 },
|
|
run = { y = 8 },
|
|
wave = { first = -32, height = 32, beats = 0.45 },
|
|
}
|
|
end
|
|
|
|
-- Background
|
|
|
|
local ImasSidemBackground = {}
|
|
ImasSidemBackground.__index = ImasSidemBackground
|
|
|
|
function ImasSidemBackground.new(player_num, bpm)
|
|
local self = setmetatable({}, ImasSidemBackground)
|
|
self.donbg = SparkleDonBG.new(player_num, COLLAB_PATH, SIDEM_DONBG, SIDEM_STARS)
|
|
self.bg_normal = SidemBGNormal.new(bpm)
|
|
self.bg_fever = SidemBGFever.new(bpm)
|
|
self.footer = Footer.new(COLLAB_PATH, 0, { false, true })
|
|
self.fever = Fever.new(bpm, COLLAB_PATH, SIDEM_FEVER)
|
|
self.dancer = Dancer.BaseDancerGroup.new(0, bpm, MAX_DANCERS, COLLAB_PATH, SIDEM_DANCERS)
|
|
self.dancer.spawn_positions = DANCER_SPAWN
|
|
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, 0)
|
|
self.is_clear = false
|
|
self.is_rainbow = false
|
|
self.last_milestone = 1
|
|
return self
|
|
end
|
|
|
|
function ImasSidemBackground:update(current_ms, bpm)
|
|
self.donbg:update(current_ms, bpm)
|
|
self.bg_normal: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 ImasSidemBackground:add_chibi(player_num)
|
|
BaseChibi.add(self.chibi, SIDEM_CHIBIS[math.random(#SIDEM_CHIBIS)], COLLAB_PATH, player_num, ChibiWave, "chibi_0")
|
|
end
|
|
|
|
function ImasSidemBackground:handle_good(player_num) self:add_chibi(player_num) end
|
|
|
|
function ImasSidemBackground:handle_ok(player_num) self:add_chibi(player_num) end
|
|
|
|
function ImasSidemBackground:handle_bad(player_num) self.chibi:add_chibi(player_num, true) end
|
|
|
|
function ImasSidemBackground:handle_drumroll(player_num) self.renda:add_renda() end
|
|
|
|
function ImasSidemBackground:handle_balloon(player_num) self.renda:add_renda() end
|
|
|
|
function ImasSidemBackground: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 ImasSidemBackground:draw_back()
|
|
self.bg_normal:draw()
|
|
self.bg_fever:draw(self.bg_normal)
|
|
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 ImasSidemBackground:draw_fore() end
|
|
|
|
function ImasSidemBackground: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 ImasSidemBackground
|