From 8a9dc05c614b3a78c3132eeee361319716a10f07 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 17 Jun 2019 12:02:57 +0200 Subject: [PATCH] refactor(levels): use a gamecore timer to handle debris diseappearing --- .../scenes/levels/entities/debris.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/imperium-porcorum.love/scenes/levels/entities/debris.lua b/imperium-porcorum.love/scenes/levels/entities/debris.lua index 1bdfc48..183deed 100644 --- a/imperium-porcorum.love/scenes/levels/entities/debris.lua +++ b/imperium-porcorum.love/scenes/levels/entities/debris.lua @@ -4,9 +4,10 @@ local Debris = Entity:extend() function Debris:new(world, x, y, speed, dir, timelimit) Debris.super.new(self, world, "debris", x - 4, y - 4, 8, 8) - self.life = 0; - self.timer = 0 - self.timelimit = timelimit or 2 + local timelimit = timelimit or 2 + + self:addTimer("timelimit", timelimit) + self:setMotionDirection(dir, speed) self:setGravityFlag(true) self:setBounceFactor(0.5) @@ -31,9 +32,10 @@ function Debris:updateEnd(dt) if (isInsideView == false) then self:destroy() end +end - self.timer = self.timer + dt - if (self.timer >= self.timelimit) then +function Debris:timerResponse(timer) + if (timer == "timelimit") then self:destroy() end end