sonic-radiance/sonic-radiance.love/scenes/battlesystem/init.lua

105 lines
2.2 KiB
Lua
Raw Normal View History

2021-05-05 08:30:32 +02:00
local Scene = require "birb.modules.scenes"
local BattleSystem = Scene:extend()
local World = require "scenes.battlesystem.world"
local MenuSystem = require "scenes.battlesystem.gui.menus.controller"
2021-08-15 16:41:33 +02:00
local Turns = require "scenes.battlesystem.turns"
local VictoryScreen = require "scenes.battlesystem.gui.screens.victory"
local GameOverScreen = require "scenes.battlesystem.gui.screens.gameover"
local TweenManager = require "birb.classes.time"
2021-03-13 18:00:39 +01:00
function BattleSystem:new(battleData)
BattleSystem.super.new(self)
2019-08-14 13:56:25 +02:00
self.assets:batchImport("assets.commons")
self.assets:batchImport("assets.battle")
self:playMusic(battleData.music)
2019-08-19 12:00:24 +02:00
self:initManagers(battleData)
self:register()
self:startBattle()
self.screen = nil
2021-03-13 18:00:39 +01:00
self.tweens = TweenManager(self)
end
function BattleSystem:playMusic(music)
self.assets:setMusic("assets/music/" .. music .. ".mp3")
self.assets:playMusic()
end
function BattleSystem:initManagers(battleData)
self.datas = {}
self.world = World(self)
self.menu = MenuSystem(self)
self.turns = Turns(self, battleData)
end
function BattleSystem:startBattle()
2020-05-01 14:50:21 +02:00
self.turns:startBattle()
end
function BattleSystem:finishBattle()
2019-08-19 12:00:24 +02:00
self.assets:setMusic("assets/music/victory.mp3")
self.assets:playMusic()
self.screen = VictoryScreen(self)
end
2021-03-13 18:00:39 +01:00
function BattleSystem:fleeBattle()
self.tweens:newTimer(2, "flee")
end
function BattleSystem:timerResponse(name)
if (name == "flee") then
self:returnToOverworld(true)
2021-03-13 18:00:39 +01:00
end
end
function BattleSystem:returnToOverworld(isFleeing)
self.assets:silence()
game.cbs:endBattle(isFleeing)
end
2020-08-07 11:17:10 +02:00
function BattleSystem:looseBattle()
self.screen = GameOverScreen(self)
end
function BattleSystem:haveMenus()
for k,v in pairs(self.menusystem.menus) do
return true
end
return false
end
function BattleSystem:update(dt)
2021-03-13 18:00:39 +01:00
self.tweens:update(dt)
self.world:update(dt)
2020-05-01 14:50:21 +02:00
self.turns:update(dt)
if (self.screen ~= nil) then
self.screen:update(dt)
end
end
function BattleSystem:draw()
self.world:draw()
self.turns:draw()
if (self.screen ~= nil) then
self.screen:draw()
end
end
function BattleSystem:exit()
self.world:destroy()
self.battlearena = nil
collectgarbage()
end
return BattleSystem