Cabinet 01 · Canvas 2D · Vanilla JS

Brick·Breaker

400×600 field, 32 bricks, 3 lives, a 3px ball that never changes speed — only direction. Closest AABB hit is resolved per frame; the paddle angle is mapped from where you actually hit it.

  • No libs
  • 60 FPS fixed step
  • Touch drag
  • DPR-aware buffer
INSERT COIN ▮
Screen · 400×60060 fps

Under the hood

Explicit collision math — no physics engine, no easing tricks. Every bounce is an axis-aligned box test plus a penetration-depth tie-break.

01

AABB overlap, closest hit wins

The ball is treated as a 6×6 box. Every live brick that overlaps is measured, and only the candidate with the smallest penetration depth is resolved — one brick destroyed per frame, so the ball can never chew through two bricks or get wedged in a seam.

02

The shortest axis decides the bounce

min(left, right, top, bottom) penetration identifies the face: top/bottom flips dy, left/right flips dx, then the ball is pushed flush to that face. Flipping components preserves velocity magnitude exactly.

03

Paddle angle is a hit-position map

Hit offset is normalised to -1…1 across the 60px paddle. Edges steer hard sideways, the centre stays near-vertical, and dy is always rebuilt upward so the ball never crawls along the paddle.

04

Fixed timestep, refresh-rate agnostic

An accumulator steps physics in 1/60s slices with a 5-step cap, so a 120 Hz phone and a 60 Hz desktop behave identically. Rendering happens once per requestAnimationFrame.

05

Touch that doesn't fight the browser

touchstart / touchmove / touchend with {passive:false} and touch-action:none; finger x is mapped through getBoundingClientRect() into canvas space and lerped onto the paddle, clamped to 0…340. Landscape and portrait both work down to 320px.

06

Everything drawn on canvas

Field, bricks, paddle, ball, HUD, particles, scanlines, vignette, Game Over / You Won screens and the restart buttons are all canvas-drawn with pointer hit-testing — the DOM is only cabinet chrome.