163 lines
3.7 KiB
Lua
163 lines
3.7 KiB
Lua
local Controller = Object:extend()
|
|
--local GUI = require "modules.gui"
|
|
local Assets = require "core.modules.assets"
|
|
|
|
local folder = "scenes.subgame.sonic-boost.controller."
|
|
|
|
local HUD = require(folder .. "hud")
|
|
local Background = require(folder .. "background")
|
|
local Camera = require(folder .. "camera")
|
|
local World = require(folder .. "world")
|
|
--local PauseMenu = require(folder .. "pause")
|
|
|
|
local CharacterManager = require(folder .. "characters")
|
|
|
|
local zoneDatas = require "datas.subgame.sonic-boost.levels.zones"
|
|
|
|
local LoadAssets = require(folder .. "loader")
|
|
|
|
function Controller:new(levelid, character)
|
|
self:initMission()
|
|
|
|
self.assets = Assets()
|
|
--self.gui = GUI()
|
|
LoadAssets(self)
|
|
|
|
self:initManagers()
|
|
|
|
self:resetFont()
|
|
|
|
self.levelid = levelid
|
|
self.character = character
|
|
|
|
if self.datas.music ~= nil then
|
|
local filepath = "assets/music/" .. self.datas.music .. ".mp3"
|
|
print(filepath)
|
|
self.assets:setMusic(filepath)
|
|
self.assets:playMusic()
|
|
end
|
|
|
|
self.pause = false
|
|
self.initiated = false
|
|
|
|
self.world:loadWorld()
|
|
|
|
self.characters:newPlayer("sonic", 2)
|
|
--self.characters:newDummy("sonic", 0)
|
|
--self.characters:newDummy("sonic", 1)
|
|
--self.characters:newDummy("sonic", 3)
|
|
--self.characters:newDummy("sonic", 4)
|
|
end
|
|
|
|
function Controller:restartLevel()
|
|
self:new(self.levelid, self.character)
|
|
end
|
|
|
|
function Controller:exitLevel()
|
|
Gamestate.switch(Scenes.options)
|
|
end
|
|
|
|
function Controller:initManagers()
|
|
--self.loader = Loader()
|
|
self.world = World(self)
|
|
self.hud = HUD(self)
|
|
self.camera = Camera(self, 0, 0)
|
|
self.background = Background(self)
|
|
self.characters = CharacterManager(self)
|
|
--self.pausemenu = PauseMenu(self)
|
|
end
|
|
|
|
function Controller:destroy()
|
|
self.world:destroy()
|
|
|
|
|
|
self.world = nil
|
|
self.hud = nil
|
|
self.camera = nil
|
|
self.background = nil
|
|
self.characters = nil
|
|
--self.pausemenu = nil
|
|
|
|
self.assets:clear()
|
|
end
|
|
|
|
function Controller:initMission(levelid)
|
|
self:getLevelData(levelid)
|
|
|
|
self.mission = {}
|
|
self.mission.timer = 0
|
|
self.mission.completed = false
|
|
end
|
|
|
|
function Controller:startMission()
|
|
self.initiated = true
|
|
end
|
|
|
|
function Controller:getLevelData(file)
|
|
local file = file or "testlevel.test1"
|
|
local level = require("datas.subgame.sonic-boost.levels." .. file)
|
|
|
|
self.zone = level.datas.zone
|
|
|
|
local zone_data = zoneDatas[self.zone]
|
|
local bypass_data = level.datas.bypass_data
|
|
|
|
self.datas = {}
|
|
|
|
if (level.datas.bypass_zone) then
|
|
self.datas.name = bypass_data.name or zone_data.name
|
|
self.datas.borders = bypass_data.borders or zone_data.borders
|
|
self.datas.tiles = bypass_data.tiles or zone_data.tiles
|
|
self.datas.background = bypass_data.background or zone_data.background
|
|
self.datas.music = bypass_data.music or zone_data.music
|
|
else
|
|
self.datas = zone_data
|
|
end
|
|
|
|
self.layout = level.layout
|
|
self.parts = level.parts
|
|
self.endless_parts = level.endless_parts
|
|
|
|
self.missiondata = level.datas.missiondata
|
|
|
|
end
|
|
|
|
function Controller:update(dt)
|
|
|
|
if self.pause == false then
|
|
self.assets:update(dt)
|
|
self.mission.timer = self.mission.timer + dt
|
|
self.world:update(dt)
|
|
self.camera:update(dt)
|
|
else
|
|
--self.pausemenu:update(dt)
|
|
end
|
|
|
|
if core.input.keys["start"].isPressed then
|
|
self.pause = (self.pause == false)
|
|
end
|
|
|
|
end
|
|
|
|
function Controller:draw()
|
|
|
|
self.background:draw()
|
|
|
|
self.camera.view:attach()
|
|
self.world:draw()
|
|
self.camera.view:detach()
|
|
|
|
utils.graphics.resetColor()
|
|
self.hud:draw()
|
|
|
|
if self.pause == true then
|
|
--self.pausemenu:draw(dt)
|
|
end
|
|
|
|
end
|
|
|
|
function Controller:resetFont()
|
|
self.assets.fonts["text"]:set()
|
|
end
|
|
|
|
return Controller
|