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
|
-- UPDATE and COLLISION functions
|
||||||
-- Physics and function called every game update
|
-- 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)
|
function Player:updateStart(dt)
|
||||||
self.keys = self.scene.sources[1].keys
|
self.keys = self.scene.sources[1].keys
|
||||||
|
|
||||||
|
@ -200,6 +209,12 @@ end
|
||||||
|
|
||||||
-- DRAW functions
|
-- DRAW functions
|
||||||
|
|
||||||
|
function Player:draw()
|
||||||
|
if (self.isAlive) then
|
||||||
|
Player.super.draw(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Player:setAnimation()
|
function Player:setAnimation()
|
||||||
local animation = "idle"
|
local animation = "idle"
|
||||||
self:setSpriteScallingX(self.direction)
|
self:setSpriteScallingX(self.direction)
|
||||||
|
@ -245,7 +260,7 @@ function Player:drawHUD()
|
||||||
local weapon = 0
|
local weapon = 0
|
||||||
love.graphics.draw(self.itembox, 16, 16)
|
love.graphics.draw(self.itembox, 16, 16)
|
||||||
|
|
||||||
if (true) then
|
if (self.isAlive) then
|
||||||
hp = self.hp / self.stats.maxHP
|
hp = self.hp / self.stats.maxHP
|
||||||
mp = self.mp / self.stats.maxMP
|
mp = self.mp / self.stats.maxMP
|
||||||
weapon = self.weapon
|
weapon = self.weapon
|
||||||
|
@ -267,11 +282,11 @@ function Player:drawHUD()
|
||||||
utils.graphics.resetColor()
|
utils.graphics.resetColor()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:getScore(score)
|
function Player:addScore(score)
|
||||||
self.score = self.score + score
|
self.score = self.score + score
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:getGold(gold)
|
function Player:addGold(gold)
|
||||||
self.gold = self.gold + gold
|
self.gold = self.gold + gold
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -281,6 +296,8 @@ end
|
||||||
function Player:resetLife()
|
function Player:resetLife()
|
||||||
self.hp = self.stats.maxHP
|
self.hp = self.stats.maxHP
|
||||||
self.mp = self.stats.maxMP
|
self.mp = self.stats.maxMP
|
||||||
|
|
||||||
|
self.isAlive = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:takeHit(damage)
|
function Player:takeHit(damage)
|
||||||
|
|
Loading…
Reference in New Issue