summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-12 16:24:36 +0800
committerEltrac <hi@guhub.cn>2025-03-12 16:24:36 +0800
commite2e128d6d925e132de5092faa91c26705826653d (patch)
tree4f395524fd14a47f330b35b423933bfeee17cdcb /main.lua
parent66b583bcfad32261c9cd44df8f13b39024c441a7 (diff)
refactor: damage enemy on shot contact, not on detecting bullets itself
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index bf25f8b..0781c5f 100644
--- a/main.lua
+++ b/main.lua
@@ -67,4 +67,14 @@ function onContact(a, b, contact)
local otherBody = (a:getBody() == playerBody) and b:getBody() or a:getBody()
G.player:onContact(otherBody, contact)
end
+
+ -- Determine if one of the bodies belongs to a shot
+ for _, shot in ipairs(G.currentRoom.objects.shots) do
+ if a:getBody() == shot.physicsBody or b:getBody() == shot.physicsBody then
+ -- Identify the other body
+ -- and deal with shot body contact
+ local otherBody = (a:getBody() == shot.body) and b:getBody() or a:getBody()
+ shot:onContact(otherBody, contact)
+ end
+ end
end