Level Discoverystart here Intermediatethe architecture Expertin depth
Batch 2 · Desert
Chapter 2

Make it look good

A game that works is nice. A game that makes you want to play is better! Scenery, landscapes generated by maths, depth, particles and sounds.

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.

src/config/biomes.js — one biome's sheet
{
  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!

Meadow Desert Tundra Volcano

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.

src/sim/terrain.js (the main idea)
// 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
Try it! Generate new landscapes. The “roughness” slider makes the hills smoother or more rugged (like the desert or the volcano!).

Landscape generator

Same random “seed” = same landscape. That's what lets the TV and the phones show exactly the same terrain (chapter 3!).

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.

far (slow) near (fast) →
Several layers, several speeds → a very convincing fake 3D.

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.

For the curious. We don't create each snowflake by hand! We describe rules (speed, lifetime, start and end size) and the engine makes hundreds of particles that follow those rules.

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.

src/systems/Sfx.js (the idea of the “boom”)
// 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
Try it! Turn your device's volume up a little, then click. (The sound effects need a click to start: browsers forbid automatic sound.)

100% code sound effects

No download: these sounds only exist while they play.
Now play it for real! This is batch 2 — the biomes, the modern visuals and the synthesized sound from this chapter — playable right in your browser, two players sharing one screen.
Play batch 2
← Chapter 1 Chapter 3 · Several screens →