Commits

Cong  committed 1214884

Wait a while before skipping die screen

  • Participants
  • Parent commits df0764a

Comments (0)

Files changed (1)

File javascripts/main.js

 
 // Set up scene and objects
 var gameState = "start";  // start, playing, end
+var dieTime = null;
 
 // Keyboard
 var keysPressed = {};
 		highScore.set(score.value)
 	}
     // Check for key presses
-    if ( keysPressed.left || keysPressed.right || keysPressed.up || keysPressed.down ) {
+    // Wait a while before reloading to prevent reloading immediately
+    // because the player is still pressing keys hectically
+    var isStillHectic = clock.elapsedTime - dieTime < 0.5;
+    var hasPressed = keysPressed.left || keysPressed.right || keysPressed.up || keysPressed.down;
+    if ( !isStillHectic && hasPressed ) {
       location.reload();
     }
   }
 	music.stop();
 	deathMusic.play();
   gameState = "end";
+  dieTime = clock.elapsedTime;
 }
 
 function onDocumentKeyDown( event ) {