summaryrefslogtreecommitdiff
path: root/objects
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-12 17:55:00 +0800
committerEltrac <hi@guhub.cn>2025-03-12 17:55:00 +0800
commit6b48551d59818b385200221f0a42afea0a3545d5 (patch)
treea3403b639567693f25462a5aaf74ffba8a42ccf3 /objects
parent4bfe8d7679bfce861c03cff728d1aa9f44efeff9 (diff)
fix: game crash when creating new body during world update
use a body lifecycle manager to create after world update is done
Diffstat (limited to 'objects')
-rw-r--r--objects/Loot.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/objects/Loot.lua b/objects/Loot.lua
index c8cd51f..9c272a1 100644
--- a/objects/Loot.lua
+++ b/objects/Loot.lua
@@ -1,4 +1,5 @@
local Body = require "objects.Body"
+local physics = require "logic.physics"
local Loot = {}
Loot.__index = Loot
@@ -12,16 +13,22 @@ function Loot:new(name, x, y)
}
setmetatable(obj, Loot)
+ G.BodyLifeCycleManager:create(obj, config.lootSize, "static")
return obj
end
-function Loot:update(dt)
+function Loot:onContact(other)
local loots = G.currentRoom.objects.loots
- if self.body:collide(G.player.body, self.x, self.y, G.player.x, G.player.y) then
+ if other.objectType == "player" then
local pickedLoot = table.remove(loots, utils.indexof(loots, self))
table.insert(G.player.hearts, pickedLoot.type)
+ self.physicsBody:destroy()
end
end
+function Loot:update(dt)
+ -- nothing yet
+end
+
return Loot