1Cycling without cutting a gust
In random play, each character plays for a while, then another takes over. Since wind is a continuous loop, we avoid cutting it mid-swell: once the duration elapses, we wait for a lull (a dip in level) before switching, with a crossfade of about 1.4 s. A 2.5 s cap guarantees it always eventually changes.
// has the duration elapsed? if (!swapPending) { if (now >= cycleAt) { swapPending = true; pendingSince = now; } } else if (rms() < 0.05 || now - pendingSince > 2.5) { swap(pickOther(), 1.4); // gentle crossfade to another character cycleAt = now + 8 + Math.random() * 5; }
The result: you never hear a gust cut off abruptly โ the transition slips into the wind's relative quiet.
2Per-biome soundtrack โ proposals & round transition
Each biome has its own sonic climate, offered in several proposals. During a match, a biome's two ambiences alternate from round to round; the final round has its own music. When the scene slides to the next hill, the music follows: a crossfade of the volumes and a tempo glide (BPM) along the same smoothstep curve, so both tracks stay in sync through the transition.
The catalog keeps every proposal โ including the five Desert ones. The mixer plays the playlist chosen per biome (Desert: Mirage and Fournaise in rotation, Simoun for the finale). Pick a biome, then run through the rounds.
โ And that wraps up the notebook!
From the game loop to synthesized sound, you've made the full tour of Tower Duel.
Five batches, three reading levels, a handful of simulators: you now know how a small web game comes to life, screen after screen, gust after gust. Thanks for reading all the way through.