1Textures generated at runtime
There are no PNGs. Every particle sprite is drawn once into an off-screen texture at boot, then reused, tinted and blended for the rest of the session.
g = make(); for (let r = 16; r > 0; r -= 2) { g.fillStyle(0xffffff, 0.06); // faint, additive translucent rings g.fillCircle(16, 16, r); // β a soft gradient, no image } g.generateTexture('smoke', 32, 32);
Four sprites cover the whole game: a hard spark dot, a soft smoke puff, a bright additive flash, and a blobby cloud. White by default, recoloured per biome at runtime.
2Sound: oscillators & envelopes
Every sound effect is a tiny Web Audio graph: a source (an oscillator or a buffer of noise), a filter, and a gain envelope that shapes the volume over time. An explosion is filtered noise whose low-pass sweeps down while the gain decays.
const src = this.noise(0.55); // white noise (random buffer) lp.frequency.setValueAtTime(1200, now); lp.frequency.exponentialRampToValueAtTime(120, now + 0.5); // darkens gain.gain.exponentialRampToValueAtTime(0.001, now + 0.55); // decays
Richer effects just stack graphs: the tower rubble() layers a low rumble, a deep sine thud, and a scatter of short high-passed βdebrisβ bursts at random times. The continuous flyby() whizz keeps one band-passed sawtooth alive and nudges its gain and pitch toward a target with setTargetAtTime as a shell nears. On iOS, where the Vibration API is blocked, this audio whizz stands in for the haptics you'd otherwise feel.
AudioContext suspended and only resume it after a user gesture. A single shared Sfx instance lives on the game registry and is unlock()-ed on first interaction β otherwise the opening sounds vanish silently.3Colour maths: lerp, shade, barrelColor
Colours are computed, not stored. Linear interpolation (lerp) between two RGB triples drives the charging barrel (steel β glowing red), and a multiplicative shade brightens or darkens any colour. All of it lives in the renderer-agnostic src/render/visuals.js.
export function shade(color, factor) { const r = clamp(Math.round(((color >> 16) & 0xff) * factor), 0, 255); const g = clamp(Math.round(((color >> 8) & 0xff) * factor), 0, 255); const b = clamp(Math.round(( color & 0xff) * factor), 0, 255); return (r << 16) | (g << 8) | b; // repacks the integer }
barrelColor(power) lerps from cool steel toward burning red on a power ratio clamped to [0, 1]; craterRimColor(edge) pulls the biome's edge tint toward dark brown for a βscorched earthβ rim rather than a black ring. The bit-shifts (>> 16, & 0xff) extract each channel from a 0xRRGGBB integer.
0xRRGGBB). Bit-shifting splits the channels, the maths runs per channel, and the shift-OR repacks them β the same representation Phaser and a plain canvas both accept, which is why this code is shared.4Animated geometry: the windsock
The windsock isn't a sprite β it's geometry generated every frame. From the base point, the wind strength and the time, computeWindsock returns a pole plus tapering striped quads that point downwind, lift with strength, and flutter with a time-driven sine.
const length = 16 + 50 * k; // 0..1 strength const droop = lerp(1.2, 0.14, k); // flatter when windy const flutter = Math.sin(time * 0.006 + f * 6.2) * 7 * k * f; // tip waves most
Because it returns plain points and colours, the TV draws it with Phaser graphics and the controller draws the same shape on a 2D canvas β one definition, two renderers.
5Particle systems & blend modes
Ambient scenery is a single emitter configured by data. Each biome picks a behaviour β drifting leaves, falling snow, rising embers, blowing sand β and embers add an ADD blend mode so they glow. The live wind even bends the stream by setting the emitter's gravity.
config = {
y: GAME_HEIGHT + 10, // born at the bottom
speedY: { min: -110, max: -45 }, // upward
scale: { start: 0.7, end: 0 }, // shrink as they die
blendMode: 'ADD', // additive: bright embers glow over the dark sky
};
All this synthesis can overwhelm a smart TV. So at boot the host samples real frame deltas for a short window, computes the average fps, and records a tier the renderer respects (fewer clouds, no ambient layer on lite).
// the ambient layer is the easiest to sacrifice on a weak device if (quality !== 'lite') this.spawnAmbient();