1Scenery that changes: the biomes
Rather than drawing each scene by hand, we describe each “biome” with a small colour sheet. The game reads the sheet and paints everything on its own.
{
id: 'volcano',
sky: [0x2a1430, 0x6e2535], // dark gradient
terrain: { fill: 0x3a2f3a, edge: 0xff6b35 },
ambient: 'embers' // embers drifting up
}
Four biomes: Meadow 🌳, Desert 🏜️, Tundra ❄️, Volcano 🌋. Same game, totally different mood: it's exactly what this notebook does, changing its outfit each chapter!
2A landscape made by maths
The terrain isn't drawn: it's computed. We add up several waves (sine curves, like the waves of the sea) of different sizes. The result: hills that look natural, and always different.
// ground height at horizontal position x = sum of 3 waves height = base - big_wave(x) // the large hills - mid_wave(x) // the bumps - small_wave(x); // the details
Landscape generator
3Depth: parallax
To give a sense of depth, we stack layers that move at different speeds: the far clouds drift slowly, the foreground faster. Your brain understands “ah, that's far / that's near”. It's called parallax.
4Living particles
A particle is a tiny dot that is born, moves, changes size/transparency, then dies. On their own they're nothing; by the hundreds, they make the smoke, the sparks, the snow, the embers, the dust.
- 💥 on firing: a muzzle flash + sparks;
- 🌫️ on impact: dust that falls back down;
- 🍃 in the background: leaves, sand, snow or embers depending on the biome, pushed by the wind.
5Sound… without any audio file
Surprising: the game contains no sound file at all. Every sound effect is made on the fly by code, with Web Audio. An explosion? Some “noise” (like the static of an old TV) that we filter and fade out very fast.
// noise + a filter + a volume that drops = explosion const noise = makeNoise(); filter.frequency.rampTo(120); // gets deep volume.gain.rampTo(0, 0.5); // fades out in 0.5 s