Skip to content

Commit

Permalink
Add sounds to rock flinging.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDiBernardo committed Aug 26, 2024
1 parent ccbcb50 commit beb6211
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const numRocks = 1000;
const gridSize = 51200 / 256;

const rockSounds = [];

function preloadAssets() {
const imagesToPreload = ["./assets/img/rock1.png"];

Expand Down Expand Up @@ -35,6 +37,7 @@ function preloadSound(src) {
audio.oncanplaythrough = resolve;
audio.onerror = reject;
audio.src = src;
rockSounds.push(audio);
});
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit beb6211

Please # to comment.