From 078eca583eec21d317e931c84db8f084bef4305d Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Wed, 22 Apr 2026 15:58:41 -0700 Subject: Snapshot --- collisions.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 collisions.lua (limited to 'collisions.lua') 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 -- cgit v1.3