2014-08-23 02:10:55 +00:00
|
|
|
function addKeyListeners() {
|
2015-05-24 14:54:12 +00:00
|
|
|
keypress.register_combo({
|
|
|
|
keys: "left",
|
|
|
|
on_keydown: function() {
|
|
|
|
if (MainHex && gameState !== 0) {
|
|
|
|
MainHex.rotate(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
keypress.register_combo({
|
|
|
|
keys: "right",
|
|
|
|
on_keydown: function() {
|
|
|
|
if (MainHex && gameState !== 0){
|
|
|
|
MainHex.rotate(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
keypress.register_combo({
|
|
|
|
keys: "a",
|
|
|
|
on_keydown: function() {
|
|
|
|
if (MainHex && gameState !== 0) {
|
|
|
|
MainHex.rotate(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
keypress.register_combo({
|
|
|
|
keys: "d",
|
|
|
|
on_keydown: function() {
|
|
|
|
if (MainHex && gameState !== 0){
|
|
|
|
MainHex.rotate(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
keypress.register_combo({
|
|
|
|
keys: "p",
|
|
|
|
on_keydown: function(){pause();}
|
|
|
|
});
|
|
|
|
|
|
|
|
keypress.register_combo({
|
|
|
|
keys: "space",
|
|
|
|
on_keydown: function(){pause();}
|
|
|
|
});
|
|
|
|
|
|
|
|
keypress.register_combo({
|
|
|
|
keys: "q",
|
|
|
|
on_keydown: function() {
|
|
|
|
if (devMode) toggleDevTools();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
keypress.register_combo({
|
|
|
|
keys: "enter",
|
|
|
|
on_keydown: function() {
|
|
|
|
if (gameState==1 || importing == 1) {
|
|
|
|
init(1);
|
|
|
|
}
|
|
|
|
if (gameState == 2) {
|
|
|
|
init();
|
2015-08-27 01:34:09 +00:00
|
|
|
$("#gameoverscreen").fadeOut();
|
2015-05-24 14:54:12 +00:00
|
|
|
}
|
|
|
|
if (gameState===0) {
|
|
|
|
resumeGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-08-23 02:10:55 +00:00
|
|
|
|
|
|
|
$("#pauseBtn").on('touchstart mousedown', function() {
|
2015-05-24 16:39:27 +00:00
|
|
|
if (gameState != 1 && gameState != -1) {
|
2014-08-23 02:10:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-24 16:39:27 +00:00
|
|
|
if ($('#helpScreen').is(":visible")) {
|
|
|
|
$('#helpScreen').fadeOut(150, "linear");
|
2014-08-23 02:10:55 +00:00
|
|
|
}
|
|
|
|
pause();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#colorBlindBtn").on('touchstart mousedown', function() {
|
|
|
|
window.colors = ["#8e44ad", "#f1c40f", "#3498db", "#d35400"];
|
|
|
|
|
2015-05-24 14:54:12 +00:00
|
|
|
window.hexColorsToTintedColors = {
|
|
|
|
"#8e44ad": "rgb(229,152,102)",
|
|
|
|
"#f1c40f": "rgb(246,223,133)",
|
|
|
|
"#3498db": "rgb(151,201,235)",
|
|
|
|
"#d35400": "rgb(210,180,222)"
|
|
|
|
};
|
|
|
|
|
|
|
|
window.rgbToHex = {
|
|
|
|
"rgb(142,68,173)": "#8e44ad",
|
|
|
|
"rgb(241,196,15)": "#f1c40f",
|
|
|
|
"rgb(52,152,219)": "#3498db",
|
|
|
|
"rgb(211,84,0)": "#d35400"
|
|
|
|
};
|
|
|
|
|
|
|
|
window.rgbColorsToTintedColors = {
|
|
|
|
"rgb(142,68,173)": "rgb(229,152,102)",
|
|
|
|
"rgb(241,196,15)": "rgb(246,223,133)",
|
|
|
|
"rgb(52,152,219)": "rgb(151,201,235)",
|
|
|
|
"rgb(46,204,113)": "rgb(210,180,222)"
|
2014-08-23 02:10:55 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-05-24 14:54:12 +00:00
|
|
|
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
2015-08-27 01:57:52 +00:00
|
|
|
$("#restart").on('touchstart', function() {
|
2015-05-30 16:36:18 +00:00
|
|
|
init();
|
2015-05-30 00:23:17 +00:00
|
|
|
canRestart = false;
|
2015-06-03 19:45:16 +00:00
|
|
|
$("#gameoverscreen").fadeOut();
|
2015-05-30 00:23:17 +00:00
|
|
|
});
|
|
|
|
|
2015-05-24 14:54:12 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-05-30 00:23:17 +00:00
|
|
|
$("#restart").on('mousedown', function() {
|
2015-05-30 16:36:18 +00:00
|
|
|
init();
|
2015-05-30 00:23:17 +00:00
|
|
|
canRestart = false;
|
2015-05-30 16:36:18 +00:00
|
|
|
$("#gameoverscreen").fadeOut();
|
2015-05-30 00:23:17 +00:00
|
|
|
});
|
|
|
|
|
2015-05-24 14:54:12 +00:00
|
|
|
}
|
2015-08-27 03:35:53 +00:00
|
|
|
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
|
|
|
$("#restartBtn").on('touchstart', function() {
|
|
|
|
init(1);
|
|
|
|
canRestart = false;
|
|
|
|
$("#gameoverscreen").fadeOut();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2015-09-26 02:30:16 +00:00
|
|
|
else {
|
|
|
|
$("#restartBtn").on('mousedown', function() {
|
|
|
|
init(1);
|
|
|
|
canRestart = false;
|
|
|
|
$("#gameoverscreen").fadeOut();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-08-27 03:35:53 +00:00
|
|
|
|
2014-08-23 02:10:55 +00:00
|
|
|
}
|
2014-08-24 16:40:50 +00:00
|
|
|
function inside (point, vs) {
|
2015-05-24 14:54:12 +00:00
|
|
|
// ray-casting algorithm based on
|
|
|
|
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
|
|
|
|
|
|
var x = point[0], y = point[1];
|
|
|
|
|
|
|
|
var inside = false;
|
|
|
|
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
|
|
|
|
var xi = vs[i][0], yi = vs[i][1];
|
|
|
|
var xj = vs[j][0], yj = vs[j][1];
|
|
|
|
|
|
|
|
var intersect = ((yi > y) != (yj > y))
|
|
|
|
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
|
|
|
if (intersect) inside = !inside;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inside;
|
2014-08-24 16:40:50 +00:00
|
|
|
};
|
2014-08-23 02:10:55 +00:00
|
|
|
|
|
|
|
function handleClickTap(x,y) {
|
2015-05-26 14:52:15 +00:00
|
|
|
if (x < 120 && y < 83 && $('.helpText').is(':visible')) {
|
2015-05-24 14:54:12 +00:00
|
|
|
showHelp();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var radius = settings.hexWidth ;
|
|
|
|
var halfRadius = radius/2;
|
|
|
|
var triHeight = radius *(Math.sqrt(3)/2);
|
|
|
|
var Vertexes =[
|
|
|
|
[radius,0],
|
|
|
|
[halfRadius,-triHeight],
|
|
|
|
[-halfRadius,-triHeight],
|
|
|
|
[-radius,0],
|
|
|
|
[-halfRadius,triHeight],
|
|
|
|
[halfRadius,triHeight]];
|
|
|
|
Vertexes = Vertexes.map(function(coord){
|
|
|
|
return [coord[0] + trueCanvas.width/2, coord[1] + trueCanvas.height/2]});
|
2015-05-24 16:36:09 +00:00
|
|
|
|
2015-05-24 14:54:12 +00:00
|
|
|
if (!MainHex || gameState === 0 || gameState==-1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x < window.innerWidth/2) {
|
|
|
|
MainHex.rotate(1);
|
|
|
|
}
|
|
|
|
if (x > window.innerWidth/2) {
|
|
|
|
MainHex.rotate(-1);
|
|
|
|
}
|
2014-08-23 02:10:55 +00:00
|
|
|
}
|
2014-08-24 16:12:41 +00:00
|
|
|
|