local DonBGBase = require("background/bg_objects/donbg/base") 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/mario" local MAX_DANCERS = 5 local DONBG_SCALE = 184 / 64 local MarioDonBG = setmetatable({}, { __index = DonBGBase }) MarioDonBG.__index = MarioDonBG function MarioDonBG.new(index, player_num, path) local self = setmetatable({}, MarioDonBG) local base = DonBGBase.new(index, player_num, path) for k, v in pairs(base) do self[k] = v end self.tile_width = self.bg_texture.width * DONBG_SCALE local duration = 3000 * DONBG_SCALE * 2 self.move = anim.move(duration, { total_distance = -self.tile_width, loop = true }) self.move:start() return self end function MarioDonBG:draw_textures(fade, y, frame) for i = 0, 4 do tex.draw_texture(self._id_bg, { frame = frame, fade = fade, x = (i * self.tile_width) + self.move.attribute, y = y }) end end local BGN_SCALE = 360 / 128 local MarioBGNormal = {} MarioBGNormal.__index = MarioBGNormal function MarioBGNormal.new(move) local self = setmetatable({}, MarioBGNormal) self.name = "bg_0" tex.load_folder(COLLAB_PATH, "bg_normal/" .. self.name) self.move = move self.bg_texture = tex.get_texture_info(self.name, "background") self.tile_width = self.bg_texture.width * BGN_SCALE self.block_flicker = anim.texture_change(600, { { 0, 300, 0 }, { 300, 600, 1 } }, { loop = true }) self.block_flicker:start() self._id_bg = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "background") or 0 self._id_block_flicker = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "block_flicker") or 0 return self end function MarioBGNormal:update(current_time_ms) self.block_flicker:update(current_time_ms) end function MarioBGNormal:draw() local w = self.tile_width local x = self.move.attribute % w for _, dx in ipairs({ x - w, x }) do tex.draw_texture(self._id_bg, { x = dx }) tex.draw_texture(self._id_block_flicker, { frame = self.block_flicker.attribute, x = dx }) end end function MarioBGNormal:destroy() tex.unload_folder(COLLAB_PATH, "bg_normal/" .. self.name) end local MarioBGFever = {} MarioBGFever.__index = MarioBGFever function MarioBGFever.new() local self = setmetatable({}, MarioBGFever) self.name = "bg_fever_0" tex.load_folder(COLLAB_PATH, "bg_fever/" .. self.name) self._id_bg = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "background") or 0 self._id_icon1 = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "icon1") or 0 self._id_icon2 = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "icon2") or 0 return self end function MarioBGFever:start() end function MarioBGFever:update(current_time_ms) end function MarioBGFever:draw() tex.draw_texture(self._id_bg) tex.draw_texture(self._id_icon1) tex.draw_texture(self._id_icon2) end function MarioBGFever:destroy() tex.unload_folder(COLLAB_PATH, "bg_fever/" .. self.name) end local MarioFever = {} MarioFever.__index = MarioFever function MarioFever.new(bpm) local self = setmetatable({}, MarioFever) self.name = "fever_0" tex.load_folder(COLLAB_PATH, "fever/" .. self.name) local half_beat = (60000 / bpm) / 2 self.bounce_up = anim.move(half_beat, { total_distance = 30, ease_out = "quadratic" }) self.bounce_down = anim.move(half_beat, { total_distance = 30, ease_in = "quadratic", delay = half_beat }) self._id_goomba = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "goomba") or 0 self._id_mushroom = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "mushroom") or 0 self._id_toad = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "toad") or 0 self._id_peach = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "peach") or 0 self._id_koopa = tex.get_texture(COLLAB_PATH .. "/" .. self.name .. "/" .. "koopa") or 0 return self end function MarioFever:start() self.bounce_up:start() self.bounce_down:start() end function MarioFever:update(current_time_ms, bpm) self.bounce_up:update(current_time_ms) self.bounce_down:update(current_time_ms) if self.bounce_down.is_finished then local half_beat = (60000 / bpm) / 2 self.bounce_up = anim.move(half_beat, { total_distance = 30, ease_out = "quadratic" }) self.bounce_down = anim.move(half_beat, { total_distance = 30, ease_in = "quadratic", delay = half_beat }) self.bounce_up:start() self.bounce_down:start() end end function MarioFever:draw() local y = self.bounce_down.attribute - self.bounce_up.attribute tex.draw_texture(self._id_goomba, { y = y }) tex.draw_texture(self._id_mushroom, { y = y }) tex.draw_texture(self._id_toad, { y = y }) tex.draw_texture(self._id_peach, { y = y }) tex.draw_texture(self._id_koopa, { y = y }) end function MarioFever:destroy() tex.unload_folder(COLLAB_PATH, "fever/" .. self.name) end -- Background local MarioBackground = {} MarioBackground.__index = MarioBackground function MarioBackground.new(player_num, bpm) local self = setmetatable({}, MarioBackground) self.donbg = MarioDonBG.new(1, player_num, COLLAB_PATH) self.bg_normal = MarioBGNormal.new(self.donbg.move) self.bg_fever = MarioBGFever.new() self.footer = Footer.new(COLLAB_PATH, -1) self.fever = MarioFever.new(bpm) self.dancer = Dancer.BaseDancerGroup.new(0, bpm, MAX_DANCERS, COLLAB_PATH) 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 MarioBackground:update(current_ms, bpm) self.donbg:update(current_ms) self.bg_normal: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 MarioBackground:handle_good(player_num) self.chibi:add_chibi(player_num, false) end function MarioBackground:handle_ok(player_num) self.chibi:add_chibi(player_num, false) end function MarioBackground:handle_bad(player_num) self.chibi:add_chibi(player_num, true) end function MarioBackground:handle_drumroll(player_num) self.renda:add_renda() end function MarioBackground:handle_balloon(player_num) self.renda:add_renda() end function MarioBackground: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 MarioBackground: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 MarioBackground:draw_fore() end function MarioBackground: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 MarioBackground