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.
// 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); }
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.
- 🏁 Boot — gets the game ready, the “press to play” screen.
- ⚙️ Setup — we pick the names and the number of rounds.
- 💥 Game — the duel.
- 🏆 Result — who won?
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:
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
Shot simulator
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.
# 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