Maker's notebook
How you build…

…a real video game inside a browser

Follow the making of Tower Duel, a two-player cannon duel, step by step. With diagrams, real code, and little games you can play with to understand.

?What is a “web game”?

A web game is a game that runs in a browser (Chrome, Firefox, Safari…) without installing anything. You click a link, and it plays!

For that to work, we put together three ingredients you may already know:

Our game draws everything inside a special area called a canvas (a digital painter's “canvas”). We use a toolbox, Phaser, which handles the tricky parts (displaying, animating, listening to the keyboard) so we can focus on the game.

HTML + CSS the page JavaScript + Phaser <canvas> You 🙂 you play
From code to the screen: JavaScript draws the game inside the canvas, and you play.
Remember. The browser already knows how to display pages. A web game is “just” a very lively page where JavaScript redraws the image dozens of times per second.

★The game we're building

Two towers, one on each side of a landscape. Each player sets the angle and the power of their cannon, taking the wind into account. The twist: both players aim at the same time, then both shots fire together. The first to hit the opposite tower wins the round!

We built the game in 5 steps (we call them “batches”). Each chapter tells one step, with its own biome mood:

↑Choose your level

Every chapter comes in three depths. Read the one that fits — or climb from one to the next as your curiosity grows. (The level switcher sits at the top of each chapter, so you can jump anytime.)

iHow to read this notebook

You'll come across little coloured boxes. Here's what they mean:

Remember — the important idea to keep in mind.
Try it! — a little game right below, to play with using your mouse or finger.
For the curious — a sharper detail, if you want to dig deeper (you can skip it!).

And blocks of real game code, like this one:

a bit of JavaScript
// once both players have confirmed, we fire!
if (tower1.ready && tower2.ready) {
  fire();
}

Start chapter 1 →

📎Annexes

Extras to go further: deploy the game yourself, a detour through the maths, and the behind-the-scenes of the starting brief.

See all the annexes →