feat(example): add a respawn timer

This commit is contained in:
Kazhnuz 2019-09-08 12:34:16 +02:00
parent e40ea3cfab
commit eccaf77687

View file

@ -9,6 +9,8 @@ function Player:new(world, x, y, id)
self.isPunching = false self.isPunching = false
self.direction = 1 self.direction = 1
self.startx, self.starty = self.x, self.y
self.isDead = false
self.punchName = "" self.punchName = ""
self:setHitboxFile("examples.gameplay.plateform.actors.hitboxes.player") self:setHitboxFile("examples.gameplay.plateform.actors.hitboxes.player")
@ -55,6 +57,13 @@ end
function Player:updateEnd(dt) function Player:updateEnd(dt)
self:setAnimation() self:setAnimation()
local width, height = self.world:getDimensions()
if (self.y > height + self.h) and (self.isDead == false) then
self:addTimer("respawn", 1)
self.isDead = true
end
end end
function Player:setAnimation() function Player:setAnimation()
@ -83,6 +92,15 @@ function Player:setDirection(direction)
end end
end end
function Player:timerResponse(timer)
if timer == "respawn" then
self.x, self.y = self.startx, self.starty
self.xspeed = 0
self.yspeed = 0
self.isDead = false
end
end
function Player:collisionResponse(collision) function Player:collisionResponse(collision)
if collision.other.type == "coin" then if collision.other.type == "coin" then
collision.other.owner:takeCoin(self) collision.other.owner:takeCoin(self)