diff --git a/.gitignore b/.gitignore index 96374c4..283dbfc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,11 @@ +# Firebase files +.firebaserc +firebase.json + +# Google files +googlebffbfc06c66171db.html +manifest.json + # Windows image file caches Thumbs.db ehthumbs.db diff --git a/icon_128.png b/icon_128.png new file mode 100644 index 0000000..df8d33c Binary files /dev/null and b/icon_128.png differ diff --git a/index.html b/index.html index ce434ad..9ff030b 100644 --- a/index.html +++ b/index.html @@ -4,8 +4,8 @@
- - + + @@ -17,7 +17,7 @@ - + @@ -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(); @@ -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(); diff --git a/js/bubbles.js b/js/bubbles.js index b8197f9..fef6b7d 100644 --- a/js/bubbles.js +++ b/js/bubbles.js @@ -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; @@ -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'); @@ -31,6 +32,7 @@ function getBubblesCanevasContext() { } function drawBubbles() { + var ctx = getBubblesCanevasContext(); ctx.fillStyle = "#dca5be"; @@ -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"; @@ -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 ++; } } @@ -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); @@ -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); @@ -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(); diff --git a/js/ghosts.js b/js/ghosts.js index 120a4ec..dad4737 100644 --- a/js/ghosts.js +++ b/js/ghosts.js @@ -137,6 +137,7 @@ function drawGhosts() { drawGhost("clyde"); } function drawGhost(ghost) { + var ctx = getGhostCanevasContext(ghost); if (eval('GHOST_' + ghost.toUpperCase() + '_STATE === 0')) { @@ -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() { @@ -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) { @@ -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 { @@ -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() { diff --git a/js/home.js b/js/home.js index 489ab88..cc9c856 100644 --- a/js/home.js +++ b/js/home.js @@ -57,6 +57,7 @@ function initHome() { $("#panel").hide(); $("#home").show(); + $("#home h3 em").append( " - " + new Date().getFullYear() ); $('#help').fadeOut("slow"); diff --git a/js/jquery-buzz.js b/js/jquery-buzz.js index b373e91..76c7a5f 100644 --- a/js/jquery-buzz.js +++ b/js/jquery-buzz.js @@ -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/ // ---------------------------------------------------------------------------- @@ -23,6 +23,7 @@ var buzz = { defaults: { autoplay: false, + crossOrigin: null, duration: 5e3, formats: [], loop: false, @@ -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(); @@ -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) { diff --git a/js/pacman.js b/js/pacman.js index bddee07..4607fb1 100644 --- a/js/pacman.js +++ b/js/pacman.js @@ -93,6 +93,7 @@ function movePacman(direction) { if (PACMAN_MOVING === false) { PACMAN_MOVING = true; + drawPacman(); PACMAN_MOVING_TIMER = setInterval('movePacman()', PACMAN_MOVING_SPEED); } @@ -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; } } } \ No newline at end of file diff --git a/js/sound.js b/js/sound.js index df7a5a1..9e0169b 100644 --- a/js/sound.js +++ b/js/sound.js @@ -1,41 +1,31 @@ var EATING_SOUND = new buzz.sound([ - "./sound/eating.ogg", "./sound/eating.mp3" ]); var GHOST_EATEN_SOUND = new buzz.sound([ - "./sound/ghost-eaten.ogg", "./sound/ghost-eaten.mp3" ]); var EXTRA_LIFE_SOUND = new buzz.sound([ - "./sound/extra-life.ogg", "./sound/extra-life.mp3" ]); var EAT_PILL_SOUND = new buzz.sound([ - "./sound/eat-pill.ogg", "./sound/eat-pill.mp3" ]); var EAT_FRUIT_SOUND = new buzz.sound([ - "./sound/eat-fruit.ogg", "./sound/eat-fruit.mp3" ]); var EAT_GHOST_SOUND = new buzz.sound([ - "./sound/eat-ghost.ogg", "./sound/eat-ghost.mp3" ]); var SIREN_SOUND = new buzz.sound([ - "./sound/siren.ogg", "./sound/siren.mp3" ]); var WAZA_SOUND = new buzz.sound([ - "./sound/waza.ogg", "./sound/waza.mp3" ]); var READY_SOUND = new buzz.sound([ - "./sound/ready.ogg", "./sound/ready.mp3" ]); var DIE_SOUND = new buzz.sound([ - "./sound/die.ogg", "./sound/die.mp3" ]); diff --git a/js/tools.js b/js/tools.js index 8a9d7aa..0715ab7 100644 --- a/js/tools.js +++ b/js/tools.js @@ -1,3 +1,11 @@ +function isPointInRect(point, rect) { + if (rect.width <= 0 || rect.height <= 0) { + return false; + } else { + return (point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height); + } +} + function Timer(callback, delay) { var id, started, remaining = delay, running diff --git a/sound/die.ogg b/sound/die.ogg deleted file mode 100644 index 3ffd959..0000000 Binary files a/sound/die.ogg and /dev/null differ diff --git a/sound/eat-fruit.ogg b/sound/eat-fruit.ogg deleted file mode 100644 index b65c4cf..0000000 Binary files a/sound/eat-fruit.ogg and /dev/null differ diff --git a/sound/eat-ghost.ogg b/sound/eat-ghost.ogg deleted file mode 100644 index 59a60e2..0000000 Binary files a/sound/eat-ghost.ogg and /dev/null differ diff --git a/sound/eat-pill.ogg b/sound/eat-pill.ogg deleted file mode 100644 index b65c4cf..0000000 Binary files a/sound/eat-pill.ogg and /dev/null differ diff --git a/sound/eating.ogg b/sound/eating.ogg deleted file mode 100644 index 3269383..0000000 Binary files a/sound/eating.ogg and /dev/null differ diff --git a/sound/extra-life.ogg b/sound/extra-life.ogg deleted file mode 100644 index a64153c..0000000 Binary files a/sound/extra-life.ogg and /dev/null differ diff --git a/sound/ghost-eaten.ogg b/sound/ghost-eaten.ogg deleted file mode 100644 index daf395f..0000000 Binary files a/sound/ghost-eaten.ogg and /dev/null differ diff --git a/sound/ready.ogg b/sound/ready.ogg deleted file mode 100644 index ac62f8a..0000000 Binary files a/sound/ready.ogg and /dev/null differ diff --git a/sound/siren.ogg b/sound/siren.ogg deleted file mode 100644 index 0fe60aa..0000000 Binary files a/sound/siren.ogg and /dev/null differ diff --git a/sound/waza.ogg b/sound/waza.ogg deleted file mode 100644 index 55a2647..0000000 Binary files a/sound/waza.ogg and /dev/null differ