Merge branch 'gh-pages' of https://github.com/teamsnowman/hextris into gh-pages

This commit is contained in:
Michael Yang 2014-05-26 01:12:01 -04:00
commit 4af9d97442
6 changed files with 82 additions and 40 deletions

View file

@ -49,23 +49,25 @@
<body>
<canvas id="canvas"></canvas>
<div id='devtools' style='z-index:3;display:none;position:absolute;left:50%;width:400px;height:400px;top:50%;margin-top:-200px;margin-left:-200px;'>
<h2 id = 'clickToExit' style = 'background-color:#fff;color:#000'>Click to exit</h2>
<textarea id ='devtoolsText' style = 'height:300px;width:400px;'></textarea>
</div>
<script type = 'text/javascript' src="vendor/hammer.min.js"></script>
<script type = 'text/javascript' src="vendor/keypress.min.js"></script>
<script type = 'text/javascript' src="vendor/jquery.js"></script>
<script type = 'text/javascript' src="js/view.js"></script>
<script type = 'text/javascript' src="js/wavegen.js"></script>
<script type = 'text/javascript' src="js/math.js"></script>
<script type = 'text/javascript' src="js/entities.js"></script>
<script type = 'text/javascript' src="js/Block.js"></script>
<script type = 'text/javascript' src="js/Clock.js"></script>
<script type = 'text/javascript' src="js/input.js"></script>
<script type = 'text/javascript' src="js/checking.js"></script>
<script type = 'text/javascript' src='js/render.js'></script>
<script type = 'text/javascript' src='js/update.js'></script>
<script type = 'text/javascript' src="js/main.js"></script>
<script type = 'text/javascript' src="js/analytics.js"></script>
<h2 id = 'clickToExit' style = 'background-color:#fff;color:#000'>Click to exit</h2>
<textarea id ='devtoolsText' style = 'height:300px;width:400px;'></textarea>
</div>
<script type = 'text/javascript' src="vendor/hammer.min.js"></script>
<script type = 'text/javascript' src="vendor/jsonfn.min.js"></script>
<script type = 'text/javascript' src="vendor/keypress.min.js"></script>
<script type = 'text/javascript' src="vendor/jquery.js"></script>
<script type = 'text/javascript' src="js/save-state.js"></script>
<script type = 'text/javascript' src="js/view.js"></script>
<script type = 'text/javascript' src="js/wavegen.js"></script>
<script type = 'text/javascript' src="js/math.js"></script>
<script type = 'text/javascript' src="js/entities.js"></script>
<script type = 'text/javascript' src="js/Block.js"></script>
<script type = 'text/javascript' src="js/Clock.js"></script>
<script type = 'text/javascript' src="js/input.js"></script>
<script type = 'text/javascript' src="js/checking.js"></script>
<script type = 'text/javascript' src='js/update.js'></script>
<script type = 'text/javascript' src='js/render.js'></script>
<script type = 'text/javascript' src="js/main.js"></script>
<script type = 'text/javascript' src="js/analytics.js"></script>
</body>
</html>

View file

@ -47,7 +47,6 @@ function Clock(sideLength) {
block.distFromHex = MainClock.sideLength / 2 * Math.sqrt(3) + block.height * this.blocks[lane].length;
this.blocks[lane].push(block);
block.attachedLane = lane;
block.parentArr = this.blocks[lane];
consolidateBlocks(this, lane, this.blocks[lane].length - 1);
};

View file

@ -9,4 +9,4 @@ var colorSounds = {"#e74c3c": new Audio("../sounds/lowest.ogg"),
"#f1c40f":new Audio("../sounds/highest.ogg"),
"#3498db":new Audio("../sounds/middle.ogg"),
"#2ecc71":new Audio("../sounds/highest.ogg") //fix this later
};
};

View file

@ -1,5 +1,8 @@
$(document).ready(scaleCanvas);
$(window).resize(scaleCanvas);
$(window).unload(function() {
localStorage.setItem("saveState", exportSaveState());
});
function scaleCanvas() {
canvas.width = $(window).width();
@ -86,7 +89,6 @@ if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigat
};
}
var gameState = 0;
var framerate = 60;
var history = {};
var score = 0;
@ -115,21 +117,55 @@ var importing = 0;
var importedHistory;
var startTime;
var gameState;
if(isStateSaved())
init();
else
gameState = 0;
function init() {
var saveState = localStorage.getItem("saveState") || "{}";
saveState = JSONfn.parse(saveState);
history = {};
importedHistory = undefined;
importing = 0;
isGameOver = 2;
score = 0;
score = saveState.score || 0;
prevScore = 0;
spawnLane = 0;
gameState = -2;
count = 0;
blocks = [];
MainClock = new Clock(settings.hexWidth);
if(saveState.blocks) {
for(var i=0; i<saveState.blocks.length; i++) {
var block = saveState.blocks[i];
blocks.push(block);
}
console.log(blocks);
}
else {
blocks = [];
}
gdx = saveState.gdx || 0;
gdy = saveState.gdy || 0;
MainClock = saveState.clock || new Clock(settings.hexWidth);
for(var i=0; i<MainClock.blocks.length; i++) {
for(var j=0; j<MainClock.blocks[i].length; j++) {
MainClock.blocks[i][j].settled = 0;
}
}
MainClock.y = -100;
startTime = Date.now();
waveone = new waveGen(MainClock,Date.now(),[1,1,0],[1,1],[1,1]);
waveone = saveState.wavegen || new waveGen(MainClock,Date.now(),[1,1,0],[1,1],[1,1]);
clearSaveState();
}
function addNewBlock(blocklane, color, iter, distFromHex, settled) { //last two are optional parameters
@ -207,6 +243,7 @@ function animLoop() {
// isGameOver--;
// if (isGameOver === 0) {
gameState = 2;
clearSaveState();
// }
}
}

View file

@ -1,21 +1,24 @@
function exportSaveState() {
var state = {
clock: undefined,
blocks: undefined,
iter: undefined,
score: undefined,
};
var state = {};
if(gameState == 1) {
state.clock = MainClock;
state.blocks = blocks;
state.iter = iter;
state.score = score;
if(gameState == 1 || gameState == -1) {
state = {
clock: MainClock,
blocks: blocks,
score: score,
wavegen: waveone,
gdx: gdx,
gdy: gdy,
}
}
return JSON.stringify(state);
return JSONfn.stringify(state);
}
function loadSaveState() {
function clearSaveState() {
localStorage.setItem("saveState", "{}");
}
function isStateSaved() {
return localStorage.getItem("saveState") != "{}";
}

1
vendor/jsonfn.min.js vendored Normal file
View file

@ -0,0 +1 @@
"use strict";(function(exports){exports.stringify=function(e){return JSON.stringify(e,function(e,t){if(t instanceof Function||typeof t=="function"){return t.toString()}if(t instanceof RegExp){return"_PxEgEr_"+t}return t})};exports.parse=function(str,date2obj){var iso8061=date2obj?/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/:false;return JSON.parse(str,function(key,value){var prefix;if(typeof value!="string"){return value}if(value.length<8){return value}prefix=value.substring(0,8);if(iso8061&&value.match(iso8061)){return new Date(value)}if(prefix==="function"){return eval("("+value+")")}if(prefix==="_PxEgEr_"){return eval(value.slice(8))}return value})};exports.clone=function(e,t){return exports.parse(exports.stringify(e),t)}})(typeof exports==="undefined"?window.JSONfn={}:exports)