Learn how to build 2D HTML5 Breakout game in pure JavaScript

In this step-by-step tutorial we create a simple MDN Breakout game written entirely in pure JavaScript and rendered on HTML5 Canvas. Every step has editable, live samples available to play with so you can see what the intermediate stages should look like. You will learn the basics of using the Canvas element to implement fundamental game mechanics like rendering and moving images, collision detection, control machanisms, and winning and losing states.

MDN Breakout gameplay

To get the most out of this series of articles you should already have basic to intermediate JavaScript knowledge. After working through this tutorial you should be able to build your own simple Web games.

2D breakout game using pure JavaScript

  1. Create the Canvas and draw on it - example #1
  2. Move the ball - example #2
  3. Bounce off the walls - example #3
  4. Paddle and keyboard controls - example #4
  5. Game over - example #5
  6. Build the brick field - example #6
  7. Collision detection - example #7
  8. Track the score and win - example #8
  9. Mouse controls - example #9
  10. Finishing up - example #10

Starting with pure JavaScript is the best way to get a solid knowledge of web game development. After that, you can pick any framework you like and use it for your projects. Frameworks are just tools built with the JavaScript language; so even if you plan on working with them, it's good to learn about the language itself first to know what exactly is going on under the hood. Frameworks speed up development time and help take care of boring parts of the game, but if something is not working as expected, you can always try to debug that or just write your own solutions in pure JavaScript.

You can visit the GitHub repository of this tutorial to get the source code of all the lessons.