1The terrain is a heightfield, not an image
The destructible ground isn't a big bitmap. It's a heightfield: one surface height per column, plus a growing list of craters. Cheap to store, cheap to send, and easy to keep identical everywhere.
export function generateHeights(seed, roughness = 1) { const r = rng(seed); // seeded generator const heights = new Float32Array(width); // sum of sine waves → natural relief }
Destruction doesn't rewrite that array. Instead, we keep a list of craters alongside it. The terrain's final shape is “the heightfield minus the craters” — a subtraction computed on demand, never materialised.
2Solidity by squared distance
A point is solid when it sits below the surface and inside no crater. Testing “inside a crater?” is a circle test — and we do it without a square root by comparing the squared distance to the squared radius.
export function inCrater(craters, x, y) { for (const c of craters) { const dx = x - c.x, dy = y - c.y; if (dx * dx + dy * dy <= c.r * c.r) return true; } return false; }
That tiny rule is enough to produce caves and overhangs: a crater dug under a bump leaves the matter above it floating, because that matter is still below the surface and inside no crater.
dx²+dy² with c.r² is the trick from the maths annex: the square root is monotonic, so for a yes/no test the squares answer the same question — without the expensive root.3Determinism: send the seed, not the terrain
The terrain is a pure function of a seed. The server rolls one number, generates the heights, and ships only that seed in the snapshot. Each client regenerates the identical surface — so the ground the server resolves collisions against is the very ground the TV draws.
snapshot() { return { seed: this.seed, // regenerate the heightfield from this craters: this.craters, // just the carved circles // …phase, wind, scores, towers, live projectiles }; }
And the craters? Just a short list of { x, y, r } circles. So the entire destructible state on the wire is one seed + a handful of crater circles — not a heightfield, never a bitmap.
if (p.y > 0 && pointSolid(this.heights, this.craters, p.x, p.y)) { this.craters.push({ x: Math.round(p.x), y: Math.round(p.y), r }); }
4A taste of turbo: continuous wind
Classic mode rolls a fresh wind each turn. Turbo mode keeps the wind flowing: it eases between random keypoints every 10 seconds with a smoothstep curve, and layers a light gust wave on top so the breeze breathes.
const t = this.windClock / WIND_KEY_SECONDS; const s = t * t * (3 - 2 * t); // smoothstep easing const base = this.windFrom + (this.windTo - this.windFrom) * s;
On top, a light gust wave (two sines) rides over the base, its amplitude set by a per-match trait (gustiness). The result: a wind that drifts gently between keypoints but breathes instead of gliding mechanically. The expert level details the full formula.