Skip to content

Commit

Permalink
Bringing pinball code in sync with what's online at corehtml5canvas.com
Browse files Browse the repository at this point in the history
  • Loading branch information
corehtml5canvas committed Sep 27, 2013
1 parent ce08dc4 commit d80b58d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions ch09/pinball/pinball.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ var game = new Game('pinball', 'gameCanvas'),


showingHighScores = true, showingHighScores = true,


// Cursor readout.............................................

readoutToast = document.getElementById('readoutToast'),

// Flippers................................................... // Flippers...................................................


LEFT_FLIPPER = 1, LEFT_FLIPPER = 1,
Expand Down Expand Up @@ -272,7 +268,7 @@ pausedToast.onclick = function (e) {
pausedToast.style.display = 'none'; pausedToast.style.display = 'none';
togglePaused(); togglePaused();
}; };
/*
window.onblur = function windowOnBlur() { window.onblur = function windowOnBlur() {
if (!launching && !loading && !gameOver && !game.paused) { if (!launching && !loading && !gameOver && !game.paused) {
game.togglePaused(); game.togglePaused();
Expand All @@ -286,7 +282,6 @@ window.onfocus = function windowOnFocus() {
pausedToast.style.display = game.paused ? 'inline' : 'none'; pausedToast.style.display = game.paused ? 'inline' : 'none';
} }
}; };
*/


// New game .................................................. // New game ..................................................


Expand All @@ -297,10 +292,9 @@ newGameButton.onclick = function (e) {


function startNewGame() { function startNewGame() {
showPolygonsOnlyToast.style.display = 'block'; showPolygonsOnlyToast.style.display = 'block';
readoutToast.style.display = 'block';
highScoreParagraph.style.display = 'none'; highScoreParagraph.style.display = 'none';
gameOver = false; gameOver = false;
livesLeft = 1; livesLeft = 3;
score = 0; score = 0;
showingHighScores = false; showingHighScores = false;
loading = false; loading = false;
Expand Down Expand Up @@ -542,7 +536,7 @@ function detectCollisions() {
shape === oneHundredBumperLeft || shape === oneHundredBumperLeft ||
shape === oneHundredBumperRight || shape === oneHundredBumperRight ||
shape === fiveHundredBumper) { shape === fiveHundredBumper) {
//game.playSound('bumper'); game.playSound('bumper');
bounce(mtv, shape, 4.5); bounce(mtv, shape, 4.5);
bumperLit = shape; bumperLit = shape;
return true; return true;
Expand Down Expand Up @@ -738,16 +732,16 @@ game.startAnimate = function (time) {
if (loading || game.paused || launching) if (loading || game.paused || launching)
return; return;


if (!gameOver && livesLeft === 0) {
over();
return;
}


if (ballOutOfPlay) { if (ballOutOfPlay) {
ballOutOfPlay = false; ballOutOfPlay = false;
prepareForLaunch(); prepareForLaunch();
brieflyShowTryAgainImage(2000); brieflyShowTryAgainImage(2000);
livesLeft--; livesLeft--;

if (!gameOver && livesLeft === 0) {
over();
}
return; return;
} }


Expand Down Expand Up @@ -963,7 +957,7 @@ game.addKeyListener(
if ( !launching && !gameOver) { if ( !launching && !gameOver) {
rightFlipperRiseTimer.start(); rightFlipperRiseTimer.start();
rightFlipperAngle = 0; rightFlipperAngle = 0;
//game.playSound('flipper'); game.playSound('flipper');
} }
} }
} }
Expand All @@ -976,7 +970,7 @@ game.addKeyListener(
if ( !launching && !gameOver) { if ( !launching && !gameOver) {
leftFlipperRiseTimer.start(); leftFlipperRiseTimer.start();
leftFlipperAngle = 0; leftFlipperAngle = 0;
//game.playSound('flipper'); game.playSound('flipper');
} }
} }
} }
Expand Down Expand Up @@ -1312,11 +1306,6 @@ function drawVerticalLine (x) {
game.context.stroke(); game.context.stroke();
} }


game.context.canvas.onmousemove = function (e) {
var loc = windowToCanvas(e);
readoutToast.innerText = '(' + loc.x.toFixed(0) + ', ' + loc.y.toFixed(0) + ')';
};

showPolygonsOnlyCheckbox.onclick = function (e) { showPolygonsOnlyCheckbox.onclick = function (e) {
showPolygonsOnly = showPolygonsOnlyCheckbox.checked; showPolygonsOnly = showPolygonsOnlyCheckbox.checked;
if (showPolygonsOnly) { if (showPolygonsOnly) {
Expand Down Expand Up @@ -1432,7 +1421,6 @@ var interval = setInterval( function (e) {


showPolygonsOnlyToast.style.display = 'block'; showPolygonsOnlyToast.style.display = 'block';
showPolygonsOnlyToast.style.left = '290px'; showPolygonsOnlyToast.style.left = '290px';
readoutToast.style.display = 'block';
scoreToast.style.display = 'inline'; scoreToast.style.display = 'inline';


launching = true; launching = true;
Expand All @@ -1443,7 +1431,7 @@ var interval = setInterval( function (e) {


ballSprite.visible = true; ballSprite.visible = true;
actuatorSprite.visible = true; actuatorSprite.visible = true;
//game.playSound('jingle'); //game.playSound('pinball');


for (var i=0; i < LAUNCH_STEPS; ++i) { for (var i=0; i < LAUNCH_STEPS; ++i) {
launchImages[i] = new Image(); launchImages[i] = new Image();
Expand Down
Binary file added ch09/pinball/sounds/pinball.ogg
Binary file not shown.

0 comments on commit d80b58d

Please sign in to comment.