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

87 lines
1.8 KiB
Lua
Raw Normal View History

local Scene = require "game.scenes"
local BattleSystem = Scene:extend()
local World = require "scenes.battlesystem.world"
2021-08-15 16:41:33 +02:00
local Turns = require "scenes.battlesystem.turns"
2021-09-18 21:31:17 +02:00
local VictoryScreen = require "scenes.battlesystem.gui.victory"
2021-09-16 22:06:59 +02:00
local GameOverScreen = require "game.modules.gui.gameover"
local CbsScreen = require "scenes.battlesystem.gui"
local TweenManager = require "birb.classes.time"
2021-03-13 18:00:39 +01:00
function BattleSystem:new(battleData)
BattleSystem.super.new(self, false, false)
self.assets:batchImport("assets.battle")
self:playMusic(battleData.music)
self:initManagers(battleData)
self:startBattle()
CbsScreen()
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.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()
2021-09-18 21:31:17 +02:00
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()
2021-09-16 22:06:59 +02:00
GameOverScreen(self)
2020-08-07 11:17:10 +02:00
end
function BattleSystem:haveMenus()
return self.gui.elements["battleMenu"].isVisible
end
function BattleSystem:update(dt)
2021-03-13 18:00:39 +01:00
self.tweens:update(dt)
2020-05-01 14:50:21 +02:00
self.turns:update(dt)
2021-09-18 21:31:17 +02:00
self.world:update(dt)
end
function BattleSystem:exit()
self.world:destroy()
self.battlearena = nil
collectgarbage()
end
return BattleSystem