From 25a582821f1db217ed371637678f15b7fcea7ce3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 May 2019 19:50:33 +0200 Subject: [PATCH] modules/world: only check collision if the object isn't being destroyed --- gamecore/modules/world/actors/actor2D.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index c58f759..16101de 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -76,6 +76,7 @@ end function Actor2D:register() self.world:registerActor(self) + self.isDestroyed = false end function Actor2D:setBounceFactor(newBounceFactor) @@ -84,6 +85,7 @@ end function Actor2D:destroy() self.world:removeActor(self) + self.isDestroyed = true end -- INPUT FUNCTIONS @@ -165,7 +167,7 @@ end function Actor2D:checkGroundX() 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 if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then @@ -178,7 +180,7 @@ end function Actor2D:checkGroundY() 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 if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then @@ -190,8 +192,18 @@ function Actor2D:checkGroundY() end function Actor2D:move(dx, dy) - local cols, colNumber - self.x, self.y, cols, colNumber = self.world:moveActor(self, dx, dy, self.filter) + local cols, colNumber = {}, 0 + if (self.isDestroyed == false) then + 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 end