removed intro JSON, kept keypress, consolidated initialization to a single function

This commit is contained in:
lengstrom 2014-07-17 21:11:05 -04:00
parent ce6ce5e4c4
commit 80ccc10b46
12 changed files with 290 additions and 1222 deletions

View file

@ -22,7 +22,6 @@
<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/intro.js"></script>
<script type = 'text/javascript' src="js/math.js"></script>
<script type = 'text/javascript' src="js/Block.js"></script>
<script type = 'text/javascript' src="js/Hex.js"></script>
@ -33,7 +32,7 @@
<script type = 'text/javascript' src='js/render.js'></script>
<script type = 'text/javascript' src="js/input.js"></script>
<script type = 'text/javascript' src="js/main.js"></script>
<script type = 'text/javascript' src="js/analytics.js"></script>
<script type = 'text/javascript' src="js/initialization.js"></script>
<div id='startBtn' style='position:absolute;left:40%;top:38%;height:25%;width:25%;z-index:99999999;cursor:pointer;'></div>
<div id="helpScreen" class = 'unselectable'>

View file

@ -167,4 +167,3 @@ function Hex(sideLength) {
function arrayToColor(arr){
return 'rgb(' + arr[0]+ ','+arr[1]+','+arr[2]+')';
}

View file

@ -1,7 +0,0 @@
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-51272720-1', 'teamsnowman.github.io');
ga('send', 'pageview');

View file

@ -7,6 +7,7 @@ function search(twoD,oneD){
}
return false;
}
function floodFill(hex, side, index, deleting) {
if (hex.blocks[side] === undefined || hex.blocks[side][index] === undefined) {
//just makin sure stuff exists

174
js/initialization.js Normal file
View file

@ -0,0 +1,174 @@
$(document).ready(initialize);
function initialize() {
//view.js
window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"];
window.hexColorsToTintedColors = {
"#e74c3c":"rgb(241,163,155)",
"#f1c40f":"rgb(246,223,133)",
"#3498db":"rgb(151,201,235)",
"#2ecc71":"rgb(150,227,183)"
};
window.rgbToHex = {
"rgb(231,76,60)":"#e74c3c",
"rgb(241,196,15)":"#f1c40f",
"rgb(52,152,219)":"#3498db",
"rgb(46,204,113)":"#2ecc71"
};
window.rgbColorsToTintedColors = {
"rgb(231,76,60)":"rgb(241,163,155)",
"rgb(241,196,15)":"rgb(246,223,133)",
"rgb(52,152,219)":"rgb(151,201,235)",
"rgb(46,204,113)":"rgb(150,227,183)"
};
window.hexagonBackgroundColor = 'rgb(236, 240, 241)';
window.hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)';
window.centerBlue = 'rgb(44,62,80)'; //tumblr?
window.angularVelocityConst = 4;
window.scoreOpacity = 0;
window.textOpacity = 0;
window.prevGameState = undefined;
//render.js
window.op=0;
window.saveState = localStorage.getItem("saveState") || "{}";
if (saveState !== "{}"){op=1;}
//input.js
//all of main.js
//main.js
window.textShown = false;
window.requestAnimFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
window.setTimeout(callback, 1000 / framerate);
};
})();
$('#clickToExit').bind('click', toggleDevTools);
window.settings;
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
settings = {
platform:"mobile",
startDist:227,
creationDt:40,
baseScale:1.4,
scale:1,
prevScale:1,
baseHexWidth:87,
hexWidth:87,
baseBlockHeight:20,
blockHeight:20,
rows:6,
speedModifier:0.7,
creationSpeedModifier:0.7,
comboTime:240
};
} else {
settings = {
platform:"nonmobile",
baseScale:1,
startDist:340,
creationDt:9,
scale:1,
prevScale:1,
hexWidth:65,
baseHexWidth:87,
baseBlockHeight:20,
blockHeight:15,
rows:8,
speedModifier:0.65,
creationSpeedModifier:0.55,
comboTime:240
};
$("#inst_main_body").html("The goal of Hextris is to stop blocks from leaving the inside of the outer gray hexagon<br><br>Either press the right and left arrow keys or tap the left and right sides of the screen to rotate the Hexagon<br><br>Clear blocks by making 3 or more blocks of the same color touch<br><br>Get points by clearing blocks<br><br>Time left before your combo streak disappears is indicated shown by <span style='color:#f1c40f;'>the</span> <span style='color:#e74c3c'>colored<span> <span style='color:#3498db'>lines</span> <span style='color:#2ecc71'>in</span> the outer hexagon<br><br>Pause by pressing <i class = 'fa fa-pause'></i> or the letter <b>p</b><br>Restart by pressing <i class = 'fa fa-refresh'></i> or <b>enter</b><br>Bring up this menu by pressing <i class = 'fa fa-info-circle'><br><br><a href = 'url'>Found a bug? Go here</a");
}
window.canvas = document.getElementById('canvas');
window.ctx = canvas.getContext('2d');
window.trueCanvas = {width:canvas.width,height:canvas.height};
scaleCanvas();
window.framerate = 60;
window.history = {};
window.score = 0;
window.isGameOver = 3;
window.scoreAdditionCoeff = 1;
window.prevScore = 0;
window.numHighScores = 3;
window.highscores = [0, 0, 0];
if(localStorage.getItem('highscores'))
highscores = localStorage.getItem('highscores').split(',').map(Number);
localStorage.setItem('highscores', highscores);
window.blocks = [];
window.MainHex;
window.gdx = 0;
window.gdy = 0;
window.devMode = 0;
window.lastGen;
window.prevTimeScored;
window.nextGen;
window.spawnLane = 0;
window.importing = 0;
window.importedHistory;
window.startTime;
window.gameState;
setStartScreen();
window.onblur = function (e) {
if (gameState==1) {
pause();
}
};
debugger;
$('#startBtn').on('touchstart mousedown', function(){
if (importing == 1) {
init(1);
} else {
resumeGame();
}
setTimeout(function(){
if(settings.platform == "mobile"){
document.body.addEventListener('touchstart', function(e) {
handleClickTap(e.changedTouches[0].clientX);
}, false);
}
else {
document.body.addEventListener('mousedown', function(e) {
handleClickTap(e.clientX);
}, false);
}
}, 1);
});
document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
$(window).resize(scaleCanvas);
$(window).unload(function(){
if(gameState ==1 || gameState ==-1) localStorage.setItem("saveState", exportSaveState());
else localStorage.clear();
});
addKeyListeners();
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-51272720-1', 'teamsnowman.github.io');
ga('send', 'pageview');
}

View file

@ -1,3 +1,4 @@
function addKeyListeners() {
keypress.register_combo({
keys: "left",
on_keydown: function() {
@ -85,7 +86,7 @@ keypress.register_combo({
}
});
$(document).ready(function(){
$("#pauseBtn").on('touchstart mousedown', function() {
if (gameState != 1 && gameState != -1) {
return;
@ -129,8 +130,7 @@ $(document).ready(function(){
});
}
}, false);
}
function handleClickTap(x) {
if (gameState == 2 && canRestart) {

View file

@ -1,914 +0,0 @@
window.introJSON = {
"120": {
"block": {
"blocklane": 2,
"color": "#2ecc71",
"iter": 1.1778650000157
}
},
"240": {
"block": {
"blocklane": 0,
"color": "#2ecc71",
"iter": 1.2013300000627
}
},
"360": {
"block": {
"blocklane": 0,
"color": "#e74c3c",
"iter": 1.2403950001408
}
},
"399": {
"rotate": -1
},
"480": {
"block": {
"blocklane": 1,
"color": "#e74c3c",
"iter": 1.2950600002501
}
},
"491": {
"rotate": 1
},
"506": {
"rotate": 1
},
"600": {
"block": {
"blocklane": 1,
"color": "#2ecc71",
"iter": 1.3653250003907
}
},
"708": {
"rotate": 1
},
"720": {
"rotate": 1,
"block": {
"blocklane": 1,
"color": "#3498db",
"iter": 1.4511900005624
}
},
"731": {
"rotate": 1
},
"839": {
"block": {
"blocklane": 5,
"color": "#f1c40f",
"iter": 1.5673450007635
}
},
"958": {
"block": {
"blocklane": 0,
"color": "#3498db",
"iter": 1.6832410843286
}
},
"1077": {
"block": {
"blocklane": 3,
"color": "#2ecc71",
"iter": 1.8144782512578
}
},
"1143": {
"block": {
"blocklane": 5,
"color": "#f1c40f",
"iter": 1.4019395007083
}
},
"1154": {
"rotate": 1
},
"1209": {
"block": {
"blocklane": 1,
"color": "#e74c3c",
"iter": 1.4439993757924
}
},
"1266": {
"rotate": -1
},
"1275": {
"block": {
"blocklane": 2,
"color": "#e74c3c",
"iter": 1.4884187508812
}
},
"1341": {
"block": {
"blocklane": 2,
"color": "#3498db",
"iter": 1.4973469342324
}
},
"1347": {
"rotate": 1
},
"1358": {
"rotate": 1
},
"1368": {
"rotate": 1
},
"1384": {
"rotate": 1
},
"1406": {
"block": {
"blocklane": 4,
"color": "#2ecc71",
"iter": 1.5075657467373
}
},
"1426": {
"rotate": 1
},
"1471": {
"block": {
"blocklane": 5,
"color": "#3498db",
"iter": 1.5100989863257
}
},
"1496": {
"rotate": 1
},
"1504": {
"rotate": 1
},
"1535": {
"block": {
"blocklane": 0,
"color": "#e74c3c",
"iter": 1.5205050529975
}
},
"1560": {
"rotate": 1
},
"1599": {
"block": {
"blocklane": 1,
"color": "#2ecc71",
"iter": 1.523222053003
}
},
"1603": {
"rotate": 1
},
"1615": {
"rotate": 1
},
"1663": {
"block": {
"blocklane": 3,
"color": "#e74c3c",
"iter": 1.526049986342
}
},
"1680": {
"rotate": -1
},
"1712": {
"rotate": 1
},
"1727": {
"block": {
"blocklane": 3,
"color": "#e74c3c",
"iter": 1.5289888530145
}
},
"1729": {
"rotate": 1
},
"1775": {
"rotate": 1
},
"1790": {
"block": {
"blocklane": 1,
"color": "#e74c3c",
"iter": 1.5397901467705
}
},
"1852": {
"block": {
"blocklane": 0,
"color": "#2ecc71",
"iter": 1.55064874886
}
},
"1933": {
"rotate": -1
},
"1963": {
"block": {
"blocklane": 3,
"color": "#e74c3c",
"iter": 2.2027693477429
}
},
"1986": {
"rotate": 1
},
"2074": {
"block": {
"blocklane": 2,
"color": "#2ecc71",
"iter": 2.2149085852672
}
},
"2116": {
"rotate": 1
},
"2132": {
"rotate": 1
},
"2184": {
"block": {
"blocklane": 5,
"color": "#e74c3c",
"iter": 2.2431968561259
}
},
"2293": {
"rotate": 1
},
"2294": {
"block": {
"blocklane": 0,
"color": "#2ecc71",
"iter": 2.2565405436526
}
},
"2341": {
"rotate": 1
},
"2354": {
"rotate": 1
},
"2368": {
"rotate": 1
},
"2404": {
"block": {
"blocklane": 2,
"color": "#2ecc71",
"iter": 2.2705396478472
}
},
"2478": {
"rotate": -1
},
"2512": {
"block": {
"blocklane": 3,
"color": "#3498db",
"iter": 2.300521872876
}
},
"2550": {
"rotate": 1
},
"2563": {
"rotate": 1
},
"2578": {
"rotate": 1
},
"2620": {
"block": {
"blocklane": 2,
"color": "#e74c3c",
"iter": 2.315535897906
}
},
"2660": {
"rotate": -1
},
"2679": {
"rotate": -1
},
"2728": {
"block": {
"blocklane": 2,
"color": "#f1c40f",
"iter": 2.3311817229373
}
},
"2774": {
"rotate": -1
},
"2788": {
"rotate": -1
},
"2809": {
"rotate": -1
},
"2853": {
"rotate": 1
},
"2864": {
"block": {
"blocklane": 5,
"color": "#3498db",
"iter": 2.3023826063118
}
},
"2876": {
"rotate": 1
},
"2909": {
"rotate": 1
},
"2970": {
"block": {
"blocklane": 1,
"color": "#2ecc71",
"iter": 2.3191339188453
}
},
"3050": {
"rotate": 1
},
"3055": {
"rotate": -1
},
"3066": {
"rotate": -1
},
"3074": {
"rotate": -1,
"block": {
"blocklane": 2,
"color": "#f1c40f",
"iter": 2.3517606688794
}
},
"3146": {
"rotate": 1
},
"3178": {
"block": {
"blocklane": 1,
"color": "#f1c40f",
"iter": 2.3693732855813
}
},
"3236": {
"rotate": 1
},
"3247": {
"rotate": 1
},
"3259": {
"rotate": 1
},
"3267": {
"rotate": 1
},
"3277": {
"rotate": 1
},
"3282": {
"block": {
"blocklane": 1,
"color": "#e74c3c",
"iter": 2.387571768951
}
},
"3332": {
"rotate": 1
},
"3338": {
"rotate": -1
},
"3349": {
"rotate": -1
},
"3374": {
"rotate": -1
},
"3386": {
"block": {
"blocklane": 3,
"color": "#e74c3c",
"iter": 2.4063561189886
}
},
"3404": {
"rotate": -1
},
"3432": {
"rotate": 1
},
"3490": {
"block": {
"blocklane": 1,
"color": "#2ecc71",
"iter": 2.490726335694
}
},
"3575": {
"rotate": 1
},
"3586": {
"block": {
"blocklane": 3,
"color": "#f1c40f",
"iter": 2.5767265357308
}
},
"3655": {
"rotate": -1
},
"3682": {
"block": {
"blocklane": 2,
"color": "#2ecc71",
"iter": 2.5956259357686
}
},
"3732": {
"rotate": 1
},
"3744": {
"rotate": 1
},
"3778": {
"block": {
"blocklane": 5,
"color": "#f1c40f",
"iter": 2.6150245358074
}
},
"3858": {
"rotate": -1
},
"3874": {
"block": {
"blocklane": 3,
"color": "#2ecc71",
"iter": 2.6349223358472
}
},
"3912": {
"rotate": -1
},
"3928": {
"rotate": -1
},
"3939": {
"rotate": -1
},
"3954": {
"rotate": -1
},
"3970": {
"block": {
"blocklane": 5,
"color": "#e74c3c",
"iter": 2.655319335888
}
},
"4012": {
"rotate": 1
},
"4027": {
"rotate": 1
},
"4065": {
"block": {
"blocklane": 5,
"color": "#e74c3c",
"iter": 2.6915952942627
}
},
"4157": {
"block": {
"blocklane": 0,
"color": "#3498db",
"iter": 2.7328842693037
}
},
"4277": {
"block": {
"blocklane": 5,
"color": "#e74c3c",
"iter": 2.7108980193585
}
},
"4367": {
"block": {
"blocklane": 4,
"color": "#2ecc71",
"iter": 2.1469702069006
}
},
"4454": {
"block": {
"blocklane": 4,
"color": "#2ecc71",
"iter": 2.1937570444422
}
},
"4541": {
"block": {
"blocklane": 0,
"color": "#f1c40f",
"iter": 2.2149538694846
}
},
"4628": {
"block": {
"blocklane": 4,
"color": "#2ecc71",
"iter": 2.2365606820278
}
},
"4715": {
"block": {
"blocklane": 4,
"color": "#3498db",
"iter": 2.2585774820718
}
},
"4799": {
"block": {
"blocklane": 0,
"color": "#2ecc71",
"iter": 2.3114241071151
}
},
"4867": {
"rotate": -1
},
"4883": {
"block": {
"blocklane": 3,
"color": "#2ecc71",
"iter": 2.3334529321592
}
},
"4967": {
"block": {
"blocklane": 4,
"color": "#2ecc71",
"iter": 2.9900829321725
}
},
"5032": {
"rotate": 1
},
"5051": {
"block": {
"blocklane": 5,
"color": "#2ecc71",
"iter": 2.9900829321725
}
},
"5101": {
"rotate": -1
},
"5112": {
"rotate": -1
},
"5133": {
"block": {
"blocklane": 2,
"color": "#e74c3c",
"iter": 2.99
}
},
"5173": {
"rotate": 1
},
"5185": {
"rotate": 1
},
"5213": {
"block": {
"blocklane": 3,
"color": "#e74c3c",
"iter": 2.99
}
},
"5290": {
"block": {
"blocklane": 2,
"color": "#f1c40f",
"iter": 2.99
}
},
"5291": {
"rotate": 1
},
"5324": {
"rotate": -1
},
"5340": {
"rotate": 1
},
"5352": {
"rotate": 1
},
"5366": {
"rotate": 1
},
"5367": {
"block": {
"blocklane": 4,
"color": "#f1c40f",
"iter": 2.99
}
},
"5398": {
"rotate": 1
},
"5415": {
"rotate": 1
},
"5444": {
"block": {
"blocklane": 3,
"color": "#e74c3c",
"iter": 2.99
}
},
"5490": {
"rotate": 1
},
"5519": {
"block": {
"blocklane": 0,
"color": "#2ecc71",
"iter": 2.99
}
},
"5594": {
"block": {
"blocklane": 4,
"color": "#e74c3c",
"iter": 2.99
}
},
"5634": {
"rotate": 1
},
"5669": {
"block": {
"blocklane": 4,
"color": "#e74c3c",
"iter": 2.99
}
},
"5742": {
"block": {
"blocklane": 2,
"color": "#f1c40f",
"iter": 2.99
}
},
"5783": {
"block": {
"blocklane": 5,
"color": "#f1c40f",
"iter": 1.95
}
},
"5784": {
"rotate": -1
},
"5824": {
"block": {
"blocklane": 4,
"color": "#e74c3c",
"iter": 1.95
}
},
"5851": {
"rotate": -1
},
"5862": {
"rotate": -1
},
"5865": {
"block": {
"blocklane": 3,
"color": "#f1c40f",
"iter": 1.95
}
},
"5887": {
"rotate": -1
},
"5906": {
"block": {
"blocklane": 3,
"color": "#f1c40f",
"iter": 1.95
}
},
"5924": {
"rotate": -1
},
"5941": {
"rotate": -1
},
"5947": {
"block": {
"blocklane": 1,
"color": "#e74c3c",
"iter": 1.95
}
},
"5988": {
"block": {
"blocklane": 5,
"color": "#3498db",
"iter": 1.95
}
},
"6028": {
"block": {
"blocklane": 5,
"color": "#2ecc71",
"iter": 1.95
}
},
"6061": {
"rotate": -1
},
"6068": {
"block": {
"blocklane": 4,
"color": "#3498db",
"iter": 1.95
}
},
"6072": {
"rotate": -1
},
"6082": {
"rotate": -1
},
"6092": {
"rotate": -1
},
"6107": {
"block": {
"blocklane": 2,
"color": "#2ecc71",
"iter": 1.95
}
},
"6120": {
"rotate": 1
},
"6146": {
"block": {
"blocklane": 3,
"color": "#2ecc71",
"iter": 1.95
}
},
"6159": {
"rotate": 1
},
"6185": {
"block": {
"blocklane": 4,
"color": "#e74c3c",
"iter": 1.95
}
},
"6238": {
"rotate": 1
},
"6254": {
"block": {
"blocklane": 0,
"color": "#2ecc71",
"iter": 2.99
}
},
"6270": {
"rotate": 1
},
"6322": {
"block": {
"blocklane": 4,
"color": "#2ecc71",
"iter": 2.99
}
},
"6334": {
"rotate": -1
},
"6368": {
"rotate": -1
},
"6379": {
"rotate": -1
},
"6390": {
"block": {
"blocklane": 3,
"color": "#f1c40f",
"iter": 2.99
}
},
"6428": {
"rotate": -1
},
"6440": {
"rotate": -1
},
"6452": {
"rotate": -1
},
"6456": {
"block": {
"blocklane": 3,
"color": "#2ecc71",
"iter": 2.99
}
},
"6506": {
"rotate": 1
},
"6517": {
"rotate": 1
},
"6522": {
"block": {
"blocklane": 4,
"color": "#2ecc71",
"iter": 2.99
}
},
"6571": {
"rotate": 1
},
"6588": {
"block": {
"blocklane": 3,
"color": "#e74c3c",
"iter": 2.99
}
},
"6628": {
"rotate": 1
},
"6644": {
"rotate": 1
},
"6654": {
"block": {
"blocklane": 3,
"color": "#f1c40f",
"iter": 2.99
}
},
"6701": {
"rotate": 1
},
"6720": {
"block": {
"blocklane": 1,
"color": "#e74c3c",
"iter": 2.99
}
},
"6780": {
"rotate": -1
},
"6784": {
"block": {
"blocklane": 4,
"color": "#3498db",
"iter": 2.99
}
},
"6789": {
"rotate": -1
},
"6799": {
"rotate": -1
},
"6843": {
"rotate": 1
}
};

View file

@ -1,36 +1,3 @@
var textShown = false;
$(document).ready(function(){
scaleCanvas();
$('#startBtn').on('touchstart mousedown', function(){
if (importing == 1) {
init(1);
} else {
resumeGame();
}
setTimeout(function(){
if(settings.platform == "mobile"){
document.body.addEventListener('touchstart', function(e) {
handleClickTap(e.changedTouches[0].clientX);
}, false);
}
else {
document.body.addEventListener('mousedown', function(e) {
handleClickTap(e.clientX);
}, false);
}
}, 1);
});
document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
});
$(window).resize(scaleCanvas);
$(window).unload(function(){
if(gameState ==1 || gameState ==-1) localStorage.setItem("saveState", exportSaveState());
else localStorage.clear();
});
function scaleCanvas() {
canvas.width = $(window).width();
canvas.height = $(window).height();
@ -65,94 +32,10 @@ function scaleCanvas() {
}
}
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var trueCanvas = {width:canvas.width,height:canvas.height};
window.requestAnimFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
window.setTimeout(callback, 1000 / framerate);
};
})();
$('#clickToExit').bind('click', toggleDevTools);
function toggleDevTools() {
$('#devtools').toggle();
}
var settings;
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
settings = {
platform:"mobile",
startDist:227,
creationDt:40,
baseScale:1.4,
scale:1,
prevScale:1,
baseHexWidth:87,
hexWidth:87,
baseBlockHeight:20,
blockHeight:20,
rows:6,
speedModifier:0.7,
creationSpeedModifier:0.7,
comboTime:240
};
} else {
settings = {
platform:"nonmobile",
baseScale:1,
startDist:340,
creationDt:9,
scale:1,
prevScale:1,
hexWidth:65,
baseHexWidth:87,
baseBlockHeight:20,
blockHeight:15,
rows:8,
speedModifier:0.65,
creationSpeedModifier:0.55,
comboTime:240
};
$("#inst_main_body").html("The goal of Hextris is to stop blocks from leaving the inside of the outer gray hexagon<br><br>Either press the right and left arrow keys or tap the left and right sides of the screen to rotate the Hexagon<br><br>Clear blocks by making 3 or more blocks of the same color touch<br><br>Get points by clearing blocks<br><br>Time left before your combo streak disappears is indicated shown by <span style='color:#f1c40f;'>the</span> <span style='color:#e74c3c'>colored<span> <span style='color:#3498db'>lines</span> <span style='color:#2ecc71'>in</span> the outer hexagon<br><br>Pause by pressing <i class = 'fa fa-pause'></i> or the letter <b>p</b><br>Restart by pressing <i class = 'fa fa-refresh'></i> or <b>enter</b><br>Bring up this menu by pressing <i class = 'fa fa-info-circle'><br><br><a href = 'url'>Found a bug? Go here</a");
}
var framerate = 60;
var history = {};
var score = 0;
var isGameOver = 3;
var scoreAdditionCoeff = 1;
var prevScore = 0;
var numHighScores = 3;
var highscores = [0, 0, 0];
if(localStorage.getItem('highscores'))
highscores = localStorage.getItem('highscores').split(',').map(Number);
localStorage.setItem('highscores', highscores);
var blocks = [];
var MainHex;
var gdx = 0;
var gdy = 0;
var devMode = 0;
var lastGen;
var prevTimeScored;
var nextGen;
var spawnLane = 0;
var importing = 0;
var importedHistory;
var startTime;
var gameState;
setStartScreen();
function resumeGame() {
gameState = 1;
hideUIElements();
@ -189,6 +72,7 @@ function init(b) {
}, 7000);
clearSaveState();
}
hideUIElements();
var saveState = localStorage.getItem("saveState") || "{}";
saveState = JSONfn.parse(saveState);
@ -284,26 +168,6 @@ function addNewBlock(blocklane, color, iter, distFromHex, settled) { //last two
blocks.push(new Block(blocklane, color, iter, distFromHex, settled));
}
function importHistory(j) {
if (!j) {
try {
var ih = JSON.parse(prompt("Import JSON"));
if (ih) {
init(1);
importing = 1;
importedHistory = ih;
}
}
catch (e) {
alert("Error importing JSON");
}
} else {
init();
importing = 1;
importedHistory = j;
}
}
function exportHistory() {
$('#devtoolsText').html(JSON.stringify(history));
toggleDevTools();
@ -311,12 +175,17 @@ function exportHistory() {
function setStartScreen() {
$('#startBtn').show();
if (isStateSaved()) {
init();
if (isStateSaved()) {
importing = 0;
} else {
importHistory(introJSON);
importing = 1;
}
$('#pauseBtn').show();
$('#restartBtn').show();
$('#startBtn').show();
gameState = 0;
requestAnimFrame(animLoop);
}
@ -349,7 +218,7 @@ function animLoop() {
gameState = 2;
setTimeout(function(){
enableRestart();
}, 200)
}, 200);
canRestart = 0;
clearSaveState();
}
@ -431,11 +300,6 @@ function checkGameOver() {
return false;
}
window.onblur = function (e) {
if (gameState==1) {
pause();
}
};
function showHelp(){
if(gameState != 0){
pause(1);

View file

@ -1,6 +1,3 @@
op=0;
var saveState = localStorage.getItem("saveState") || "{}";
if(saveState !== "{}"){op=1;}
function render() {
var grey = '#bdc3c7';
if (gameState === 0) {

View file

@ -1,18 +1,7 @@
//remember to update history function to show the respective iter speeds
function update() {
var now = Date.now();
if (importing) {
if (importedHistory[MainHex.ct]) {
if (importedHistory[MainHex.ct].block) {
addNewBlock(importedHistory[MainHex.ct].block.blocklane, importedHistory[MainHex.ct].block.color, importedHistory[MainHex.ct].block.iter, importedHistory[MainHex.ct].block.distFromHex, importedHistory[MainHex.ct].block.settled);
}
if (importedHistory[MainHex.ct].rotate) {
MainHex.rotate(importedHistory[MainHex.ct].rotate);
}
}
}
else if (gameState == 1) {
if (gameState == 1) {
waveone.update();
if (now - waveone.prevTimeScored > 1000) {
waveone.prevTimeScored = now;

View file

@ -1,32 +1,3 @@
var colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"];
var hexColorsToTintedColors = {
"#e74c3c":"rgb(241,163,155)",
"#f1c40f":"rgb(246,223,133)",
"#3498db":"rgb(151,201,235)",
"#2ecc71":"rgb(150,227,183)"
};
//legacy support
var rgbToHex = {
"rgb(231,76,60)":"#e74c3c",
"rgb(241,196,15)":"#f1c40f",
"rgb(52,152,219)":"#3498db",
"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)",
"rgb(52,152,219)":"rgb(151,201,235)",
"rgb(46,204,113)":"rgb(150,227,183)"
};
var hexagonBackgroundColor = 'rgb(236, 240, 241)';
var hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)';
var centerBlue = 'rgb(44,62,80)'; //tumblr?
var angularVelocityConst = 4;
// t: current time, b: begInnIng value, c: change In value, d: duration
function easeOutCubic(t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
@ -46,8 +17,6 @@ function renderText(x, y, fontSize, color, text, font) {
ctx.restore();
}
scoreOpacity = 0;
var textOpacity=0;
function drawScoreboard() {
if (scoreOpacity < 1) {
scoreOpacity += 0.01;
@ -123,7 +92,6 @@ function toggleClass(element, active) {
}
}
var prevGameState;
function showText(text){
var messages = {
'paused':"<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectable centeredSubHeader'>Press p to resume</div>",
@ -206,5 +174,3 @@ function pause(o) {
gameState = -1;
}
}