sonic-radiance/sonic-radiance.love/game/modules/subgames/init.lua

117 lines
2.6 KiB
Lua
Raw Permalink Normal View History

local Scene = require("game.scenes")
local PlayStyle = Scene:extend()
2022-01-06 18:57:42 +01:00
local TweenManager = require "birb.classes.time"
local PauseScreen = require("game.modules.subgames.pause")
local TestWorld = require("game.modules.subgames.world.parent")
function PlayStyle:new(supportedLevels, missionfile)
2022-01-06 18:57:42 +01:00
PlayStyle.super.new(self, false, false)
self.timer = 0
self.assets:batchImport("assets.subgames")
--self:loadMissionFile(supportedLevels, missionfile)
self:initWorld()
self:initMission()
self:initCharacters()
2022-01-06 18:57:42 +01:00
self.tweens = TweenManager(self)
PauseScreen()
2020-08-16 11:03:06 +02:00
self.haveStarted = false
2022-01-06 18:57:42 +01:00
self.canPause = true
end
function PlayStyle:loadMissionFile(supportedLevels, missionfile)
self.mission = require("datas.gamedata.missions." .. missionfile)
self.assets:setMusic("assets/music/" .. self.mission.music)
end
function PlayStyle:initWorld()
TestWorld(self)
end
function PlayStyle:initMission()
-- NOTHING
end
function PlayStyle:initCharacters()
self.world:setPlayerNumber(1)
self.world.cameras:setMode("split")
end
function PlayStyle:getCharacterName(charID)
return self.characterList[charID]
end
function PlayStyle:update(dt)
2020-08-16 11:03:06 +02:00
if (self.haveStarted) then
PlayStyle.super.update(self, dt)
self:updatePauseMenus(dt)
else
self:startLevel()
end
end
function PlayStyle:updatePauseMenus(dt)
2022-01-06 18:57:42 +01:00
self.tweens:update(dt)
if self.gui.screens["pauseScreen"].isVisible == false then
self.timer = self.timer + dt
end
local keys = self:getKeys(1);
2022-01-06 18:57:42 +01:00
if (keys["start"].isPressed and self.canPause) then
if (not self.isPaused) then
if (not self.gui.screens["overlay"].isVisible) then
self.assets.sfx["mSelect"]:play()
self:pause()
end
else
2022-01-06 18:57:42 +01:00
self.assets.sfx["mBack"]:play()
self:unpause()
end
end
end
2022-01-06 18:57:42 +01:00
function PlayStyle:timerResponse(timer)
if (timer == "unPause") then
self.isPaused = false
self.world.isActive = true
end
end
function PlayStyle:pause()
self.gui:showScreen("overlay")
self.gui:showScreen("pauseScreen")
self.gui:playScreenTransform("overlay", "showBackgroundPause")
self.isPaused = true
self.world.isActive = false
end
function PlayStyle:unpause()
self.tweens:newTimer(0.2, "unPause")
self.gui:playScreenTransform("overlay", "hideBackgroundPause")
self.gui:hideScreen("overlay")
self.gui:hideScreen("pauseScreen")
end
function PlayStyle:startLevel()
2020-08-16 11:03:06 +02:00
self.haveStarted = true
self.world:loadMap()
--self.assets:playMusic()
end
function PlayStyle:restartLevel()
2022-01-06 18:57:42 +01:00
self:unpause()
self.world:reset()
end
function PlayStyle:exitLevel()
2021-08-15 16:26:05 +02:00
scenes.menus.title()
end
return PlayStyle