summaryrefslogtreecommitdiff
path: root/src/game.js
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-19 16:51:15 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-19 16:51:15 -0600
commit20b7944602626f19a538e976a57d1d344e10f71b (patch)
tree24896f9fcc4d2095a64e0ae58cd513b88f41e282 /src/game.js
parent58ceff79496f60969eecb28a767b1ea28292becb (diff)
downloadbbiy-20b7944602626f19a538e976a57d1d344e10f71b.tar.gz
bbiy-20b7944602626f19a538e976a57d1d344e10f71b.zip
Add music/sounds; fix a bug where you could attempt to resume a game when it was won
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();
};