refactor(levels): use a gamecore timer to handle debris diseappearing

This commit is contained in:
Kazhnuz 2019-06-17 12:02:57 +02:00
parent 39a998d773
commit 8a9dc05c61
1 changed files with 7 additions and 5 deletions

View File

@ -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