Skip to content

Commit

Permalink
Agitate bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDiBernardo committed Aug 27, 2024
1 parent 51af7a9 commit 15a04b1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const numRocks = 1000;
const gridSize = 51200 / 256;
const bugDanceDuration = 5000;
const bugAgitateDuration = 1000;

// One of these is randomly played whenever a rock is flung.
let rockSounds = [];
Expand Down Expand Up @@ -159,6 +160,17 @@ function happyDance(bug) {
}, bugDanceDuration);
}

function agitateBug(event) {
const bug = event.currentTarget;
bug.classList.add("pulsing");

choose(bugClickSounds).play();

setTimeout(() => {
bug.classList.remove("pulsing");
}, bugAgitateDuration);
}

/**
* Starts the game after DOMContentLoaded.
*/
Expand Down Expand Up @@ -195,6 +207,10 @@ async function startGame() {
const rockImg = rockElement.querySelector("img");
rockImg.src = randomRockImage.src;

// Make the bug agitate when clicked.
const bug = rockContainer.querySelector(".bug");
bug.addEventListener("click", agitateBug);

// Set the src attribute of the img element inside the bug div
const bugImg = rockContainer.querySelector(".bug img");
bugImg.src = randomBugProto.image.src;
Expand Down

0 comments on commit 15a04b1

Please # to comment.