forked from Yonokid/PyTaikoGreen
95 lines
2.6 KiB
Lua
95 lines
2.6 KiB
Lua
local BaseChibi = require("background/bg_objects/chibi/base")
|
|
local Chibi0 = require("background/bg_objects/chibi/0")
|
|
local Chibi2 = require("background/bg_objects/chibi/2")
|
|
local Chibi4 = require("background/bg_objects/chibi/4")
|
|
local Chibi5 = require("background/bg_objects/chibi/5")
|
|
local Chibi8 = require("background/bg_objects/chibi/8")
|
|
local Chibi13 = require("background/bg_objects/chibi/13")
|
|
local ChibiBad = require("background/bg_objects/chibi/bad")
|
|
|
|
Chibi = {}
|
|
|
|
function Chibi.create(index, bpm, bad, is_2p, path)
|
|
path = path or "background"
|
|
|
|
if bad then
|
|
return ChibiBad.new(index, bpm, is_2p, path)
|
|
end
|
|
|
|
local map = {
|
|
Chibi0, -- index 0
|
|
BaseChibi, -- index 1
|
|
Chibi2, -- index 2
|
|
BaseChibi, -- index 3
|
|
Chibi4, -- index 4
|
|
Chibi5, -- index 5
|
|
BaseChibi, -- index 6
|
|
BaseChibi, -- index 7
|
|
Chibi8, -- index 8
|
|
BaseChibi, -- index 9
|
|
BaseChibi, -- index 10
|
|
BaseChibi, -- index 11
|
|
BaseChibi, -- index 12
|
|
Chibi13 -- index 13
|
|
}
|
|
|
|
local selected_class = map[index + 1]
|
|
return selected_class.new(index, bpm, is_2p, path)
|
|
end
|
|
|
|
ChibiController = {}
|
|
ChibiController.__index = ChibiController
|
|
|
|
function ChibiController.new(bpm, path, index)
|
|
path = path or "background"
|
|
index = index or math.random(0, 13)
|
|
bpm = bpm or 120
|
|
|
|
local self = setmetatable({}, ChibiController)
|
|
|
|
self.chibis = {}
|
|
self.index = index
|
|
self.name = "chibi_" .. index
|
|
self.bpm = bpm
|
|
self.path = path
|
|
|
|
tex.load_folder(path, "chibi/" .. self.name)
|
|
tex.load_folder("background", "chibi/chibi_bad")
|
|
|
|
return self
|
|
end
|
|
|
|
function ChibiController:add_chibi(player_num, bad)
|
|
bad = bad or false
|
|
local is_2p = player_num == 2
|
|
table.insert(self.chibis, Chibi.create(self.index, self.bpm, bad, is_2p, self.path))
|
|
end
|
|
|
|
function ChibiController:update(current_time_ms, bpm)
|
|
if bpm then
|
|
self.bpm = bpm
|
|
end
|
|
|
|
for i = #self.chibis, 1, -1 do
|
|
local chibi = self.chibis[i]
|
|
chibi:update(current_time_ms, self.bpm)
|
|
|
|
if chibi.hori_move and chibi.hori_move.is_finished then
|
|
table.remove(self.chibis, i)
|
|
end
|
|
end
|
|
end
|
|
|
|
function ChibiController:draw()
|
|
for _, chibi in ipairs(self.chibis) do
|
|
chibi:draw()
|
|
end
|
|
end
|
|
|
|
function ChibiController:destroy()
|
|
tex.unload_folder(self.path, "chibi/" .. self.name)
|
|
tex.unload_folder("background", "chibi/chibi_bad")
|
|
end
|
|
|
|
return ChibiController
|