local DonBG4 = require("background/bg_objects/donbg/4") 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 COLLAB_PATH = "background/collab/kumamon" local MAX_DANCERS = 5 -- BGFever: sunburst backdrop with the prefecture map and local produce local KumamonBGFever = {} KumamonBGFever.__index = KumamonBGFever function KumamonBGFever.new() local self = setmetatable({}, KumamonBGFever) self.name = "bg_fever_0" tex.load_folder(COLLAB_PATH, "bg_fever/" .. self.name) -- sunburst rays flicker between two frames every half-second, matching -- the source movie's 60-frame flicker cycle self.ray_flicker = anim.texture_change(1000, { { 0, 500, 0 }, { 500, 1000, 1 } }, { loop = true }) self.ray_flicker:start() -- produce icon strip scrolls right and wraps around (source uses a long -- single-image cycle -- a position tween, not a frame-swap animation) self.produce_texture = tex.get_texture_info(self.name, "produce") self.produce_move = anim.move(8000, { total_distance = self.produce_texture.width, loop = true }) self.produce_move:start() self._id_bg = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "background") or 0 self._id_rays = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "rays") or 0 self._id_map = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "map") or 0 self._id_produce = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "produce") or 0 return self end function KumamonBGFever:start() end function KumamonBGFever:update(current_time_ms) self.ray_flicker:update(current_time_ms) self.produce_move:update(current_time_ms) end function KumamonBGFever:draw() tex.draw_texture(self._id_bg) tex.draw_texture(self._id_rays, { frame = self.ray_flicker.attribute }) tex.draw_texture(self._id_map) local pw = self.produce_texture.width local x = -self.produce_move.attribute % pw tex.draw_texture(self._id_produce, { x = x - pw }) tex.draw_texture(self._id_produce, { x = x }) end function KumamonBGFever:destroy() tex.unload_folder(COLLAB_PATH, "bg_fever/" .. self.name) end -- Background local KumamonBackground = {} KumamonBackground.__index = KumamonBackground function KumamonBackground.new(player_num, bpm) local self = setmetatable({}, KumamonBackground) self.donbg = DonBG4.new(1, player_num, COLLAB_PATH) self.bg_normal = BGNormal.Base.new(0, COLLAB_PATH) self.bg_fever = KumamonBGFever.new() self.footer = Footer.new(COLLAB_PATH, -1) self.fever = Fever.create(0, bpm, COLLAB_PATH) self.dancer = Dancer.BaseDancerGroup.new(0, bpm, MAX_DANCERS, COLLAB_PATH) for i, d in ipairs(self.dancer.dancers) do if d.index == 4 then self.dancer.dancers[i], self.dancer.dancers[1] = self.dancer.dancers[1], self.dancer.dancers[i] break end end self.renda = RendaController.new(COLLAB_PATH, 0) self.chibi = ChibiController.new(bpm, COLLAB_PATH, 1) self.is_clear = false self.is_rainbow = false self.last_milestone = 1 tex.load_folder(COLLAB_PATH, "dodai") self._id_dodai = tex.get_texture(COLLAB_PATH .. "/" .. "dodai" .. "/" .. "dodai") or 0 return self end function KumamonBackground:update(current_ms, bpm) self.donbg:update(current_ms) self.bg_fever:update(current_ms) 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 KumamonBackground:handle_good(player_num) self.chibi:add_chibi(player_num, false) end function KumamonBackground:handle_ok(player_num) self.chibi:add_chibi(player_num, false) end function KumamonBackground:handle_bad(player_num) self.chibi:add_chibi(player_num, true) end function KumamonBackground:handle_drumroll(player_num) self.renda:add_renda() end function KumamonBackground:handle_balloon(player_num) self.renda:add_renda() end function KumamonBackground:handle_gauge(player_num, progress, is_clear, is_rainbow) self.donbg:set_clear(is_clear) if is_rainbow and not self.is_rainbow then self.fever:start() 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:remove_dancer() end self.last_milestone = current_milestone end end function KumamonBackground:draw_back() if self.is_clear then self.bg_fever:draw() else self.bg_normal:draw() end tex.draw_texture(self._id_dodai) self.donbg:draw() self.renda:draw() self.dancer:draw() self.footer:draw() if self.is_rainbow then self.fever:draw() end self.chibi:draw() end function KumamonBackground:draw_fore() end function KumamonBackground: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() tex.unload_folder(COLLAB_PATH, "dodai") end return KumamonBackground