Arcade build 01  //  vanilla canvas · no libraries

BREAK/OUT

Field 400×600
Grid 8×4 · 50×20
Peak score 320
Playfield Ready
Grid cleared 0/32

Arrows / mouse move the paddle · Space launches · P pauses · R restarts Drag anywhere on the playfield to slide the paddle · tap to launch

Under the hood

Collision model — explicit AABB, one resolution per frame

The ball is a 3px circle; bricks, paddle and walls are axis-aligned boxes. Each substep moves the ball by a fraction of its velocity, then the nearest surface is found by clamping the ball centre into each rect — the closest contact wins and only that one is resolved, so a wide hit never punches through two bricks at once.

The contact normal decides the response: top/bottom faces flip dy, side faces flip dx, corners reflect off the true normal. The ball is then pushed clear of the surface, so it can never be trapped inside a brick, and the velocity is renormalised so |v| stays constant (3.44 → 4.0 px/frame as the grid thins).

Paddle bounces ignore the incoming vector entirely: contact position across the 60px bar maps to a ±65° exit angle, plus a touch of paddle spin — edge hits skim sideways, centre hits rebound straight up.

// closest contact across all live bricks
const nx = clamp(ball.x, b.x, b.x + b.w);
const ny = clamp(ball.y, b.y, b.y + b.h);
const dx = ball.x - nx, dy = ball.y - ny;
if (dx*dx + dy*dy > R*R) continue;

// reflect about contact normal
const dot = ball.dx*ux + ball.dy*uy;
if (dot < 0) {
  ball.dx -= 2*dot*ux;   // side → ux=±1, uy=0
  ball.dy -= 2*dot*uy;   // top  → ux=0,  uy=-1
}
ball.x = nx + ux*(R + 0.5);  // never stick
renormalise(SPEED);          // |v| constant

// paddle: exit angle from hit position
rel = (ball.x - (px + PW/2)) / (PW/2);
ang = clamp(rel, -1, 1) * 65°;