flix

0.81.0

Collide

Axis-aligned rectangle overlap.

Deliberately ordinary code rather than anything clever. Collision runs on every entity pair on every step, so it stays a plain pure function -- a Datalog formulation would be a nice exercise for a discrete problem like formation adjacency, but it is the wrong tool for a hot per-frame loop.

Definitions

def overlaps(aPos: { aPos = Vec2 }, aSize: { aSize = Vec2 }, bPos: { bPos = Vec2 }, bSize: { bSize = Vec2 }): Bool§ Source

Whether two rectangles overlap.

Positions are centres, not corners, which is how everything in the game is stored and drawn. Touching exactly at the edge does not count as a hit: the comparison is strict, so a bullet grazing an invader's boundary passes by. Picking one convention and testing it matters more than which one it is.

All four arguments are named. They are structurally identical Vec2s, so a transposed pair would compile, type-check, and silently change collision.