summaryrefslogtreecommitdiff
path: root/collisions.lua
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-05-28 21:01:02 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-05-28 21:01:02 -0700
commit16c1140ead99064799113eb3d8ddcf47929bba70 (patch)
tree39222a2af7491afaf0efd7fa9b5771d0283c78cc /collisions.lua
parent661156ce988131eb4896a7af4d00a42b520305e7 (diff)
downloaddyl8-main.tar.gz
dyl8-main.zip
Adding debug collision boxes, making bullets hurt you, and be able to kill bullets upon consumptionHEADmain
Diffstat (limited to 'collisions.lua')
-rw-r--r--collisions.lua26
1 files changed, 22 insertions, 4 deletions
diff --git a/collisions.lua b/collisions.lua
index 3d3ba46..093d57c 100644
--- a/collisions.lua
+++ b/collisions.lua
@@ -5,9 +5,24 @@ function is_colliding(a, b)
)
end
+_kills = {
+ vec2(Entities.Sword, Entities.Bullet)
+}
+function kills(a, b)
+ return some(_kills, function (v) return a.entity_type == v.x and b.entity_type == v.y end)
+end
+_consume = {
+ -- Consume the bullet as soon as it hits a target
+ vec2(Entities.Player, Entities.Bullet),
+ vec2(Entities.Wife, Entities.Bullet)
+}
+function consume(a, b)
+ return some(_consume, function (v) return a.entity_type == v.x and b.entity_type == v.y end)
+end
_hurts = {
vec2(Entities.Bullet, Entities.Player),
vec2(Entities.Sword, Entities.Enemy),
+ vec2(Entities.Enemy, Entities.Player)
}
function hurts(a, b)
if b:is_in_iframe() then
@@ -26,6 +41,12 @@ function handle_collision(a, b)
end
if hurts(a, b) then
b:take_damage(a.line_of_sight, a.damage)
+ if consume(b, a) then
+ a:kill()
+ end
+ end
+ if kills(a, b) then
+ b:kill()
end
end
@@ -36,10 +57,7 @@ function run_collisions()
if a.id == b.id then
goto continue
end
- if is_colliding(
- {top_left = (a.collision_bounds.top_left + a.position), bottom_right = (a.collision_bounds.bottom_right + a.position) },
- {top_left = (b.collision_bounds.top_left + b.position), bottom_right = (b.collision_bounds.bottom_right + b.position) }
- ) then
+ if is_colliding(a:collision_box(), b:collision_box()) then
handle_collision(a, b)
end
::continue::