Different sound effect when punching Ryan.

This commit is contained in:
Ritchie Cunningham 2025-08-23 14:16:06 +01:00
parent f12f0fc4bb
commit 730c7e3e52
2 changed files with 10 additions and 3 deletions

1
dist/index.html vendored
View File

@ -13,6 +13,7 @@
<div id="hand">👋🏿</div>
<div id="fist">✊🏾</div>
<audio id="slap-sound" src="slap.mp3" preload="auto"></audio>
<audio id="punch-sound" src="punch.mp3" preload="auto"></audio>
<script src="script.js"></script>
</body>
</html>

12
dist/script.js vendored
View File

@ -2,6 +2,7 @@ const slapImage = document.getElementById('slap-image');
const hand = document.getElementById('hand');
const fist = document.getElementById('fist');
const slapSound = document.getElementById('slap-sound');
const punchSound = document.getElementById('punch-sound');
const initialHandRight = 20;
const initialFistRight = 20;
@ -19,8 +20,13 @@ function doAction(emoji, x, y) {
emoji.style.left = `${x - emoji.offsetWidth / 2}px`;
emoji.style.top = `${y - emoji.offsetHeight / 2}px`;
slapSound.currentTime = 0;
slapSound.play();
if (emoji === hand) {
slapSound.currentTime = 0;
slapSound.play();
} else {
punchSound.currentTime = 0;
punchSound.play();
}
/* Move the emoji back to a ready position. */
setTimeout(() => {
@ -85,4 +91,4 @@ slapImage.addEventListener('touchend', (event) => {
slapImage.addEventListener('touchmove', (event) => {
/* Cancel the long press if the user moves their finger. */
clearTimeout(pressTimer);
});
});