summaryrefslogtreecommitdiff
path: root/src/game.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.js')
-rw-r--r--src/game.js11
1 files changed, 11 insertions, 0 deletions
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();
};