From eccaf776870de4003e552bf5524f46b75d75ee6e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 8 Sep 2019 12:34:16 +0200 Subject: [PATCH] feat(example): add a respawn timer --- examples/gameplay/plateform/actors/player.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/gameplay/plateform/actors/player.lua b/examples/gameplay/plateform/actors/player.lua index 2541525..f964a0a 100644 --- a/examples/gameplay/plateform/actors/player.lua +++ b/examples/gameplay/plateform/actors/player.lua @@ -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)