From beb6211e76dae7e610707f058be904d2fff53de4 Mon Sep 17 00:00:00 2001 From: Michael DiBernardo Date: Mon, 26 Aug 2024 14:35:42 -0400 Subject: [PATCH] Add sounds to rock flinging. --- main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.js b/main.js index 5adbd82..7162ad1 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,8 @@ const numRocks = 1000; const gridSize = 51200 / 256; +const rockSounds = []; + function preloadAssets() { const imagesToPreload = ["./assets/img/rock1.png"]; @@ -35,6 +37,7 @@ function preloadSound(src) { audio.oncanplaythrough = resolve; audio.onerror = reject; audio.src = src; + rockSounds.push(audio); }); } @@ -92,6 +95,8 @@ document.addEventListener("DOMContentLoaded", () => { rock.style.opacity = "0"; rock.style.transition = `all ${duration}ms cubic-bezier(0.25, 0.1, 0.25, 1)`; + rockSounds[Math.floor(Math.random() * rockSounds.length)].play(); + setTimeout(() => { rock.remove(); }, duration);