gitflarePublicPartly agent-ready40
orbit-duel
Real-time two-player orbital combat game on Cloudflare Workers and Durable Objects.
- LicenseApache-2.0
- LanguageJavaScript
- Last landed
0413e56Oct 23, 2026
Add the Apache-2.0 licence
0413e56export function createAudio() { let ac = null, master = null, noiseBuf = null, thrustGain = null, thrustOn = false, muted = false, level = 1; function tone(type, f0, f1, dur, vol) { if (!ac) return; const t = ac.currentTime, o = ac.createOscillator(), g = ac.createGain(); o.type = type; o.frequency.setValueAtTime(f0, t); o.frequency.exponentialRampToValueAtTime(Math.max(1, f1), t + dur); g.gain.setValueAtTime(vol, t); g.gain.exponentialRampToValueAtTime(0.001, t + dur); o.connect(g); g.connect(master); o.start(t); o.stop(t + dur + 0.02); } function noise(dur, vol, freq) { if (!ac) return; const t = ac.currentTime, s = ac.createBufferSource(), f = ac.createBiquadFilter(), g = ac.createGain(); s.buffer = noiseBuf; f.type = 'lowpass'; f.frequency.value = freq; g.gain.setValueAtTime(vol, t); g.gain.exponentialRampToValueAtTime(0.001, t + dur); s.connect(f); f.connect(g); g.connect(master); s.start(t); s.stop(t + dur); } const sfx = { fire: () => tone('square', 800 * (0.92 + Math.random() * 0.16), 220, 0.12, 0.12), hit: () => { tone('sawtooth', 300, 80, 0.15, 0.2); noise(0.1, 0.2, 2000); }, explode: () => { noise(1.1, 0.8, 350); tone('sine', 70, 20, 1.0, 0.7); }, pickup: () => { tone('triangle', 600, 1200, 0.15, 0.2); }, power: () => { tone('triangle', 400, 1600, 0.3, 0.25); }, respawn: () => { tone('sine', 200, 1400, 0.4, 0.2); noise(0.3, 0.08, 3000); }, countdown: () => tone('sine', 660, 660, 0.15, 0.25), win: () => { tone('triangle', 523, 523, 0.2, 0.25); setTimeout(() => tone('triangle', 784, 784, 0.4, 0.25), 180); }, }; return { unlock() { if (ac) { if (ac.state === 'suspended') ac.resume(); return; } const C = globalThis.AudioContext || globalThis.webkitAudioContext; if (!C) return; ac = new C(); master = ac.createGain(); master.gain.value = muted ? 0 : 0.5; const comp = ac.createDynamicsCompressor(); master.connect(comp); comp.connect(ac.destination); noiseBuf = ac.createBuffer(1, ac.sampleRate, ac.sampleRate); const d = noiseBuf.getChannelData(0); for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1; const s = ac.createBufferSource(), f = ac.createBiquadFilter(); s.buffer = noiseBuf; s.loop = true; f.type = 'lowpass'; f.frequency.value = 220; thrustGain = ac.createGain(); thrustGain.gain.value = thrustOn ? 0.15 : 0; s.connect(f); f.connect(thrustGain); thrustGain.connect(master); s.start(); }, play(name) { const f = sfx[name]; if (f && ac) f(); }, setMuted(m) { muted = !!m; if (master) master.gain.value = muted ? 0 : 0.5; }, isMuted() { return muted; }, thrust(on, throttle) { if (throttle !== undefined) level = throttle; if (on === thrustOn && throttle === undefined) return; thrustOn = on; if (thrustGain) thrustGain.gain.setTargetAtTime(on ? 0.15 * level : 0, ac.currentTime, 0.05); }, };}