2019-02-03 20:00:08 +01:00
|
|
|
local Scene = require "core.modules.scenes"
|
2019-02-04 08:40:41 +01:00
|
|
|
local BoostLevel = Scene:extend()
|
2019-02-04 09:35:12 +01:00
|
|
|
|
|
|
|
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")
|
2019-02-10 20:00:37 +01:00
|
|
|
local PauseMenu = require(folder .. "pause")
|
2019-02-04 09:35:12 +01:00
|
|
|
|
|
|
|
local CharacterManager = require(folder .. "characters")
|
|
|
|
|
|
|
|
local zoneDatas = require "datas.subgame.sonic-boost.levels.zones"
|
|
|
|
|
|
|
|
local LoadAssets = require(folder .. "loader")
|
2019-02-03 19:54:02 +01:00
|
|
|
|
2019-02-03 20:00:08 +01:00
|
|
|
function BoostLevel:new()
|
2019-02-04 08:40:06 +01:00
|
|
|
BoostLevel.super.new(self)
|
2019-02-04 09:35:12 +01:00
|
|
|
self:initMission()
|
|
|
|
|
|
|
|
LoadAssets(self)
|
|
|
|
|
|
|
|
self:initManagers()
|
|
|
|
|
|
|
|
self:resetFont()
|
|
|
|
|
|
|
|
self.levelid = nil
|
|
|
|
self.character = nil
|
|
|
|
|
|
|
|
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.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)
|
2019-02-04 08:43:48 +01:00
|
|
|
|
|
|
|
self:register()
|
2019-02-03 19:54:02 +01:00
|
|
|
end
|
|
|
|
|
2019-02-04 09:30:03 +01:00
|
|
|
function BoostLevel: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)
|
2019-02-11 20:34:25 +01:00
|
|
|
|
|
|
|
PauseMenu(self)
|
2019-02-04 09:30:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function BoostLevel:initMission(levelid)
|
|
|
|
self:getLevelData(levelid)
|
|
|
|
|
|
|
|
self.mission = {}
|
|
|
|
self.mission.timer = 0
|
|
|
|
self.mission.completed = false
|
|
|
|
end
|
|
|
|
|
|
|
|
function BoostLevel:startMission()
|
|
|
|
self.initiated = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function BoostLevel: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
|
|
|
|
|
2019-02-03 19:58:13 +01:00
|
|
|
function BoostLevel:update(dt)
|
2019-02-11 20:34:25 +01:00
|
|
|
if self.menusystem.menus["pauseMenu"].isActive == false then
|
2019-02-04 09:35:12 +01:00
|
|
|
self.assets:update(dt)
|
|
|
|
self.mission.timer = self.mission.timer + dt
|
|
|
|
self.world:update(dt)
|
|
|
|
self.camera:update(dt)
|
|
|
|
end
|
|
|
|
|
2019-02-04 09:38:16 +01:00
|
|
|
if self.keys["start"].isPressed then
|
2019-02-11 20:34:25 +01:00
|
|
|
if not (self.menusystem.menus["pauseMenu"].isActive) then
|
|
|
|
self.menusystem.menus["pauseMenu"].isActive = true
|
|
|
|
self.menusystem.menus["pauseMenu"].isVisible = true
|
2019-02-15 18:37:03 +01:00
|
|
|
self.menusystem.menus["pauseMenu"]:getFocus()
|
2019-02-15 18:38:41 +01:00
|
|
|
self.assets.isActive = false
|
2019-02-11 20:34:25 +01:00
|
|
|
else
|
|
|
|
self.menusystem.menus["pauseMenu"].isActive = false
|
|
|
|
self.menusystem.menus["pauseMenu"].isVisible = false
|
2019-02-15 18:38:41 +01:00
|
|
|
self.assets.isActive = true
|
2019-02-11 20:34:25 +01:00
|
|
|
end
|
2019-02-04 09:35:12 +01:00
|
|
|
end
|
2019-02-03 19:54:02 +01:00
|
|
|
end
|
|
|
|
|
2019-02-03 19:58:13 +01:00
|
|
|
function BoostLevel:draw()
|
2019-02-04 09:35:12 +01:00
|
|
|
self.background:draw()
|
|
|
|
|
|
|
|
self.camera.view:attach()
|
|
|
|
self.world:draw()
|
|
|
|
self.camera.view:detach()
|
|
|
|
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
self.hud:draw()
|
2019-02-03 19:54:02 +01:00
|
|
|
end
|
|
|
|
|
2019-02-04 09:30:03 +01:00
|
|
|
function BoostLevel:resetFont()
|
|
|
|
self.assets.fonts["text"]:set()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BoostLevel:restartLevel()
|
|
|
|
self:new(self.levelid, self.character)
|
|
|
|
end
|
|
|
|
|
|
|
|
function BoostLevel:exitLevel()
|
|
|
|
Gamestate.switch(Scenes.options)
|
|
|
|
end
|
|
|
|
|
2019-02-03 19:58:13 +01:00
|
|
|
function BoostLevel:leave()
|
2019-02-04 09:35:12 +01:00
|
|
|
self.world:destroy()
|
|
|
|
|
|
|
|
|
|
|
|
self.world = nil
|
|
|
|
self.hud = nil
|
|
|
|
self.camera = nil
|
|
|
|
self.background = nil
|
|
|
|
self.characters = nil
|
|
|
|
--self.pausemenu = nil
|
|
|
|
|
|
|
|
self.assets:clear()
|
2019-02-03 19:54:02 +01:00
|
|
|
|
|
|
|
collectgarbage()
|
|
|
|
end
|
|
|
|
|
2019-02-03 19:58:13 +01:00
|
|
|
return BoostLevel
|