From 33cf1a9f7fe9a87923db11f8d1e2a7cf756a690a Mon Sep 17 00:00:00 2001 From: Eltrac Date: Wed, 12 Mar 2025 17:58:31 +0800 Subject: refactor: use lifecycle manager to destroy all bodies --- objects/Enemy.lua | 2 +- objects/Loot.lua | 2 +- objects/Shot.lua | 2 +- objects/room.lua | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'objects') diff --git a/objects/Enemy.lua b/objects/Enemy.lua index 2ab24b8..9c28c3c 100644 --- a/objects/Enemy.lua +++ b/objects/Enemy.lua @@ -120,7 +120,7 @@ function Enemy:die() end local enemies = G.currentRoom.objects.enemies - self.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(self.physicsBody) table.remove(enemies, utils.indexof(enemies, self)) end diff --git a/objects/Loot.lua b/objects/Loot.lua index 9c272a1..b7ea2c5 100644 --- a/objects/Loot.lua +++ b/objects/Loot.lua @@ -23,7 +23,7 @@ function Loot:onContact(other) if other.objectType == "player" then local pickedLoot = table.remove(loots, utils.indexof(loots, self)) table.insert(G.player.hearts, pickedLoot.type) - self.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(self.physicsBody) end end diff --git a/objects/Shot.lua b/objects/Shot.lua index 3a07a7b..67caadd 100644 --- a/objects/Shot.lua +++ b/objects/Shot.lua @@ -37,7 +37,7 @@ end function Shot:die() local shots = G.currentRoom.objects.shots table.remove(shots, utils.indexof(shots, self)) - self.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(self.physicsBody) end function Shot:onContact(other, contact) diff --git a/objects/room.lua b/objects/room.lua index 39552bc..3415660 100644 --- a/objects/room.lua +++ b/objects/room.lua @@ -245,11 +245,11 @@ end function Room:removeAllBodies() for _, group in pairs(self.objects) do for _, obj in ipairs(group) do - obj.physicsBody:destroy() + G.BodyLifeCycleManager:destroy(obj.physicsBody) end end for _, wall in ipairs(self.walls) do - wall.body:destroy() + G.BodyLifeCycleManager:destroy(wall.body) end end -- cgit v1.2.3