proper player and general collision disposal for gc
This commit is contained in:
parent
5cbd3385c8
commit
9f389e5232
3 changed files with 15 additions and 2 deletions
|
|
@ -16,9 +16,14 @@ end
|
||||||
---Updates area
|
---Updates area
|
||||||
---@param dt number
|
---@param dt number
|
||||||
function Area:update(dt)
|
function Area:update(dt)
|
||||||
for i, game_object in ipairs(self.game_objects) do
|
for i = #self.game_objects, 1, -1 do
|
||||||
if game_object:isDead() then table.remove(self.game_objects, i) end
|
local game_object = self.game_objects[i]
|
||||||
|
|
||||||
game_object:update(dt)
|
game_object:update(dt)
|
||||||
|
|
||||||
|
if game_object:isDead() then
|
||||||
|
table.remove(self.game_objects, i)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ function GameObject:new(area, x, y, opts)
|
||||||
self.id = UUID()
|
self.id = UUID()
|
||||||
self.dead = false
|
self.dead = false
|
||||||
self.timer = Timer()
|
self.timer = Timer()
|
||||||
|
self.collider = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
---Updates game object
|
---Updates game object
|
||||||
|
|
@ -36,6 +37,10 @@ function GameObject:destroy()
|
||||||
self.timer:clear() -- cancel all tweens/after/every
|
self.timer:clear() -- cancel all tweens/after/every
|
||||||
self.timer = nil
|
self.timer = nil
|
||||||
end
|
end
|
||||||
|
if self.collider then
|
||||||
|
self.area.world:remove(self.collider)
|
||||||
|
self.collider = nil
|
||||||
|
end
|
||||||
self.dead = true
|
self.dead = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ end
|
||||||
|
|
||||||
function Player:update(dt)
|
function Player:update(dt)
|
||||||
Player.super.update(self, dt)
|
Player.super.update(self, dt)
|
||||||
|
if self:isDead() then return end
|
||||||
|
|
||||||
-- controls
|
-- controls
|
||||||
if input:down('left') then self.r = self.r - self.rv*dt end
|
if input:down('left') then self.r = self.r - self.rv*dt end
|
||||||
|
|
@ -41,6 +42,8 @@ function Player:update(dt)
|
||||||
|
|
||||||
-- move collision area
|
-- move collision area
|
||||||
self.collider:moveTo(self.x, self.y)
|
self.collider:moveTo(self.x, self.y)
|
||||||
|
|
||||||
|
if input:pressed('f2') then self:kill() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:draw()
|
function Player:draw()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue