diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-12 16:24:36 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-12 16:24:36 +0800 |
| commit | e2e128d6d925e132de5092faa91c26705826653d (patch) | |
| tree | 4f395524fd14a47f330b35b423933bfeee17cdcb /main.lua | |
| parent | 66b583bcfad32261c9cd44df8f13b39024c441a7 (diff) | |
refactor: damage enemy on shot contact, not on detecting bullets itself
Diffstat (limited to 'main.lua')
| -rw-r--r-- | main.lua | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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 |
