Skip to content

Commit

Permalink
Pac-Man Sound Effects + Sound On/Off
Browse files Browse the repository at this point in the history
  • Loading branch information
luciopanepinto committed Jul 6, 2015
1 parent 48b8da8 commit 57edb26
Show file tree
Hide file tree
Showing 30 changed files with 982 additions and 8 deletions.
29 changes: 24 additions & 5 deletions css/pacman.css
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ h3 {
font-style: normal;
}

.sound {
position: absolute;
}
.sound img {
height: 28px;
}
#home .sound {
bottom: 0px;
right: 5px;
}
#panel .sound {
top: 77px;
right: 5px;
}

.github {
position: absolute;
bottom: 0px;
Expand All @@ -216,8 +231,8 @@ h3 {
.help-button {
position: absolute;
text-align: center;
bottom: 0px;
right: 5px;
bottom: 8px;
right: 55px;
margin: auto;
font-size: 14px;
font-weight: bold;
Expand Down Expand Up @@ -272,6 +287,10 @@ h3 {
text-align: left;
}

#sound {
position: absolute;
}

.ui-mobile {
-webkit-touch-callout: none;
-webkit-user-select: none;
Expand All @@ -290,7 +309,7 @@ h3 {
}

@media screen and (max-width:1024px), screen and (min-device-width : 768px) and (max-device-width : 1024px) {
#home .help-button, #panel .help-button, #home .github {
#home .help-button, #panel .help-button, #home .github, #sound, .sound {
display: none;
}
#panel, #home {
Expand All @@ -308,7 +327,7 @@ h3 {
#control {
display: inline;
}
#home .help-button, #panel .help-button, #home .github {
#home .help-button, #panel .help-button, #home .github, #sound, .sound {
display: none;
}
h1, #canvas-panel-title-pacman {
Expand All @@ -322,7 +341,7 @@ h3 {
#control {
display: inline;
}
h1, #canvas-panel-title-pacman, #control-up-second, #control-down-second, #home .help-button, #panel .help-button, #home .github {
h1, #canvas-panel-title-pacman, #control-up-second, #control-down-second, #home .help-button, #panel .help-button, #home .github, #sound, .sound {
display: none;
}
#score, #highscore {
Expand Down
Binary file added img/sound-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/sound-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-mobile.js"></script>
<script type="text/javascript" src="js/jquery-buzz.js"></script>

<script type="text/javascript" src="js/game.js"></script>
<script type="text/javascript" src="js/tools.js"></script>
Expand All @@ -28,6 +29,7 @@
<script type="text/javascript" src="js/pacman.js"></script>
<script type="text/javascript" src="js/ghosts.js"></script>
<script type="text/javascript" src="js/home.js"></script>
<script type="text/javascript" src="js/sound.js"></script>

<script type="text/javascript">

Expand All @@ -44,9 +46,25 @@

$(document).ready(function() {
$.mobile.loading().hide();
loadAllSound();

HELP_TIMER = setInterval('blinkHelp()', HELP_DELAY);

$(".sound").click(function(e) {
e.stopPropagation();

var sound = $(this).attr("data-sound");
if ( sound === "on" ) {
$(".sound").attr("data-sound", "off");
$(".sound").find("img").attr("src", "img/sound-off.png");
GROUP_SOUND.mute();
} else {
$(".sound").attr("data-sound", "on");
$(".sound").find("img").attr("src", "img/sound-on.png");
GROUP_SOUND.unmute();
}
});

$(".help-button, #help").click(function(e) {
e.stopPropagation();
if (!PACMAN_DEAD && !LOCK && !GAMEOVER) {
Expand Down Expand Up @@ -156,6 +174,8 @@

<body>

<div id="sound"></div>

<div id="help">
<h2>Help</h2>
<table align="center" border="0" cellPadding="2" cellSpacing="0">
Expand Down Expand Up @@ -183,6 +203,7 @@ <h3>Lucio PANEPINTO<br><em>2015</em></h3>
</div>
<canvas id="trailer"></canvas>
<div class="help-button">- help -</div>
<a class="sound" href="javascript:void(0);" data-sound="on"><img src="img/sound-on.png" alt="" border="0"></a>
<a class="github" target="_blank" href="https://github.com/luciopanepinto/pacman"><img src="img/github.png" alt="GitHub - Lucio PANEPINTO - Pac-Man"></a>
</div>

Expand Down Expand Up @@ -214,6 +235,7 @@ <h1>pac-man</h1>
<canvas id="canvas-level-fruits"></canvas>
<div id="message"></div>
<div class="help-button">- help -</div>
<a class="sound" href="javascript:void(0);" data-sound="on"><img src="img/sound-on.png" alt="" border="0"></a>
</div>

</body>
Expand Down
2 changes: 2 additions & 0 deletions js/fruits.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ function getLevelFruitsCanevasContext() {
}

function eatFruit() {
playEatFruitSound();

var s = 0;
if (FRUIT === "cherry") s = 100;
else if (FRUIT === "strawberry") s = 300;
Expand Down
14 changes: 13 additions & 1 deletion js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ function initGame(newgame) {
}

function win() {
stopAllSound();

LOCK = true;
stopPacman();
stopGhosts();
Expand Down Expand Up @@ -168,9 +170,12 @@ function ready() {
LOCK = true;
message("ready!");

setTimeout("go()", "2000");
playReadySound();
setTimeout("go()", "4100");
}
function go() {
playSirenSound();

LOCK = false;

startTimes();
Expand Down Expand Up @@ -219,7 +224,9 @@ function stopTimes() {
}

function pauseGame() {

if (!PAUSE) {
stopAllSound();
PAUSE = true;

message("pause");
Expand All @@ -232,6 +239,8 @@ function pauseGame() {
}
function resumeGame() {
if (PAUSE) {
testStateGhosts();

PAUSE = false;

clearMessage();
Expand All @@ -245,6 +254,9 @@ function resumeGame() {

function lifes(l) {
if (l) {
if ( l > 0 ) {
playExtraLifeSound();
}
LIFES += l;
}

Expand Down
27 changes: 27 additions & 0 deletions js/ghosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ function drawGhost(ghost) {
}

function affraidGhosts() {

playWazaSound();

SCORE_GHOST_COMBO = 200;

affraidGhost("blinky");
Expand Down Expand Up @@ -181,10 +184,31 @@ function cancelAffraidGhost(ghost) {
stopGhost(ghost);
eval('GHOST_' + ghost.toUpperCase() + '_STATE = 0');
moveGhost(ghost);
testStateGhosts();
}
}
function testStateGhosts() {

if ( GHOST_BLINKY_STATE === 1 ||
GHOST_PINKY_STATE === 1 ||
GHOST_INKY_STATE === 1 ||
GHOST_CLYDE_STATE === 1
) {
playWazaSound();
} else if ( GHOST_BLINKY_STATE === -1 ||
GHOST_PINKY_STATE === -1 ||
GHOST_INKY_STATE === -1 ||
GHOST_CLYDE_STATE === -1
) {
playGhostEatenSound();
} else {
playSirenSound();
}
}

function startEatGhost(ghost) {
playEatGhostSound();

LOCK = true;

if ( eval('GHOST_' + ghost.toUpperCase() + '_AFFRAID_TIMER !== null') ) {
Expand All @@ -202,6 +226,8 @@ function startEatGhost(ghost) {

function eatGhost(ghost) {

playGhostEatenSound();

if (eval('GHOST_' + ghost.toUpperCase() + '_STATE === 1')) {
$("#board span.combo").remove();
eval('GHOST_' + ghost.toUpperCase() + '_STATE = -1');
Expand All @@ -218,6 +244,7 @@ function cancelEatGhost(ghost) {
stopGhost(ghost);
eval('GHOST_' + ghost.toUpperCase() + '_STATE = 0');
moveGhost(ghost);
testStateGhosts();
}
}

Expand Down
Loading

0 comments on commit 57edb26

Please sign in to comment.