Level Discoverystart here Intermediatethe architecture Expertin depth
Batch 1 · Meadow
Chapter 1

Make a cannon move

We lay the foundations: how an image “comes to life”, how a cannonball follows a curve, and how we wrap it all up to share it.

1The game loop: 60 frames per second

A game is like a cartoon: a sequence of still images shown very fast. On screen, it gives the illusion of movement.

About 60 times per second, the browser calls a function we name update. On each call, we move the objects a little, then redraw. That's the game loop.

1 · Listen 2 · Compute 3 · Draw …1/60 s later
Listen to the keyboard → compute the movements → draw. And we start over, 60×/second.
src/scenes/GameScene.js (simplified)
// delta = time elapsed since the last frame (in milliseconds)
update(time, delta) {
  const dt = delta / 1000;        // convert it to seconds
  if (this.state === 'aiming')  this.handleAiming(dt);
  if (this.state === 'firing')  this.handleFiring(dt);
}
Why dt? Not all computers run at the same speed. By multiplying the movements by the elapsed time, the game runs at the same speed everywhere. Clever!

2“Scenes” like in a theatre

We split the game into scenes, a bit like the rooms of a house: the title screen, the settings screen, the match itself. We move from one to another.

Phaser handles this on its own: we give it the list, and we say “go to the Game scene”.

3The path of a cannonball

When the cannon fires, the ball goes in a straight line… then gravity pulls it down, and the wind pushes it sideways. The result is a nice curve: a parabola.

We store two numbers for the ball: its horizontal speed vx and its vertical speed vy. On each frame, we update them:

src/sim/Simulation.js (the heart of the physics)
ball.vx += wind   * dt;   // the wind pushes sideways
ball.vy += 520    * dt;   // gravity pulls downward
ball.x  += ball.vx * dt;   // move horizontally
ball.y  += ball.vy * dt;   // …and vertically
For the curious. Really, it's the same formula as in physics class (acceleration). You don't need to know it to play: the computer just adds up tiny steps, many times per second. Lots of tiny steps ≈ a beautiful curve.
Try it! Set the angle, the power and the wind, then fire. Can you manage to hit the red target on the right?

Shot simulator

Negative wind = to the left, positive = to the right. The target moves on every hit!

4Docker: the box to go

My game works on my computer… but will it work on yours? Often, a program needs specific tools (this version of that software). If they're missing, it crashes.

Docker fixes that: we put the game and all its tools into a “box” (a container). This box works the same everywhere: on your PC, on a server, in the cloud. A bit like a shipping container: whatever the ship, the box is always the same.

Step 1 · build the code → game files 📦 the container game + server all-in-one your PC a server the cloud ☁️
We build once, we get a box, and it runs identically everywhere.
Dockerfile (the key excerpt)
# 1) build the game with Node
FROM node:24 AS build
RUN npm run build      # produces the final files

# 2) serve them with a small web server
FROM nginx
COPY --from=build /app/dist /usr/share/nginx/html
Remember. Batch 1 = a game that runs, inside a Docker box ready to be shared. Not pretty yet: that's the job of chapter 2!
Now play it for real! This is the complete batch 1 — the little game this chapter just walked through — playable right in your browser, two players sharing one screen.
Play batch 1
← Home Chapter 2 · Make it look good →