feat(example): add a respawn timer

This commit is contained in:
Kazhnuz 2019-09-08 12:34:16 +02:00
parent e40ea3cfab
commit eccaf77687
1 changed files with 18 additions and 0 deletions

View File

@ -9,6 +9,8 @@ function Player:new(world, x, y, id)
self.isPunching = false
self.direction = 1
self.startx, self.starty = self.x, self.y
self.isDead = false
self.punchName = ""
self:setHitboxFile("examples.gameplay.plateform.actors.hitboxes.player")
@ -55,6 +57,13 @@ end
function Player:updateEnd(dt)
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
function Player:setAnimation()
@ -83,6 +92,15 @@ function Player:setDirection(direction)
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)
if collision.other.type == "coin" then
collision.other.owner:takeCoin(self)