refactor(levels): add a "isAlive" variable to manage player state
This commit is contained in:
parent
e16d36f301
commit
b9c041fbeb
|
@ -66,6 +66,15 @@ end
|
|||
-- UPDATE and COLLISION functions
|
||||
-- Physics and function called every game update
|
||||
|
||||
function Player:update(dt)
|
||||
if (self.isAlive) then
|
||||
Player.super.update(self, dt)
|
||||
else
|
||||
-- Only update timers if the player is dead
|
||||
self:updateTimers(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function Player:updateStart(dt)
|
||||
self.keys = self.scene.sources[1].keys
|
||||
|
||||
|
@ -200,6 +209,12 @@ end
|
|||
|
||||
-- DRAW functions
|
||||
|
||||
function Player:draw()
|
||||
if (self.isAlive) then
|
||||
Player.super.draw(self)
|
||||
end
|
||||
end
|
||||
|
||||
function Player:setAnimation()
|
||||
local animation = "idle"
|
||||
self:setSpriteScallingX(self.direction)
|
||||
|
@ -245,7 +260,7 @@ function Player:drawHUD()
|
|||
local weapon = 0
|
||||
love.graphics.draw(self.itembox, 16, 16)
|
||||
|
||||
if (true) then
|
||||
if (self.isAlive) then
|
||||
hp = self.hp / self.stats.maxHP
|
||||
mp = self.mp / self.stats.maxMP
|
||||
weapon = self.weapon
|
||||
|
@ -267,11 +282,11 @@ function Player:drawHUD()
|
|||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
function Player:getScore(score)
|
||||
function Player:addScore(score)
|
||||
self.score = self.score + score
|
||||
end
|
||||
|
||||
function Player:getGold(gold)
|
||||
function Player:addGold(gold)
|
||||
self.gold = self.gold + gold
|
||||
end
|
||||
|
||||
|
@ -281,6 +296,8 @@ end
|
|||
function Player:resetLife()
|
||||
self.hp = self.stats.maxHP
|
||||
self.mp = self.stats.maxMP
|
||||
|
||||
self.isAlive = true
|
||||
end
|
||||
|
||||
function Player:takeHit(damage)
|
||||
|
|
Loading…
Reference in New Issue