LIVE BUILD CANVAS 400 × 600 AABB COLLISION VANHILLA JS
SCREEN CRT-01FPS 60 · T 00:00

Mouse / arrows / A-D · drag on touch · SPACE launches · P pauses · R resets

ENGINE NOTES / COLLISION MODEL

Four rules keep the ball honest.

  1. 01

    AABB, inflated by radius

    The ball is treated as a square [x−r, x+r] × [y−r, y+r] against each brick rect. Overlap is measured on both axes, so contact never depends on the centre point crossing an edge.

  2. 02

    Least-penetration decides the side

    If overlapY < overlapX the ball entered through the top or bottom — flip dy. Otherwise it entered through a flank — flip dx. The ball is then pushed flush to that face, so it can never be re-absorbed by the same brick.

  3. 03

    One resolution per substep

    Movement is split into substeps of ≤2px and only the shallowest (nearest) overlapping brick is resolved per substep. Corner-brick clusters and tunnelling through 20px rows both die here.

  4. 04

    Speed is always renormalised

    Every bounce rebuilds the vector from the angle and the current magnitude, so energy never drifts. Anti-stall guards clamp the trajectory away from pure vertical and pure horizontal.

OFFSET −1.0 → +1.0 → ANGLE 0° → 60° INCOMING REFAN
Paddle reflection. The contact offset (x − paddleCentre) / halfWidth is clamped to ±1 and mapped onto a ±60° fan: dead-centre hits return straight up, edge hits scream off sideways. Paddle velocity is smeared into dx for a slice of english, then the whole vector is renormalised. Side faces of the paddle flip dx instead of swallowing the ball.