feat(cbs): initial functions to start and finish the battle
This commit is contained in:
parent
b3428da090
commit
92e77e4335
3 changed files with 50 additions and 12 deletions
BIN
sonic-radiance.love/assets/gui/strings/battle_completed.png
Normal file
BIN
sonic-radiance.love/assets/gui/strings/battle_completed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
|
@ -13,6 +13,8 @@ function BattleSystem:new()
|
|||
self:initManagers()
|
||||
|
||||
self:register()
|
||||
|
||||
self:startBattle()
|
||||
end
|
||||
|
||||
function BattleSystem:initManagers()
|
||||
|
@ -21,6 +23,14 @@ function BattleSystem:initManagers()
|
|||
self.menu = MenuSystem(self)
|
||||
end
|
||||
|
||||
function BattleSystem:startBattle()
|
||||
self.world:startBattle()
|
||||
end
|
||||
|
||||
function BattleSystem:finishBattle()
|
||||
|
||||
end
|
||||
|
||||
function BattleSystem:update(dt)
|
||||
self.world:update(dt)
|
||||
end
|
||||
|
|
|
@ -43,6 +43,8 @@ function World:new(scene, battlefile)
|
|||
self:initHeroes()
|
||||
self:initEnnemies()
|
||||
self:initHUD()
|
||||
|
||||
self.isBattleActive = false
|
||||
end
|
||||
|
||||
function World:initHeroes(battlefile)
|
||||
|
@ -177,7 +179,9 @@ function World:update(dt)
|
|||
actor:update(dt)
|
||||
end
|
||||
|
||||
if (self.isBattleActive) then
|
||||
self:updateTurns(dt)
|
||||
end
|
||||
self:moveBattleCursor(dt)
|
||||
|
||||
self.cursor:update(dt)
|
||||
|
@ -200,6 +204,10 @@ end
|
|||
-- TURNS FUNCTIONS
|
||||
-- Handle everything related to the turn system
|
||||
|
||||
function World:startBattle()
|
||||
self.isBattleActive = true
|
||||
end
|
||||
|
||||
function World:recalculateTurns()
|
||||
self:generateActionList()
|
||||
table.sort(self.actionlist, maputils.sortBattlers)
|
||||
|
@ -212,23 +220,41 @@ function World:updateTurns(dt)
|
|||
end
|
||||
|
||||
function World:switchActiveBattler()
|
||||
if (self:countEnnemies()==0) then
|
||||
self:finishBattle()
|
||||
else
|
||||
if (self.turns.isFinished) or (self.turns.current >= #self.actionlist) then
|
||||
core.debug:print("cbs/world", "turn finished")
|
||||
self.turns.current = 1
|
||||
self.turns.isFinished = false
|
||||
self.turns.number = self.turns.number + 1
|
||||
self:recalculateTurns()
|
||||
self:switchToNextTurn()
|
||||
else
|
||||
self.turns.current = self.turns.current + 1
|
||||
core.debug:print("cbs/world", "switching to action number " .. self.turns.current)
|
||||
end
|
||||
|
||||
self:selectNextAction()
|
||||
self.turns.changeBattler = false
|
||||
end
|
||||
end
|
||||
|
||||
function World:switchToNextTurn()
|
||||
core.debug:print("cbs/world", "turn finished")
|
||||
self.turns.current = 1
|
||||
self.turns.isFinished = false
|
||||
self.turns.number = self.turns.number + 1
|
||||
self:recalculateTurns()
|
||||
end
|
||||
|
||||
function World:selectNextAction()
|
||||
if (self.actionlist[self.turns.current].actor.isDestroyed == true) then
|
||||
self:switchActiveBattler()
|
||||
else
|
||||
self.actionlist[self.turns.current].actor:setActive()
|
||||
end
|
||||
self.turns.changeBattler = false
|
||||
end
|
||||
|
||||
function World:finishBattle()
|
||||
self.isBattleActive = false
|
||||
self.actionlist = {}
|
||||
self.scene:finishBattle()
|
||||
end
|
||||
|
||||
function World:sendSignalToCurrentBattler()
|
||||
|
@ -273,7 +299,9 @@ function World:drawHUD()
|
|||
end
|
||||
local cursorx = self.BattlerCursor * 20 - 6
|
||||
|
||||
if #self.actionlist > 0 then
|
||||
self.assets.images["menucursor"]:draw(cursorx, 26, math.rad(-90), 1, 1, 4, 8)
|
||||
end
|
||||
|
||||
for i,v in ipairs(self.battlers) do
|
||||
v:drawHUD()
|
||||
|
|
Loading…
Reference in a new issue