From 20b7944602626f19a538e976a57d1d344e10f71b Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Tue, 19 Apr 2022 16:51:15 -0600 Subject: Add music/sounds; fix a bug where you could attempt to resume a game when it was won --- src/game.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/game.js') diff --git a/src/game.js b/src/game.js index 4053d84..5a7e391 100644 --- a/src/game.js +++ b/src/game.js @@ -29,6 +29,10 @@ game.toggleRunning = () => { game.startLoop = () => { game.running = true; game.lastTimeStamp = performance.now(); + game.assets.music.play(); + if (game.assets.music.paused) { + alert("Failed to start background music; please allow autoplay in your browser settings."); + } requestAnimationFrame(game.loop); }; @@ -47,6 +51,8 @@ game.loadSystems = () => { }; game.loadLevelIndex = (level) => { + game.win = false; + game.level = level; [game.entities, game.config] = game.loadLevel(game.levels[game.level]); @@ -56,6 +62,11 @@ game.loadLevelIndex = (level) => { }; game.initialize = () => { + game.assets.music.addEventListener('ended', function() { + this.currentTime = 0; + this.play(); + }, false); + game.loadLevelIndex(0); game.startLoop(); }; -- cgit v1.2.3-70-g09d2