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

98 lines
2 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"
local VictoryScreen = require "scenes.battlesystem.gui.screens.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)
2019-08-14 13:56:25 +02:00
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()
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()
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)
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()
2021-09-16 22:06:15 +02:00
BattleSystem.super.draw(self)
if (self.screen ~= nil) then
self.screen:draw()
end
end
function BattleSystem:exit()
self.world:destroy()
self.battlearena = nil
collectgarbage()
end
return BattleSystem