summaryrefslogtreecommitdiff
path: root/collisions.lua
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-04-22 15:58:41 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-04-22 15:58:41 -0700
commit078eca583eec21d317e931c84db8f084bef4305d (patch)
tree76b303cdda70a87a5febaf57726d4f8779a387a3 /collisions.lua
parent3555b9ff88c3872c8f2dd8a8ab02382e2a7d0cb2 (diff)
downloaddyl8-078eca583eec21d317e931c84db8f084bef4305d.tar.gz
dyl8-078eca583eec21d317e931c84db8f084bef4305d.zip
Snapshot
Diffstat (limited to 'collisions.lua')
-rw-r--r--collisions.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/collisions.lua b/collisions.lua
new file mode 100644
index 0000000..fb7aca7
--- /dev/null
+++ b/collisions.lua
@@ -0,0 +1,30 @@
+sw, sh = 8, 8
+function is_colliding(a, b)
+ ax1, bx1 = a.pos.x, b.pos.x
+ ax2, bx2 = ax1 + sw, bx1 + sw
+ ay1, by1 = a.pos.y, b.pos.y
+ ay2, by2 = ay1 + sh, by1 + sh
+ return (ax1 < bx2 and ax2 > bx1
+ and ay1 < by2 and ay2 > by1)
+end
+
+function handle_collision(a, b)
+-- if b.typ == types.enemy then
+-- --print(b.id,100,100)
+-- end
+end
+
+function run_collisions()
+ collidable = filter(World, function (e) return e.collision end)
+ for _ai, a in ipairs(collidable) do
+ for _bi, b in ipairs(collidable) do
+ if a.id == b.id then
+ goto continue
+ end
+ if is_colliding(a, b) then
+ handle_collision(a, b)
+ end
+ ::continue::
+ end
+ end
+end \ No newline at end of file