diff --git a/static/audio/theme.ogg b/static/audio/theme.ogg new file mode 100644 index 0000000..60d4b41 Binary files /dev/null and b/static/audio/theme.ogg differ diff --git a/static/js/script.js b/static/js/script.js index 5a84a40..93ac5ac 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -13,6 +13,18 @@ document.addEventListener('DOMContentLoaded', () => { let tokensRemaining = 5; let inStreak = false; + // Set up them track + const bgMusic = new Audio("static/audio/theme.ogg"); + bgMusic.loop = true; + bgMusic.volume = 0.15; // adjust to taste + + // Some browsers block autoplay unless user interacts first + document.addEventListener("click", () => { + if (bgMusic.paused) { + bgMusic.play(); + } + }, { once: true }); + // Generate the board for (let i=0; i < 5; i++) { for (let j = 0; j < 5; j++) { @@ -54,6 +66,9 @@ document.addEventListener('DOMContentLoaded', () => { // check for the player grabbing the player icon player_token.addEventListener('pointerdown', (e) => { e.preventDefault(); + if (bgMusic.paused) { + bgMusic.play(); + } player_token.style.zIndex = "9999"; const rect = player_token.getBoundingClientRect(); player_token.style.width = `${rect.width}px`;