Brick breaker in JavaScript canvas
A paddle-and-ball brick breaking game in the browser with levels, power-ups and mobile touch controls.
Beginner⏱ 6–10 hours🪜 7 stepsJavaScriptHTML Canvas
What you'll learn
- ◆requestAnimationFrame and delta time
- ◆Circle–rectangle collision
- ◆Simple particle effects
What you'll build
- ✓Paddle with mouse, keyboard or touch
- ✓Ball bounces with angle based on hit position
- ✓Levels from a layout array
- ✓Power-ups: wider paddle, multi-ball
Step-by-step guide
- 1
Canvas loop
requestAnimationFrame(loop); compute dt from timestamps so speed is the same on every screen.
- 2
Paddle and ball
Paddle follows input; ball has x, y, vx, vy; bounce off walls.
- 3
Paddle angle
Where the ball hits the paddle changes the bounce angle; this makes the game feel skilful.
- 4
Bricks
Levels as arrays of strings ("1110111"); build brick rectangles from them.
- 5
Collision
Find the closest point on the rectangle to the ball centre; if distance < radius, bounce on the correct axis.
- 6
Power-ups
Bricks sometimes drop a capsule; catching it applies an effect for 10 seconds.
- 7
Mobile
Touch events move the paddle; scale the canvas for high-DPI screens.
🚀 Make it stand out
- +Level editor
- +Sound with the Web Audio API
- +Online leaderboard