diff --git a/sonic-radiance.love/assets/gui/strings/battle_completed.png b/sonic-radiance.love/assets/gui/strings/battle_completed.png new file mode 100644 index 0000000..8157042 Binary files /dev/null and b/sonic-radiance.love/assets/gui/strings/battle_completed.png differ diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 2eab6c1..5fdc3b9 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -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 diff --git a/sonic-radiance.love/scenes/battlesystem/world.lua b/sonic-radiance.love/scenes/battlesystem/world.lua index 80f274c..d43b0fa 100644 --- a/sonic-radiance.love/scenes/battlesystem/world.lua +++ b/sonic-radiance.love/scenes/battlesystem/world.lua @@ -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 - self:updateTurns(dt) + 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.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() + if (self:countEnnemies()==0) then + self:finishBattle() else - self.turns.current = self.turns.current + 1 - core.debug:print("cbs/world", "switching to action number " .. self.turns.current) - end + if (self.turns.isFinished) or (self.turns.current >= #self.actionlist) then + 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 - 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 v:drawHUD()