2021-05-05 08:30:32 +02:00
|
|
|
local Scene = require "birb.modules.scenes"
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2019-03-10 13:26:20 +01:00
|
|
|
local BattleSystem = Scene:extend()
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
local World = require "scenes.battlesystem.world"
|
2020-08-20 15:33:28 +02:00
|
|
|
local MenuSystem = require "scenes.battlesystem.menus.controller"
|
2020-05-01 14:50:21 +02:00
|
|
|
local Turns = require "scenes.battlesystem.controllers"
|
2019-03-10 13:26:20 +01:00
|
|
|
|
2019-08-16 22:37:43 +02:00
|
|
|
local VictoryScreen = require "scenes.battlesystem.screens.victory"
|
2020-08-07 11:17:10 +02:00
|
|
|
local GameOverScreen = require "scenes.battlesystem.screens.gameover"
|
2019-08-16 22:37:43 +02:00
|
|
|
|
2021-03-13 18:00:39 +01:00
|
|
|
local TweenManager = require "game.modules.tweenmanager"
|
|
|
|
|
2020-08-04 17:50:03 +02:00
|
|
|
function BattleSystem:new(battleData)
|
2019-03-10 13:33:38 +01:00
|
|
|
BattleSystem.super.new(self)
|
2019-08-14 13:56:25 +02:00
|
|
|
|
2019-08-13 21:08:37 +02:00
|
|
|
self.assets:batchImport("scenes.battlesystem.assets")
|
|
|
|
|
2020-08-04 17:50:03 +02:00
|
|
|
self:playMusic(battleData.music)
|
2019-08-19 12:00:24 +02:00
|
|
|
|
2020-08-04 17:50:03 +02:00
|
|
|
self:initManagers(battleData)
|
2019-03-10 13:33:38 +01:00
|
|
|
|
|
|
|
self:register()
|
2019-08-16 18:33:47 +02:00
|
|
|
|
|
|
|
self:startBattle()
|
2019-08-16 22:37:43 +02:00
|
|
|
|
|
|
|
self.screen = nil
|
2021-03-13 18:00:39 +01:00
|
|
|
self.tweens = TweenManager(self)
|
2019-03-10 13:26:20 +01:00
|
|
|
end
|
|
|
|
|
2020-08-04 17:50:03 +02:00
|
|
|
function BattleSystem:playMusic(music)
|
|
|
|
self.assets:setMusic("assets/music/" .. music .. ".mp3")
|
|
|
|
self.assets:playMusic()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleSystem:initManagers(battleData)
|
2019-03-10 13:26:20 +01:00
|
|
|
self.datas = {}
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world = World(self)
|
2019-03-23 11:51:47 +01:00
|
|
|
self.menu = MenuSystem(self)
|
2020-08-04 17:50:03 +02:00
|
|
|
self.turns = Turns(self, battleData)
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-08-16 18:33:47 +02:00
|
|
|
function BattleSystem:startBattle()
|
2020-05-01 14:50:21 +02:00
|
|
|
self.turns:startBattle()
|
2019-08-16 18:33:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function BattleSystem:finishBattle()
|
2019-08-19 12:00:24 +02:00
|
|
|
self.assets:setMusic("assets/music/victory.mp3")
|
|
|
|
self.assets:playMusic()
|
2019-08-16 22:37:43 +02:00
|
|
|
self.screen = VictoryScreen(self)
|
2019-08-16 18:33:47 +02:00
|
|
|
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
|
2021-04-02 22:25:26 +02:00
|
|
|
self:returnToOverworld(true)
|
2021-03-13 18:00:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-02 22:25:26 +02:00
|
|
|
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
|
|
|
|
|
2019-08-24 15:44:07 +02:00
|
|
|
function BattleSystem:haveMenus()
|
|
|
|
for k,v in pairs(self.menusystem.menus) do
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2019-03-10 13:11:26 +01:00
|
|
|
function BattleSystem:update(dt)
|
2021-03-13 18:00:39 +01:00
|
|
|
self.tweens:update(dt)
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world:update(dt)
|
2020-05-01 14:50:21 +02:00
|
|
|
self.turns:update(dt)
|
2019-08-16 22:37:43 +02:00
|
|
|
if (self.screen ~= nil) then
|
|
|
|
self.screen:update(dt)
|
|
|
|
end
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function BattleSystem:draw()
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world:draw()
|
2020-07-19 16:20:57 +02:00
|
|
|
self.turns:draw()
|
2019-08-16 22:37:43 +02:00
|
|
|
if (self.screen ~= nil) then
|
|
|
|
self.screen:draw()
|
|
|
|
end
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-03-10 13:26:20 +01:00
|
|
|
function BattleSystem:exit()
|
|
|
|
self.world:destroy()
|
|
|
|
self.battlearena = nil
|
2019-03-10 13:11:26 +01:00
|
|
|
|
|
|
|
collectgarbage()
|
|
|
|
end
|
|
|
|
|
|
|
|
return BattleSystem
|