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:initManagers()
|
||||||
|
|
||||||
self:register()
|
self:register()
|
||||||
|
|
||||||
|
self:startBattle()
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleSystem:initManagers()
|
function BattleSystem:initManagers()
|
||||||
|
@ -21,6 +23,14 @@ function BattleSystem:initManagers()
|
||||||
self.menu = MenuSystem(self)
|
self.menu = MenuSystem(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleSystem:startBattle()
|
||||||
|
self.world:startBattle()
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleSystem:finishBattle()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function BattleSystem:update(dt)
|
function BattleSystem:update(dt)
|
||||||
self.world:update(dt)
|
self.world:update(dt)
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,6 +43,8 @@ function World:new(scene, battlefile)
|
||||||
self:initHeroes()
|
self:initHeroes()
|
||||||
self:initEnnemies()
|
self:initEnnemies()
|
||||||
self:initHUD()
|
self:initHUD()
|
||||||
|
|
||||||
|
self.isBattleActive = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function World:initHeroes(battlefile)
|
function World:initHeroes(battlefile)
|
||||||
|
@ -177,7 +179,9 @@ function World:update(dt)
|
||||||
actor:update(dt)
|
actor:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
self:updateTurns(dt)
|
if (self.isBattleActive) then
|
||||||
|
self:updateTurns(dt)
|
||||||
|
end
|
||||||
self:moveBattleCursor(dt)
|
self:moveBattleCursor(dt)
|
||||||
|
|
||||||
self.cursor:update(dt)
|
self.cursor:update(dt)
|
||||||
|
@ -200,6 +204,10 @@ end
|
||||||
-- TURNS FUNCTIONS
|
-- TURNS FUNCTIONS
|
||||||
-- Handle everything related to the turn system
|
-- Handle everything related to the turn system
|
||||||
|
|
||||||
|
function World:startBattle()
|
||||||
|
self.isBattleActive = true
|
||||||
|
end
|
||||||
|
|
||||||
function World:recalculateTurns()
|
function World:recalculateTurns()
|
||||||
self:generateActionList()
|
self:generateActionList()
|
||||||
table.sort(self.actionlist, maputils.sortBattlers)
|
table.sort(self.actionlist, maputils.sortBattlers)
|
||||||
|
@ -212,23 +220,41 @@ function World:updateTurns(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function World:switchActiveBattler()
|
function World:switchActiveBattler()
|
||||||
if (self.turns.isFinished) or (self.turns.current >= #self.actionlist) then
|
if (self:countEnnemies()==0) then
|
||||||
core.debug:print("cbs/world", "turn finished")
|
self:finishBattle()
|
||||||
self.turns.current = 1
|
|
||||||
self.turns.isFinished = false
|
|
||||||
self.turns.number = self.turns.number + 1
|
|
||||||
self:recalculateTurns()
|
|
||||||
else
|
else
|
||||||
self.turns.current = self.turns.current + 1
|
if (self.turns.isFinished) or (self.turns.current >= #self.actionlist) then
|
||||||
core.debug:print("cbs/world", "switching to action number " .. self.turns.current)
|
self:switchToNextTurn()
|
||||||
end
|
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
|
if (self.actionlist[self.turns.current].actor.isDestroyed == true) then
|
||||||
self:switchActiveBattler()
|
self:switchActiveBattler()
|
||||||
else
|
else
|
||||||
self.actionlist[self.turns.current].actor:setActive()
|
self.actionlist[self.turns.current].actor:setActive()
|
||||||
end
|
end
|
||||||
self.turns.changeBattler = false
|
end
|
||||||
|
|
||||||
|
function World:finishBattle()
|
||||||
|
self.isBattleActive = false
|
||||||
|
self.actionlist = {}
|
||||||
|
self.scene:finishBattle()
|
||||||
end
|
end
|
||||||
|
|
||||||
function World:sendSignalToCurrentBattler()
|
function World:sendSignalToCurrentBattler()
|
||||||
|
@ -273,7 +299,9 @@ function World:drawHUD()
|
||||||
end
|
end
|
||||||
local cursorx = self.BattlerCursor * 20 - 6
|
local cursorx = self.BattlerCursor * 20 - 6
|
||||||
|
|
||||||
self.assets.images["menucursor"]:draw(cursorx, 26, math.rad(-90), 1, 1, 4, 8)
|
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
|
for i,v in ipairs(self.battlers) do
|
||||||
v:drawHUD()
|
v:drawHUD()
|
||||||
|
|
Loading…
Reference in a new issue