fixed restart bug

This commit is contained in:
Michael Yang 2014-05-24 15:42:40 -04:00
parent b1a39795fa
commit c11cd336fe
3 changed files with 13 additions and 8 deletions

View file

@ -222,6 +222,7 @@ function Clock(sideLength) {
};
this.rotate = function(steps) {
if (gameState != 1) return;
this.position += steps;
if (!history[count]) {
history[count] = {};

View file

@ -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,9 +27,9 @@ keypress.register_combo({
on_keydown: function() {
if (Math.abs(gameState) == 1) {
gameState = -gameState;
}
requestAnimFrame(animLoop);
}
}
});
keypress.register_combo({

View file

@ -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;
}