hextris/js/input.js

142 lines
3.3 KiB
JavaScript
Raw Normal View History

var prevGameState;
2014-05-31 23:37:23 +00:00
function showText(text){
var messages = {
2014-06-01 01:45:25 +00:00
'paused':"<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectablecenteredSubHeader'>Press p to resume</div>",
2014-06-21 20:58:18 +00:00
'start':"<div class='centeredHeader unselectable' style='line-height:80px;' >Press enter to start</div>",
'gameover':"<div class='centeredHeader unselectable'> Game Over: "+score+" pts</div><br><div class='unselectablecenteredSubHeader'>Press enter to restart</div>",
2014-06-01 01:45:25 +00:00
};
2014-05-31 23:37:23 +00:00
var pt = document.getElementById("overlay");
pt.className = '';
pt.innerHTML = messages[text];
}
2014-05-31 23:37:23 +00:00
function hideText(text){
var pt = document.getElementById("overlay");
pt.className = 'faded';
pt.innerHTML = '';
}
2014-06-21 20:58:18 +00:00
function gameOverDisplay(){
var c = document.getElementById("canvas");
c.className = "blur";
showText('gameover');
}
function pause(x,o,message) {
message = 'paused';
var c = document.getElementById("canvas");
if (gameState == -1 ) {
2014-05-31 23:37:23 +00:00
hideText();
c.className = '';
setTimeout(function(){
2014-05-27 01:05:58 +00:00
gameState = prevGameState;
}, 300);
2014-05-31 15:13:40 +00:00
}
2014-06-22 17:25:20 +00:00
else if(gameState != -2 && gameState !== 0 && gameState !== 2) {
c.className = "blur";
2014-05-31 23:37:23 +00:00
showText(message);
prevGameState = gameState;
gameState = -1;
}
2014-05-31 15:13:40 +00:00
}
2014-05-27 01:05:58 +00:00
2014-05-17 16:41:54 +00:00
keypress.register_combo({
keys: "left",
on_keydown: function() {
if (MainClock) {
MainClock.rotate(1);
}
}
2014-05-17 16:41:54 +00:00
});
keypress.register_combo({
keys: "right",
on_keydown: function() {
if (MainClock){
MainClock.rotate(-1);
}
}
2014-05-17 16:41:54 +00:00
});
2014-05-17 22:34:02 +00:00
keypress.register_combo({
keys: "p",
2014-05-27 01:05:58 +00:00
on_keydown: function(){pause();}
});
2014-05-22 21:04:57 +00:00
keypress.register_combo({
keys: "q",
on_keydown: function() {
toggleDevTools();
}
});
2014-05-22 20:36:32 +00:00
keypress.register_combo({
keys: "e",
on_keydown: function() {
2014-05-22 21:04:57 +00:00
exportHistory();
2014-05-22 20:36:32 +00:00
}
});
keypress.register_combo({
keys: "i",
on_keydown: function() {
importHistory();
}
});
keypress.register_combo({
2014-05-31 14:22:42 +00:00
keys: "space",
on_keydown: function() {
spaceModifier = 2;
},
on_keyup: function() {
spaceModifier = 1;
}
});
2014-05-25 04:44:25 +00:00
keypress.register_combo({
keys: "enter",
on_keydown: function() {
if (gameState != -2 && gameState != -1) {
2014-05-26 01:49:03 +00:00
init();
}
}
2014-05-25 04:44:25 +00:00
});
$(document).ready(function(){
$("#pauseBtn").on('touchstart mousedown', function() {
pause();
if ($($("#pauseBtn").children()[0]).attr('class').indexOf('pause') == -1) {
$("#pauseBtn").html('<i class="fa fa-pause fa-2x"></i>');
} else {
$("#pauseBtn").html('<i class="fa fa-play fa-2x"></i>');
}
return false;
});
document.body.addEventListener('mousedown', function(e) {
handleClickTap(e.clientX);
}, false);
2014-05-22 20:36:32 +00:00
document.body.addEventListener('touchstart', function(e) {
handleClickTap(e.changedTouches[0].clientX);
}, false);
}, false);
function handleClickTap(x) {
if (x < window.innerWidth/2) {
if (gameState != 1 && gameState != -2 && gameState != -1 ){
2014-05-26 01:49:03 +00:00
init();
}
MainClock.rotate(1);
}
if (x > window.innerWidth/2) {
if (gameState != 1 && gameState != -2 && gameState != -1) {
2014-05-26 01:49:03 +00:00
init();
}
MainClock.rotate(-1);
}
}