From f7901ad59ad38fededbdcb505cbc138dc00ba25f Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Wed, 20 May 2026 11:46:21 -0700 Subject: [PATCH] Shuffle question order on load so each playthrough is different --- game.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/game.js b/game.js index 5455ac7..bcb8284 100644 --- a/game.js +++ b/game.js @@ -119,6 +119,11 @@ const SFX = (() => { if (ctx.state === 'suspended') ctx.resume(); return ctx; } + if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); + if (ctx.state === 'suspended') ctx.resume().then(() => {}); + } + document.addEventListener('touchstart', unlock, { once: true, passive: true }); + document.addEventListener('pointerdown', unlock, { once: true, passive: true }); /* Core: play a tone with envelope */ function tone(freq, type, vol, attack, sustain, release, when) { @@ -182,7 +187,8 @@ const SFX = (() => { /* Select / menu move */ select() { - tone(440, 'square', 0.12, 0.005, 0.03, 0.04); + const c = getCtx(); + tone(440, 'square', 0.12, 0.005, 0.03, 0.04, c.currentTime + 0.05); }, /* Correct answer — happy ascending chord */ @@ -945,7 +951,15 @@ class Game { if (this.state.questions.length>0) { cb(); return; } fetch('./questions.json') .then(r=>r.json()) - .then(data=>{ this.state.questions=data.levels[0].questions; cb(); }) + .then(data=>{ + const qs = data.levels[0].questions; + for (let i = qs.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [qs[i], qs[j]] = [qs[j], qs[i]]; + } + this.state.questions = qs; + cb(); + }) .catch(()=>this.toast('❌ Could not load questions.json')); }