World sounds are heard in a radius around the bot, not the view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 23:40:08 -04:00
co-authored by Claude Opus 5.5
parent daf91891fc
commit c50444b333
5 changed files with 36 additions and 18 deletions
+5 -3
View File
@@ -118,10 +118,12 @@ const SFX = {
sale() { if (!AU.ctx) return; const t = AU.ctx.currentTime; [784, 988, 1175, 1568].forEach((f, k) => tone(f, 0.09, { wave: 'p25', vol: 0.05, at: t + k * 0.06 })); },
discover() { if (!rateOk('disc', 500)) return; const t = AU.ctx && AU.ctx.currentTime; tone(880, 0.06, { wave: 'p25', vol: 0.04, at: t }); tone(1175, 0.1, { wave: 'p25', vol: 0.04, at: t + 0.06 }); },
};
// World sounds are heard around the bot, whatever the zoom: full within 24 grains, silent at 96
const SFX_NEAR = 24, SFX_FAR = 96;
function sfxPlace(x, y) {
if (typeof R === 'undefined' || !R.bw) return { gain: 1, pan: 0 };
const dx = Math.max(R.vx0 - x, 0, x - R.vx0 - R.bw), dy = Math.max(R.vy0 - y, 0, y - R.vy0 - R.bh);
return { gain: Math.max(0, 1 - Math.hypot(dx, dy) / R.bw), pan: Math.max(-1, Math.min(1, (x - R.vx0 - R.bw / 2) / (R.bw / 2))) * 0.6 };
if (typeof bot === 'undefined' || !bot.w) return { gain: 1, pan: 0 };
const dx = x - (bot.x + bot.w / 2), dy = y - (bot.y + bot.h / 2), d = Math.hypot(dx, dy);
return { gain: Math.max(0, Math.min(1, (SFX_FAR - d) / (SFX_FAR - SFX_NEAR))), pan: Math.max(-1, Math.min(1, dx / SFX_FAR)) * 0.6 };
}
function playSfx(name, arg, x, y) {
if (!AU.ctx || !SFX[name]) return;