collision resolution
No physics engine.
Circle ↔ AABB, solved by hand.
Every bounce is an explicit penetration test — clamp the ball's centre to the rectangle, compare overlap on each axis, resolve along the smaller one. Deepest overlap wins, one brick per substep.
-
Clamped point distance
cx = clamp(ball.x, x, x+w)— distance to that point ≤rmeans contact. Cheap, exact, no sqrt needed for the axis test. -
Min-penetration axis
penXvspenYdecide the wall. Flip only that velocity component and push the ball out by the overlap — so a brick can never swallow the ball. -
Deepest overlap wins
The ball's bounding box maps to a local grid window; candidates are scored and one is resolved per substep, so simultaneous hits never stack into a spiral.
-
Substepping
The ball moves in ≤2 px slices per frame, so at speed 4 it cannot tunnel through a 20 px brick — the classic breakout bug.
-
Paddle angle
Hit offset maps to ±60° off vertical, with a
|vy| ≥ 0.35·|v|floor so the ball never flattens into an endless horizontal rally.