From e2e128d6d925e132de5092faa91c26705826653d Mon Sep 17 00:00:00 2001 From: Eltrac Date: Wed, 12 Mar 2025 16:24:36 +0800 Subject: refactor: damage enemy on shot contact, not on detecting bullets itself --- main.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'main.lua') 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 -- cgit v1.2.3