Different sound effect when punching Ryan.
This commit is contained in:
parent
f12f0fc4bb
commit
730c7e3e52
1
dist/index.html
vendored
1
dist/index.html
vendored
@ -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
12
dist/script.js
vendored
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user