From c9b3175bcd71cd9814fbe94ac735041555e2cccb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 16 Aug 2019 18:40:00 +0200 Subject: [PATCH] feat(cbs): make player HUD appear only if the battle is currently active --- .../scenes/battlesystem/actors/hero.lua | 2 +- .../scenes/battlesystem/world.lua | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index 1a7dc95..37266b0 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -229,7 +229,7 @@ function Hero:drawHUD() local HUDBASE = 8 local HUDSEP = 152 local x = HUDBASE + (self.charnumber-1)*HUDSEP - local y = 36 + local y = self.world:getPlayerHUDPosition() self.assets.images["e_speedster"]:draw(x, y) core.screen:setScissor(x, y-16, 32, 40) diff --git a/sonic-radiance.love/scenes/battlesystem/world.lua b/sonic-radiance.love/scenes/battlesystem/world.lua index d43b0fa..67618f6 100644 --- a/sonic-radiance.love/scenes/battlesystem/world.lua +++ b/sonic-radiance.love/scenes/battlesystem/world.lua @@ -37,6 +37,8 @@ function World:new(scene, battlefile) self.heroNumber = 0 self.ennNumber = 0 + self.playerHUDPosition = -64 + self.map = Map(self, "city") self.cursor = Cursor(self) @@ -171,6 +173,10 @@ function World:countEnnemies() return count end +function World:getPlayerHUDPosition() + return self.playerHUDPosition +end + -- UPDATE FUNCTION -- Update all actors @@ -181,6 +187,11 @@ function World:update(dt) if (self.isBattleActive) then self:updateTurns(dt) + local dPosition = math.floor(self.playerHUDPosition + dt * 256) + self.playerHUDPosition = math.min(dPosition, 36) + else + local dPosition = math.floor(self.playerHUDPosition - dt * 256) + self.playerHUDPosition = math.max(dPosition, -64) end self:moveBattleCursor(dt) @@ -294,8 +305,12 @@ function World:initHUD() end function World:drawHUD() - for i,v in ipairs(self.actionlist) do - v.actor:drawIcon(4 + (i-1)*(20), 6) + for i, battler in ipairs(self.battlers) do + battler:drawHUD() + end + + for i, action in ipairs(self.actionlist) do + action.actor:drawIcon(4 + (i-1)*(20), 6) end local cursorx = self.BattlerCursor * 20 - 6 @@ -303,10 +318,6 @@ function World:drawHUD() 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() - end - local x, y = 362, 3 love.graphics.draw(self.frame, 424, 20, 0, -1, -1)