diff options
Diffstat (limited to 'collisions.lua')
| -rw-r--r-- | collisions.lua | 30 |
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 |
