diff --git a/js/engine.js b/js/engine.js index db98158..a96e953 100644 --- a/js/engine.js +++ b/js/engine.js @@ -283,6 +283,7 @@ function checkMilestones() { G.milestones.push(m.flag); log(m.msg, true); showToast(m.msg, 'milestone', 5000); + if (typeof Sound !== 'undefined') Sound.playMilestone(); // Check phase advancement if (m.at) { @@ -296,6 +297,10 @@ function checkMilestones() { if (pNum > _shownPhaseTransition) { _shownPhaseTransition = pNum; showPhaseTransition(pNum); + if (typeof Sound !== 'undefined') { + Sound.playFanfare(); + Sound.updateAmbientPhase(pNum); + } } } } @@ -356,6 +361,7 @@ function buyBuilding(id) { log(`Built ${def.name} ${label} (total: ${totalBuilt})`); // Particle burst on purchase const btn = document.querySelector('[onclick="buyBuilding(\'' + id + '\')"]'); + if (typeof Sound !== 'undefined') Sound.playBuild(); if (btn) { const rect = btn.getBoundingClientRect(); const cx = rect.left + rect.width / 2; @@ -396,6 +402,7 @@ function buyProject(id) { updateRates(); // Gold particle burst on project completion + if (typeof Sound !== 'undefined') Sound.playProject(); const pBtn = document.querySelector('[onclick="buyProject(\'' + id + '\')"]'); if (pBtn) { const rect = pBtn.getBoundingClientRect(); @@ -437,6 +444,7 @@ function renderDriftEnding() { // Fade-in animation el.classList.add('fade-in'); el.classList.add('active'); + if (typeof Sound !== 'undefined') Sound.playDriftEnding(); // Log the ending text with delays for dramatic effect const lines = [ @@ -479,8 +487,7 @@ function renderBeaconEnding() { `; document.body.appendChild(overlay); - - // Create particle/light ray container + if (typeof Sound !== 'undefined') Sound.playBeaconEnding(); const particleContainer = document.createElement('div'); particleContainer.id = 'beacon-ending-particles'; document.body.appendChild(particleContainer); @@ -762,6 +769,7 @@ function writeCode() { } // Float a number at the click position showClickNumber(amount, comboMult); + if (typeof Sound !== 'undefined') Sound.playClick(); updateRates(); checkMilestones(); render(); diff --git a/js/main.js b/js/main.js index d5a3f17..d00dc43 100644 --- a/js/main.js +++ b/js/main.js @@ -42,6 +42,18 @@ window.addEventListener('load', function () { // Game loop at 10Hz (100ms tick) setInterval(tick, 100); + // Start ambient drone on first interaction + if (typeof Sound !== 'undefined') { + const startAmbientOnce = () => { + Sound.startAmbient(); + Sound.updateAmbientPhase(G.phase); + document.removeEventListener('click', startAmbientOnce); + document.removeEventListener('keydown', startAmbientOnce); + }; + document.addEventListener('click', startAmbientOnce); + document.addEventListener('keydown', startAmbientOnce); + } + // Auto-save every 30 seconds setInterval(saveGame, CONFIG.AUTO_SAVE_INTERVAL); @@ -69,6 +81,7 @@ function toggleMute() { } // Save preference try { localStorage.setItem('the-beacon-muted', _muted ? '1' : '0'); } catch(e) {} + if (typeof Sound !== 'undefined') Sound.onMuteChanged(_muted); } // Restore mute state on load try {