feat(cbs): make player HUD appear only if the battle is currently active

This commit is contained in:
Kazhnuz 2019-08-16 18:40:00 +02:00
parent 92e77e4335
commit c9b3175bcd
2 changed files with 18 additions and 7 deletions

View file

@ -229,7 +229,7 @@ function Hero:drawHUD()
local HUDBASE = 8 local HUDBASE = 8
local HUDSEP = 152 local HUDSEP = 152
local x = HUDBASE + (self.charnumber-1)*HUDSEP local x = HUDBASE + (self.charnumber-1)*HUDSEP
local y = 36 local y = self.world:getPlayerHUDPosition()
self.assets.images["e_speedster"]:draw(x, y) self.assets.images["e_speedster"]:draw(x, y)
core.screen:setScissor(x, y-16, 32, 40) core.screen:setScissor(x, y-16, 32, 40)

View file

@ -37,6 +37,8 @@ function World:new(scene, battlefile)
self.heroNumber = 0 self.heroNumber = 0
self.ennNumber = 0 self.ennNumber = 0
self.playerHUDPosition = -64
self.map = Map(self, "city") self.map = Map(self, "city")
self.cursor = Cursor(self) self.cursor = Cursor(self)
@ -171,6 +173,10 @@ function World:countEnnemies()
return count return count
end end
function World:getPlayerHUDPosition()
return self.playerHUDPosition
end
-- UPDATE FUNCTION -- UPDATE FUNCTION
-- Update all actors -- Update all actors
@ -181,6 +187,11 @@ function World:update(dt)
if (self.isBattleActive) then if (self.isBattleActive) then
self:updateTurns(dt) 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 end
self:moveBattleCursor(dt) self:moveBattleCursor(dt)
@ -294,8 +305,12 @@ function World:initHUD()
end end
function World:drawHUD() function World:drawHUD()
for i,v in ipairs(self.actionlist) do for i, battler in ipairs(self.battlers) do
v.actor:drawIcon(4 + (i-1)*(20), 6) battler:drawHUD()
end
for i, action in ipairs(self.actionlist) do
action.actor:drawIcon(4 + (i-1)*(20), 6)
end end
local cursorx = self.BattlerCursor * 20 - 6 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) self.assets.images["menucursor"]:draw(cursorx, 26, math.rad(-90), 1, 1, 4, 8)
end end
for i,v in ipairs(self.battlers) do
v:drawHUD()
end
local x, y = 362, 3 local x, y = 362, 3
love.graphics.draw(self.frame, 424, 20, 0, -1, -1) love.graphics.draw(self.frame, 424, 20, 0, -1, -1)