modules/world: only check collision if the object isn't being destroyed
This commit is contained in:
parent
a1ce249e00
commit
25a582821f
1 changed files with 16 additions and 4 deletions
|
@ -76,6 +76,7 @@ end
|
||||||
|
|
||||||
function Actor2D:register()
|
function Actor2D:register()
|
||||||
self.world:registerActor(self)
|
self.world:registerActor(self)
|
||||||
|
self.isDestroyed = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:setBounceFactor(newBounceFactor)
|
function Actor2D:setBounceFactor(newBounceFactor)
|
||||||
|
@ -84,6 +85,7 @@ end
|
||||||
|
|
||||||
function Actor2D:destroy()
|
function Actor2D:destroy()
|
||||||
self.world:removeActor(self)
|
self.world:removeActor(self)
|
||||||
|
self.isDestroyed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- INPUT FUNCTIONS
|
-- INPUT FUNCTIONS
|
||||||
|
@ -165,7 +167,7 @@ end
|
||||||
|
|
||||||
function Actor2D:checkGroundX()
|
function Actor2D:checkGroundX()
|
||||||
local dx, dy = self.x + utils.math.sign(self.xgrav), self.y
|
local dx, dy = self.x + utils.math.sign(self.xgrav), self.y
|
||||||
local newx, newy, cols, colNumber = self.world:checkCollision(self, dx, dy, self.filter)
|
local newx, newy, cols, colNumber = self:checkCollision(dx, dy)
|
||||||
|
|
||||||
for i, col in ipairs(cols) do
|
for i, col in ipairs(cols) do
|
||||||
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
||||||
|
@ -178,7 +180,7 @@ end
|
||||||
|
|
||||||
function Actor2D:checkGroundY()
|
function Actor2D:checkGroundY()
|
||||||
local dx, dy = self.x, self.y + utils.math.sign(self.ygrav)
|
local dx, dy = self.x, self.y + utils.math.sign(self.ygrav)
|
||||||
local newx, newy, cols, colNumber = self.world:checkCollision(self, dx, dy, self.filter)
|
local newx, newy, cols, colNumber = self:checkCollision(dx, dy)
|
||||||
|
|
||||||
for i, col in ipairs(cols) do
|
for i, col in ipairs(cols) do
|
||||||
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
||||||
|
@ -190,8 +192,18 @@ function Actor2D:checkGroundY()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:move(dx, dy)
|
function Actor2D:move(dx, dy)
|
||||||
local cols, colNumber
|
local cols, colNumber = {}, 0
|
||||||
|
if (self.isDestroyed == false) then
|
||||||
self.x, self.y, cols, colNumber = self.world:moveActor(self, dx, dy, self.filter)
|
self.x, self.y, cols, colNumber = self.world:moveActor(self, dx, dy, self.filter)
|
||||||
|
end
|
||||||
|
return self.x, self.y, cols, colNumber
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actor2D:checkCollision(dx, dy)
|
||||||
|
local x, y, cols, colNumber = dx, dy, {}, 0
|
||||||
|
if (self.isDestroyed == false) then
|
||||||
|
x, y, cols, colNumber = self.world:moveActor(self, dx, dy, self.filter)
|
||||||
|
end
|
||||||
return self.x, self.y, cols, colNumber
|
return self.x, self.y, cols, colNumber
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue