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);
});
});
$(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();
if (canvas.height > canvas.width) {
settings.scale = (canvas.width/800) * settings.baseScale;
} else {
settings.scale = (canvas.height/800) * settings.baseScale;
}
trueCanvas = {
width:canvas.width,
height:canvas.height
};
if (window.devicePixelRatio) {
//from https://gist.github.com/joubertnel/870190
var cw = $("#canvas").attr('width');
var ch = $("#canvas").attr('height');
$("#canvas").attr('width', cw * window.devicePixelRatio);
$("#canvas").attr('height', ch * window.devicePixelRatio);
$("#canvas").css('width', cw);
$("#canvas").css('height', ch);
trueCanvas = {
width:cw,
height:ch
};
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
}
}
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var count = 0;
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
Either press the right and left arrow keys or tap the left and right sides of the screen to rotate the Hexagon
Clear blocks by making 3 or more blocks of the same color touch
Get points by clearing blocks
Time left before your combo streak disappears is indicated shown by the colored lines in the outer hexagon
Pause by pressing or the letter p
Restart by pressing or enter
Bring up this menu by pressing
Found a bug? Go heresettings.rows){
return true;
}
}
return false;
}
function checkGameOver() {
for (var i = 0; i < MainHex.sides; i++) {
if (isInfringing(MainHex)) {
updateHighScore();
gameOverDisplay();
return true;
}
}
return false;
}
window.onblur = function (e) {
if (gameState==1) {
pause();
}
};
function showHelp(){
if(gameState != 0){
pause(1);
}
$('#helpScreen').fadeToggle(150, "linear");
}