diff --git a/js/input.js b/js/input.js index d993d64..2eb7173 100644 --- a/js/input.js +++ b/js/input.js @@ -1,9 +1,9 @@ var prevGameState; function showText(text){ var messages = { - 'paused':"
Paused

Press p to resume
", + 'paused':"
Paused

Press p to resume
", 'start':"
Press enter to start
", - 'gameover':"
Game Over: "+score+" pts

Press enter to restart
", + 'gameover':"
Game Over: "+score+" pts

1. "+highscores[0]+"
2. "+highscores[1]+"
3. "+highscores[2]+"

Press enter to restart
", }; var pt = document.getElementById("overlay"); diff --git a/js/main.js b/js/main.js index fed080b..b30ccaa 100644 --- a/js/main.js +++ b/js/main.js @@ -304,25 +304,27 @@ function animLoop() { requestAnimFrame(animLoop); update(); render(); - gameOverDisplay(); - highscores = localStorage.getItem('highscores').split(',').map(Number); - for (var i = 0; i < numHighScores; i++) { - if (highscores[i] < score) { - for (var j = numHighScores - 1; j > i; j--) { - highscores[j] = highscores[j - 1]; - } - highscores[i] = score; - break; - } - } - - localStorage.setItem('highscores', highscores); - } + } else { setStartScreen(); } } +function updateHighScore(){ + if(localStorage.getItem('highscores')){ + highscores = localStorage.getItem('highscores').split(',').map(Number); + } + for (var i = 0; i < numHighScores; i++) { + if (highscores[i] <= score) { + highscores.splice(i, 0, score); + highscores = highscores.slice(0,-1); + break; + } + } + + localStorage.setItem('highscores', highscores); + +} requestAnimFrame(animLoop); function isInfringing(clock){ for(var i=0;i