Skip to content

Commit

Permalink
Added some sounds in the game RishabhDevbanshi#88
Browse files Browse the repository at this point in the history
  • Loading branch information
drj-sharma committed Oct 3, 2020
1 parent 8c2bf57 commit 9f033bf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
29 changes: 27 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@ document.addEventListener("DOMContentLoaded", () => {
}
}
createBoard();

//create Characters
//draw pacman onto the board
let pacmanCurrentIndex = 490;
Expand All @@ -835,6 +834,28 @@ document.addEventListener("DOMContentLoaded", () => {
// console.log(getCoordinates(pacmanCurrentIndex))

// set pacman velocity
function playReady() {
const readySound = document.getElementById("readySound");
readySound.play();
}
function removeSound() {
const readySound = document.getElementById("readySound");
readySound.pause();
readySound.currentTime = 0;
}
function pacmanDied() {
const dieSound = document.getElementById("pacmanDied");
dieSound.play();
}
function sirenSound() {
const siren = document.getElementById("siren");
siren.play();
}
function removeSirenSound() {
const siren = document.getElementById("siren");
siren.pause();
siren.currentTime = 0;
}
function setPacmanVelocity(e) {
switch (e.keyCode) {
case 37:
Expand Down Expand Up @@ -1050,6 +1071,8 @@ document.addEventListener("DOMContentLoaded", () => {
!squares[pacmanCurrentIndex].classList.contains("scared-ghost")
) {
ghosts.forEach((ghost) => clearInterval(ghost.timerId));
removeSirenSound();
pacmanDied();
document.removeEventListener("keyup", movePacman);
pacmanVelocity.x = 0;
pacmanVelocity.y = 0;
Expand All @@ -1075,10 +1098,12 @@ document.addEventListener("DOMContentLoaded", () => {
}, 3000);
}
}

playReady();
//start the game when enter is pressed
function startGame(event) {
if (event.keyCode === 13) {
removeSound();
sirenSound();
document.removeEventListener("keydown", startGame);
//remove start screen
document.getElementById("start-screen").style.display = "none";
Expand Down
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ <h2>Score:<span id="score">0</span></h2>
<div class="overlay-screen" id="you-won-screen">
<span>YOU WON!</span>
</div>
<!-- Sounds -->
<audio id="readySound" src="./sounds/pacman_beginning.wav" type="audio/wav" loop="infinite"></audio>
<audio id="pacmanDied" src="./sounds/pacman_death.wav" type="audio/wav"></audio>
<audio id="siren" src="./sounds/siren.wav" type="audio/wav" loop="infinity"></audio>
</body>
</html>
Binary file added sounds/pacman_beginning.wav
Binary file not shown.
Binary file added sounds/pacman_chomp.wav
Binary file not shown.
Binary file added sounds/pacman_death.wav
Binary file not shown.
Binary file added sounds/siren.wav
Binary file not shown.

0 comments on commit 9f033bf

Please sign in to comment.