fixed pause button toggling in the opposite manner. added more

highscores infrastructure to make it more reliable / more modular
This commit is contained in:
meadowstream 2014-07-26 09:23:03 -04:00
parent f0a9a4ce9b
commit e69482b453
4 changed files with 23 additions and 16 deletions

View file

@ -127,7 +127,7 @@ function initialize(a) {
if(localStorage.getItem('highscores'))
highscores = JSON.parse(localStorage.getItem('highscores'));
localStorage.setItem('highscores', JSON.stringify(highscores));
writeHighScores();
window.blocks = [];
window.MainHex;

View file

@ -295,7 +295,7 @@ function checkGameOver() {
for (var i = 0; i < MainHex.sides; i++) {
if (isInfringing(MainHex)) {
highscores.push(score);
localStorage.setItem('highscores', JSON.stringify(highscores));
writeHighScores();
gameOverDisplay();
return true;
}

View file

@ -36,6 +36,14 @@ function descaleBlock(b) {
b.distFromHex /= settings.scale;
}
function writeHighScores() {
if (Object.prototype.toString.call(highscores) === '[object Array]') {
localStorage.setItem("highscores", JSON.stringify(highscores));
} else {
debugger;
}
}
function clearSaveState() {
localStorage.setItem("saveState", "{}");
}

View file

@ -90,12 +90,10 @@ function showText(text){
};
if (text == 'gameover') {
debugger;
var allZ = 1;
var i;
highscores.sort(function(a,b){a = parseInt(a, 10); b = parseInt(b, 10); if (a < b) {return 1;} else if (a > b) {return -1;}else {return 0;}});
localStorage.setItem('highscores', JSON.stringify(highscores));
debugger;
writeHighScores();
for (i = 0; i < 3; i++) {
if (highscores.length > i) {
messages['gameover'] += "<tr> <th class='tg-031e'>"+(i+1)+".</th> <th class='tg-031e'>"+highscores[i] + " pts</th> </tr>";
@ -119,8 +117,8 @@ function showText(text){
}
}
}
$("#overlay").html(messages[text]);
$("#overlay").fadeIn("1000","swing");
$("#overlay").html(messages[text]);
$("#overlay").fadeIn("1000","swing");
if (text == 'paused') {
if (settings.platform == 'mobile') {
text = 'pausedMobile';
@ -150,19 +148,19 @@ function setMainMenu() {
}
function hideText() {
$("#overlay").fadeOut("1000",function(){$("#overlay").html("");})
$("#overlay").fadeOut("1000",function(){$("#overlay").html("");})
}
function gameOverDisplay(){
$("#attributions").show();
$("#attributions").show();
var c = document.getElementById("canvas");
c.className = "blur";
showText('gameover');
showbottombar();
showbottombar();
}
function pause(o) {
localStorage.setItem('highscores', JSON.stringify(highscores));
writeHighScores();
var message;
if (o) {
message = '';
@ -172,17 +170,17 @@ function pause(o) {
var c = document.getElementById("canvas");
if (gameState == -1) {
$("#pauseBtn").html('<i class="fa fa-play fa-2x"></i>');
if ($('#helpScreen').is(':visible')) {
$('#helpScreen').fadeOut(150, "linear");
}
$("#pauseBtn").html('<i class="fa fa-pause fa-2x"></i>');
$('.helpText').fadeOut(200, 'linear');
hideText();
hidebottombar();
setTimeout(function () {
gameState = prevGameState;
},200)
setTimeout(function () {
gameState = prevGameState;
},200)
}
else if(gameState != -2 && gameState !== 0 && gameState !== 2) {
@ -191,7 +189,8 @@ function pause(o) {
if (message == 'paused') {
showText(message);
}
$("#pauseBtn").html('<i class="fa fa-pause fa-2x"></i>');
$("#pauseBtn").html('<i class="fa fa-play fa-2x"></i>');
prevGameState = gameState;
gameState = -1;
}