removed white gaps, changed method for starting previously saved game to calling resumeGame (after init is called)
This commit is contained in:
parent
8ad952b379
commit
31c4b4d96a
5 changed files with 59 additions and 14 deletions
|
@ -51,6 +51,9 @@ function Block(fallingLane, color, iter, distFromHex, settled) {
|
|||
//slate for final deletion
|
||||
this.opacity = 0;
|
||||
this.deleted = 2;
|
||||
if (gameState == 1) {
|
||||
localStorage.setItem("saveState", exportSaveState());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -141,6 +144,9 @@ function Block(fallingLane, color, iter, distFromHex, settled) {
|
|||
|
||||
if (this.tint) {
|
||||
if (this.opacity < 1) {
|
||||
if (gameState == 1) {
|
||||
localStorage.setItem("saveState", exportSaveState());
|
||||
}
|
||||
this.tint = 0;
|
||||
}
|
||||
ctx.fillStyle = "#FFF";
|
||||
|
|
20
js/input.js
20
js/input.js
|
@ -101,8 +101,8 @@ keypress.register_combo({
|
|||
if (gameState==2 || gameState==1 || importing == 1) {
|
||||
init(1);
|
||||
}
|
||||
if (gameState==0) {
|
||||
init();
|
||||
if (gameState===0) {
|
||||
resumeGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -121,19 +121,29 @@ $(document).ready(function(){
|
|||
}, false);
|
||||
|
||||
function handleClickTap(x) {
|
||||
if (!MainClock || gameState == 0) {
|
||||
if (!MainClock || gameState === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < window.innerWidth/2) {
|
||||
if (gameState != 1 && gameState != -2 && gameState != -1 ){
|
||||
init();
|
||||
if (importing === 0) {
|
||||
resumeGame();
|
||||
}
|
||||
else {
|
||||
init(1);
|
||||
}
|
||||
}
|
||||
MainClock.rotate(1);
|
||||
}
|
||||
if (x > window.innerWidth/2) {
|
||||
if (gameState != 1 && gameState != -2 && gameState != -1) {
|
||||
init();
|
||||
if (importing === 0) {
|
||||
resumeGame();
|
||||
}
|
||||
else {
|
||||
init(1);
|
||||
}
|
||||
}
|
||||
MainClock.rotate(-1);
|
||||
}
|
||||
|
|
20
js/main.js
20
js/main.js
|
@ -6,7 +6,7 @@ $(document).ready(function(){
|
|||
if (importing == 1) {
|
||||
init(1);
|
||||
} else {
|
||||
init();
|
||||
resumeGame();
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
|
@ -23,7 +23,7 @@ $(document).ready(function(){
|
|||
|
||||
$(window).resize(scaleCanvas);
|
||||
$(window).unload(function(){
|
||||
exportSaveState();
|
||||
localStorage.setItem("saveState", exportSaveState());
|
||||
});
|
||||
|
||||
function scaleCanvas() {
|
||||
|
@ -145,13 +145,25 @@ var startTime;
|
|||
var gameState;
|
||||
setStartScreen();
|
||||
|
||||
function resumeGame() {
|
||||
gameState = 1;
|
||||
hideUIElements();
|
||||
importing = 0;
|
||||
startTime = Date.now();
|
||||
waveone = saveState.wavegen || new waveGen(MainClock,Date.now(),[1,1,0],[1,1],[1,1]);
|
||||
}
|
||||
|
||||
function hideUIElements() {
|
||||
$('#pauseBtn').hide();
|
||||
$('#startBtn').hide();
|
||||
}
|
||||
|
||||
function init(b) {
|
||||
if (b) {
|
||||
clearSaveState();
|
||||
}
|
||||
|
||||
$('#pauseBtn').hide();
|
||||
$('#startBtn').hide();
|
||||
hideUIElements();
|
||||
var saveState = localStorage.getItem("saveState") || "{}";
|
||||
saveState = JSONfn.parse(saveState);
|
||||
document.getElementById("canvas").className = "";
|
||||
|
|
|
@ -3,8 +3,8 @@ function exportSaveState() {
|
|||
|
||||
if(gameState == 1 || gameState == -1 || (gameState === 0 && localStorage.getItem('saveState') !== undefined)) {
|
||||
state = {
|
||||
clock: MainClock,
|
||||
blocks: blocks,
|
||||
clock: $.extend(true, {}, MainClock),
|
||||
blocks: $.extend(true, [], blocks),
|
||||
score: score,
|
||||
wavegen: waveone,
|
||||
gdx: gdx,
|
||||
|
@ -12,15 +12,30 @@ function exportSaveState() {
|
|||
comboMultiplier:comboMultiplier
|
||||
};
|
||||
|
||||
state.clock.blocks.map(function(i){i.map(function(o){o.distFromHex /= settings.scale})});
|
||||
state.blocks.map(function(block){block.distFromHex /= settings.scale;});
|
||||
state.clock.blocks.map(function(a){
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
a[i] = $.extend(true, {}, a[i]);
|
||||
}
|
||||
|
||||
a.map(descaleBlock);
|
||||
});
|
||||
|
||||
for (var i = 0; i < state.blocks.length; i++) {
|
||||
state.blocks[i] = $.extend(true, {}, state.blocks[i]);
|
||||
}
|
||||
|
||||
state.blocks.map(descaleBlock);
|
||||
}
|
||||
|
||||
return JSONfn.stringify(state);
|
||||
}
|
||||
|
||||
function descaleBlock(b) {
|
||||
b.distFromHex /= settings.scale;
|
||||
}
|
||||
|
||||
function clearSaveState() {
|
||||
localStorage.setItem("saveState", "{}");
|
||||
localStorage.setItem("saveState", "{}");
|
||||
}
|
||||
|
||||
function isStateSaved() {
|
||||
|
|
|
@ -6,6 +6,7 @@ var hexColorsToTintedColors = {
|
|||
"#2ecc71":"rgb(150,227,183)"
|
||||
};
|
||||
|
||||
//legacy support
|
||||
var rgbToHex = {
|
||||
"rgb(231,76,60)":"#e74c3c",
|
||||
"rgb(241,196,15)":"#f1c40f",
|
||||
|
@ -13,6 +14,7 @@ var rgbToHex = {
|
|||
"rgb(46,204,113)":"#2ecc71"
|
||||
};
|
||||
|
||||
//legacy support
|
||||
var rgbColorsToTintedColors = {
|
||||
"rgb(231,76,60)":"rgb(241,163,155)",
|
||||
"rgb(241,196,15)":"rgb(246,223,133)",
|
||||
|
|
Loading…
Reference in a new issue