diff --git a/js/entities.js b/js/entities.js index 0e16ee7..5392a87 100644 --- a/js/entities.js +++ b/js/entities.js @@ -222,6 +222,7 @@ function Clock(sideLength) { }; this.rotate = function(steps) { + if (gameState != 1) return; this.position += steps; if (!history[count]) { history[count] = {}; diff --git a/js/input.js b/js/input.js index 6364c2a..0195118 100644 --- a/js/input.js +++ b/js/input.js @@ -16,7 +16,7 @@ keypress.register_combo({ keypress.register_combo({ keys: "enter", on_keydown: function() { - if (Math.abs(gameState) != 1) { + if (Math.abs(gameState) == 0) { init(); } } @@ -27,8 +27,8 @@ keypress.register_combo({ on_keydown: function() { if (Math.abs(gameState) == 1) { gameState = -gameState; + requestAnimFrame(animLoop); } - requestAnimFrame(animLoop); } }); diff --git a/js/main.js b/js/main.js index 4afd325..60a328e 100644 --- a/js/main.js +++ b/js/main.js @@ -35,7 +35,7 @@ var numHighScores = 3; var highscores = [0, 0, 0]; if(localStorage.getItem('highscores')) - highscores = localStorage.getItem('highscores').split(',').map(Number); + highscores = localStorage.getItem('highscores').split(',').map(Number); localStorage.setItem('highscores', highscores); @@ -240,8 +240,12 @@ function animLoop() { else if (gameState == -1) { showModal('Paused!', 'Press "P" to continue.'); } - else if (gameState == 2) { - if (checkGameOver()) { + else if (gameState == 2) { // fix so that it clears blocks then checks for game over + // if (checkGameOver()) { + requestAnimFrame(animLoop); + update(); + render(); + checkGameOver(); showModal('Game over: ' + score + ' pts!', 'Press enter to restart!'); highscores = localStorage.getItem('highscores').split(',').map(Number); for (var i = 0; i < numHighScores; i++) { @@ -256,9 +260,9 @@ function animLoop() { localStorage.setItem('highscores', highscores); } else { - gameState = 1; + gameState = 0; } - } + // } } requestAnimFrame(animLoop); @@ -272,7 +276,7 @@ function checkGameOver() { return false; } window.onblur = function (e) { - gameState=-1; + if (gameState == 1) gameState = -1; }