Skip to content

Commit

Permalink
pacman 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luciopanepinto committed Oct 26, 2016
1 parent 4dff042 commit 38494fc
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 89 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Firebase files
.firebaserc
firebase.json

# Google files
googlebffbfc06c66171db.html
manifest.json

# Windows image file caches
Thumbs.db
ehthumbs.db
Expand Down
Binary file added icon_128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<head>

<meta property="og:image" content="https://87060b9f4949ec52ecb6a75e0388be0b4d345dad.googledrive.com/host/0B4HFlS9vdbwFQlJvRFU2NDVYMlk/img/preview.png">
<meta property="og:url" content="https://87060b9f4949ec52ecb6a75e0388be0b4d345dad.googledrive.com/host/0B4HFlS9vdbwFQlJvRFU2NDVYMlk/">
<meta property="og:image" content="https://pacman-e281c.firebaseapp.com/img/preview.png">
<meta property="og:url" content="https://pacman-e281c.firebaseapp.com/">
<meta property="og:description" content="Pac-Man game written in HTML5 + CSS3 + jQuery with Canvas. This WebApp is a Responsive Web Design (RWD) website.">
<meta property="og:title" content="Lucio PANEPINTO - Pac-Man">

Expand All @@ -17,7 +17,7 @@
<link rel="stylesheet" type="text/css" href="css/pacman-home.css" />

<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-mobile.js"></script>-->
<script type="text/javascript" src="js/jquery-buzz.js"></script>

<script type="text/javascript" src="js/game.js"></script>
Expand Down Expand Up @@ -45,11 +45,13 @@
}

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

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

initHome();

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

Expand Down Expand Up @@ -85,11 +87,11 @@
e.stopPropagation();
});

initHome();

$("#home").on("mousedown touchstart", function(e) {
e.preventDefault();
simulateKeydown(13);
$("#home").on("click touchstart", function(e) {
if ( $('#help').css("display") === "none") {
e.preventDefault();
simulateKeydown(13);
}
});
$("#control-up, #control-up-second, #control-up-big").on("mousedown touchstart", function(e) {
e.preventDefault();
Expand Down
53 changes: 42 additions & 11 deletions js/bubbles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var BUBBLES = [];
var BUBBLES_ARRAY = new Array();
var BUBBLES_CANVAS_CONTEXT = null;
var BUBBLES_X_START = 30;
var BUBBLES_X_END = 518;
Expand All @@ -13,10 +13,11 @@ var SUPER_BUBBLES_SIZE = 8;
var SUPER_BUBBLES_BLINK = false;
var SUPER_BUBBLES_BLINK_STATE = 0;
var SUPER_BUBBLES_BLINK_TIMER = -1;
var SUPER_BUBBLES_BLINK_SPEED = 300;
var SUPER_BUBBLES_BLINK_SPEED = 525;

function initBubbles() {
BUBBLES_COUNTER = 0;
BUBBLES_ARRAY.length = 0;

var canvas = document.getElementById('canvas-bubbles');
canvas.setAttribute('width', '550');
Expand All @@ -31,6 +32,7 @@ function getBubblesCanevasContext() {
}

function drawBubbles() {

var ctx = getBubblesCanevasContext();
ctx.fillStyle = "#dca5be";

Expand All @@ -43,7 +45,7 @@ function drawBubbles() {
if (isSuperBubble(line, bubble)) {
type = "s";
size = SUPER_BUBBLES_SIZE;
SUPER_BUBBLES[s] = line + ";" + bubble + ";" + correctionX(x, bubble) + "," + y;
SUPER_BUBBLES[s] = line + ";" + bubble + ";" + parseInt(correctionX(x, bubble)) + "," + parseInt(y) + ";0";
s ++;
} else {
type = "b";
Expand All @@ -55,7 +57,7 @@ function drawBubbles() {
ctx.fill();
ctx.closePath();

BUBBLES[parseInt(correctionX(x, bubble)) + "," + parseInt(y)] = line + ";" + bubble + ";" + type + ";0"
BUBBLES_ARRAY.push( parseInt(correctionX(x, bubble)) + "," + parseInt(y) + ";" + line + ";" + bubble + ";" + type + ";0" );
i ++;
}
}
Expand All @@ -69,6 +71,7 @@ function stopBlinkSuperBubbles() {
}

function blinkSuperBubbles() {

if (SUPER_BUBBLES_BLINK === false) {
SUPER_BUBBLES_BLINK = true;
SUPER_BUBBLES_BLINK_TIMER = setInterval('blinkSuperBubbles()', SUPER_BUBBLES_BLINK_SPEED);
Expand All @@ -80,16 +83,16 @@ function blinkSuperBubbles() {
SUPER_BUBBLES_BLINK_STATE = 0;
}

for (var i = 0, imax = SUPER_BUBBLES.length; i < imax; i ++) {
var clone = SUPER_BUBBLES.slice(0);

var s = SUPER_BUBBLES[i];
var sx = parseInt(s.split(";")[2].split(",")[0]);
var sy = parseInt(s.split(";")[2].split(",")[1]);
for (var i = 0, imax = clone.length; i < imax; i ++) {

var b = BUBBLES[sx + "," + sy];
var eat = b.split(";")[3];
var s = clone[i];

if ( s.split(";")[3] === "0" ) {

if (eat === "0") {
var sx = parseInt(s.split(";")[2].split(",")[0]);
var sy = parseInt(s.split(";")[2].split(",")[1]);

if (SUPER_BUBBLES_BLINK_STATE === 1) {
eraseBubble("s", sx, sy);
Expand All @@ -107,6 +110,34 @@ function blinkSuperBubbles() {
}
}

function setSuperBubbleOnXY( x, y, eat ) {

for (var i = 0, imax = SUPER_BUBBLES.length; i < imax; i ++) {
var bubbleParams = SUPER_BUBBLES[i].split( ";" );
var testX = parseInt(bubbleParams[2].split( "," )[0]);
var testY = parseInt(bubbleParams[2].split( "," )[1]);
if ( testX === x && testY === y ) {
SUPER_BUBBLES[i] = SUPER_BUBBLES[i].substr( 0, SUPER_BUBBLES[i].length - 1 ) + "1";
break;
}
}
}

function getBubbleOnXY( x, y ) {

var bubble = null;
for (var i = 0, imax = BUBBLES_ARRAY.length; i < imax; i ++) {
var bubbleParams = BUBBLES_ARRAY[i].split( ";" );
var testX = parseInt(bubbleParams[0].split( "," )[0]);
var testY = parseInt(bubbleParams[0].split( "," )[1]);
if ( testX === x && testY === y ) {
bubble = BUBBLES_ARRAY[i];
break;
}
}
return bubble;
}

function eraseBubble(t, x, y) {

var ctx = getBubblesCanevasContext();
Expand Down
44 changes: 22 additions & 22 deletions js/ghosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function drawGhosts() {
drawGhost("clyde");
}
function drawGhost(ghost) {

var ctx = getGhostCanevasContext(ghost);

if (eval('GHOST_' + ghost.toUpperCase() + '_STATE === 0')) {
Expand All @@ -151,6 +152,8 @@ function drawGhost(ghost) {
eval('drawHelperGhost(ctx, GHOST_' + ghost.toUpperCase() + '_POSITION_X, GHOST_' + ghost.toUpperCase() + '_POSITION_Y, GHOST_' + ghost.toUpperCase() + '_DIRECTION, GHOST_' + ghost.toUpperCase() + '_BODY_STATE, GHOST_' + ghost.toUpperCase() + '_STATE, GHOST_' + ghost.toUpperCase() + '_AFFRAID_STATE)');

ctx.closePath();


}

function affraidGhosts() {
Expand Down Expand Up @@ -207,21 +210,24 @@ function testStateGhosts() {
}

function startEatGhost(ghost) {
playEatGhostSound();

LOCK = true;

if ( eval('GHOST_' + ghost.toUpperCase() + '_AFFRAID_TIMER !== null') ) {
eval('GHOST_' + ghost.toUpperCase() + '_AFFRAID_TIMER.cancel()');
eval('GHOST_' + ghost.toUpperCase() + '_AFFRAID_TIMER = null');
if ( !LOCK ) {
playEatGhostSound();

LOCK = true;

if ( eval('GHOST_' + ghost.toUpperCase() + '_AFFRAID_TIMER !== null') ) {
eval('GHOST_' + ghost.toUpperCase() + '_AFFRAID_TIMER.cancel()');
eval('GHOST_' + ghost.toUpperCase() + '_AFFRAID_TIMER = null');
}

score(SCORE_GHOST_COMBO, ghost);

pauseGhosts();
pausePacman();

setTimeout('eatGhost(\''+ ghost + '\')', 600);
}

score(SCORE_GHOST_COMBO, ghost);

pauseGhosts();
pausePacman();

setTimeout('eatGhost(\''+ ghost + '\')', 600);
}

function eatGhost(ghost) {
Expand Down Expand Up @@ -315,7 +321,9 @@ function moveGhost(ghost) {
drawGhost(ghost);

if (eval('GHOST_' + ghost.toUpperCase() + '_BODY_STATE === 3') && eval('GHOST_' + ghost.toUpperCase() + '_STATE != -1')) {
testGhostPacman(ghost);
if ( !PACMAN_MOVING ) {
testGhostPacman(ghost);
}
testGhostTunnel(ghost);
}
} else {
Expand Down Expand Up @@ -465,15 +473,7 @@ function eraseGhost(ghost) {

var ctx = getGhostCanevasContext(ghost);

//ctx.save();
//ctx.globalCompositeOperation = "destination-out";

//ctx.beginPath();
eval('ctx.clearRect(GHOST_' + ghost.toUpperCase() + '_POSITION_X - 17, GHOST_' + ghost.toUpperCase() + '_POSITION_Y - 17, 34, 34)');
//ctx.fill();

//ctx.closePath();
//ctx.restore();
}
function eraseGhosts() {

Expand Down
1 change: 1 addition & 0 deletions js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function initHome() {

$("#panel").hide();
$("#home").show();
$("#home h3 em").append( " - " + new Date().getFullYear() );

$('#help').fadeOut("slow");

Expand Down
13 changes: 9 additions & 4 deletions js/jquery-buzz.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// ----------------------------------------------------------------------------
// Buzz, a Javascript HTML5 Audio library
// v1.1.10 - Built 2015-04-20 13:05
// v1.2.0 - Built 2016-05-22 15:16
// Licensed under the MIT license.
// http://buzz.jaysalvat.com/
// ----------------------------------------------------------------------------
// Copyright (C) 2010-2015 Jay Salvat
// Copyright (C) 2010-2016 Jay Salvat
// http://jaysalvat.com/
// ----------------------------------------------------------------------------

Expand All @@ -23,6 +23,7 @@
var buzz = {
defaults: {
autoplay: false,
crossOrigin: null,
duration: 5e3,
formats: [],
loop: false,
Expand Down Expand Up @@ -427,10 +428,11 @@
} else {
duration = duration || buzz.defaults.duration;
}
var from = this.volume, delay = duration / Math.abs(from - to), self = this;
var from = this.volume, delay = duration / Math.abs(from - to), self = this, fadeToTimeout;
this.play();
function doFade() {
setTimeout(function() {
clearTimeout(fadeToTimeout);
fadeToTimeout = setTimeout(function() {
if (from < to && self.volume < to) {
self.setVolume(self.volume += 1);
doFade();
Expand Down Expand Up @@ -516,6 +518,9 @@
}
}
this.sound = doc.createElement("audio");
if (options.crossOrigin !== null) {
this.sound.crossOrigin = options.crossOrigin;
}
if (options.webAudioApi) {
var audioCtx = buzz.getAudioContext();
if (audioCtx) {
Expand Down
56 changes: 23 additions & 33 deletions js/pacman.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function movePacman(direction) {

if (PACMAN_MOVING === false) {
PACMAN_MOVING = true;
drawPacman();
PACMAN_MOVING_TIMER = setInterval('movePacman()', PACMAN_MOVING_SPEED);
}

Expand Down Expand Up @@ -304,53 +305,42 @@ function testFruitsPacman() {
}
}
function testBubblesPacman() {

var i, imax;
if (PACMAN_DIRECTION === 3 || PACMAN_DIRECTION === 4) {
i = -PACMAN_EAT_GAP;
imax = 0;
} else if (PACMAN_DIRECTION === 1 || PACMAN_DIRECTION === 2) {
i = 0;
imax = PACMAN_EAT_GAP;
}


for ( ; i < imax; i ++ ) {

var testX = (PACMAN_POSITION_X);
var testY = (PACMAN_POSITION_Y);
if (PACMAN_DIRECTION === 3 || PACMAN_DIRECTION === 1) {
testX += i;
} else if (PACMAN_DIRECTION === 4 || PACMAN_DIRECTION === 2) {
testY += i;
}

var b = BUBBLES[testX + "," + testY];
var r = { x: PACMAN_POSITION_X - ( PACMAN_SIZE / 2 ), y: PACMAN_POSITION_Y - ( PACMAN_SIZE / 2 ) , width: ( PACMAN_SIZE * 2 ), height: ( PACMAN_SIZE * 2 ) };

for (var i = 0, imax = BUBBLES_ARRAY.length; i < imax; i ++) {
var bubble = BUBBLES_ARRAY[i];

var bubbleParams = bubble.split( ";" );
var testX = parseInt(bubbleParams[0].split( "," )[0]);
var testY = parseInt(bubbleParams[0].split( "," )[1]);
var p = { x: testX, y: testY };

if (b) {
var t = b.split(";");
var eat = t[3];
if ( isPointInRect( p, r ) ) {

if (eat === "0") {
var type = t[2];
eraseBubble(type, testX, testY);
BUBBLES[testX + "," + testY] = b.substr(0, b.length - 1) + "1";
if (type === "s") {
score(SCORE_SUPER_BUBBLE);
if ( bubbleParams[4] === "0" ) {
var type = bubbleParams[3];

eraseBubble( type, testX, testY );
BUBBLES_ARRAY[i] = bubble.substr( 0, bubble.length - 1 ) + "1"

if ( type === "s" ) {
setSuperBubbleOnXY( testX, testY, "1" );
score( SCORE_SUPER_BUBBLE );
playEatPillSound();
affraidGhosts();
} else {
score(SCORE_BUBBLE);
score( SCORE_BUBBLE );
playEatingSound();
}
BUBBLES_COUNTER --;
if (BUBBLES_COUNTER === 0) {
if ( BUBBLES_COUNTER === 0 ) {
win();
}
return;
} else {
stopEatingSound();
}
return;
}
}
}
Loading

0 comments on commit 38494fc

Please sign in to comment.