2014-07-19 23:48:28 +00:00
$ ( document ) . ready ( function ( ) {
initialize ( ) ;
2014-07-22 13:06:52 +00:00
$ ( '#bottombar' ) . hide ( ) ;
2014-07-19 23:48:28 +00:00
} ) ;
2014-07-18 01:11:05 +00:00
2014-07-22 01:41:04 +00:00
function showbottombar ( ) {
2014-07-22 13:06:52 +00:00
var isOffline = 'onLine' in navigator && ! navigator . onLine ;
if ( isOffline ) {
setTimeout ( showbottombar , 1000 ) ;
} else {
window . iframeHasLoaded = true ;
2014-07-23 01:53:51 +00:00
if ( gameState != 1 ) {
2014-07-22 13:06:52 +00:00
$ ( '#bottombar' ) . fadeIn ( 150 , 'linear' ) ;
}
}
2014-07-22 01:41:04 +00:00
}
function hidebottombar ( ) {
2014-07-22 13:06:52 +00:00
$ ( '#bottombar' ) . fadeOut ( 150 , 'linear' ) ;
2014-07-22 01:41:04 +00:00
}
2014-07-19 21:36:43 +00:00
function initialize ( a ) {
2014-07-22 13:06:52 +00:00
window . iframHasLoaded = false ;
2014-07-18 01:11:05 +00:00
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)' ;
2014-07-24 15:16:53 +00:00
window . centerBlue = 'rgb(44,62,80)' ;
2014-07-18 01:11:05 +00:00
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 ,
2014-07-26 14:47:27 +00:00
speedModifier : 0.55 ,
creationSpeedModifier : 0.55 ,
2014-07-18 01:11:05 +00:00
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 ;
2014-07-24 15:16:53 +00:00
window . highscores = [ ] ;
2014-07-26 03:10:23 +00:00
debugger ;
2014-07-18 01:11:05 +00:00
if ( localStorage . getItem ( 'highscores' ) )
2014-07-25 04:33:54 +00:00
highscores = JSON . parse ( localStorage . getItem ( 'highscores' ) ) ;
2014-07-18 01:11:05 +00:00
2014-07-26 13:23:03 +00:00
writeHighScores ( ) ;
2014-07-18 01:11:05 +00:00
window . blocks = [ ] ;
window . MainHex ;
window . gdx = 0 ;
window . gdy = 0 ;
window . devMode = 0 ;
2014-07-19 21:36:43 +00:00
window . lastGen = undefined ;
window . prevTimeScored = undefined ;
window . nextGen = undefined ;
2014-07-18 01:11:05 +00:00
window . spawnLane = 0 ;
window . importing = 0 ;
2014-07-19 21:36:43 +00:00
window . importedHistory = undefined ;
window . startTime = undefined ;
2014-07-18 01:11:05 +00:00
window . gameState ;
setStartScreen ( ) ;
2014-07-19 22:03:16 +00:00
2014-07-19 21:36:43 +00:00
if ( a != 1 ) {
2014-07-19 22:51:35 +00:00
window . canRestart = 1 ;
2014-07-19 21:36:43 +00:00
window . onblur = function ( e ) {
if ( gameState == 1 ) {
pause ( ) ;
2014-07-18 01:11:05 +00:00
}
2014-07-19 21:36:43 +00:00
} ;
2014-07-19 22:06:14 +00:00
2014-07-19 22:03:16 +00:00
$ ( '#startBtn' ) . off ( ) ;
2014-07-20 02:03:22 +00:00
2014-07-22 13:21:16 +00:00
if ( settings . platform == 'mobile' ) {
$ ( '#startBtn' ) . on ( 'touchstart' , startBtnHandler ) ;
2014-07-24 02:00:46 +00:00
// $('.helpText').on('touchstart',function(){if (gameState != 2) showHelp});
2014-07-22 13:21:16 +00:00
} else {
$ ( '#startBtn' ) . on ( 'mousedown' , startBtnHandler ) ;
2014-07-24 02:00:46 +00:00
// $('.helpText').on('mousedown',function(){if (gameState != 2) showHelp});
2014-07-22 13:21:16 +00:00
}
2014-07-19 21:36:43 +00:00
document . addEventListener ( 'touchmove' , function ( e ) { e . preventDefault ( ) ; } , false ) ;
$ ( window ) . resize ( scaleCanvas ) ;
$ ( window ) . unload ( function ( ) {
2014-07-20 02:11:42 +00:00
if ( gameState == 1 || gameState == - 1 || gameState === 0 ) localStorage . setItem ( "saveState" , exportSaveState ( ) ) ;
2014-07-19 21:36:43 +00:00
else localStorage . clear ( ) ;
} ) ;
addKeyListeners ( ) ;
2014-07-20 02:03:22 +00:00
( 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' ) ;
2014-07-19 21:36:43 +00:00
ga ( 'create' , 'UA-51272720-1' , 'teamsnowman.github.io' ) ;
ga ( 'send' , 'pageview' ) ;
2014-07-19 23:48:28 +00:00
document . addEventListener ( "pause" , handlePause , false ) ;
document . addEventListener ( "backbutton" , handlePause , false ) ;
document . addEventListener ( "menubutton" , handlePause , false ) ; //menu button on android
2014-07-24 02:00:46 +00:00
setTimeout ( function ( ) {
if ( settings . platform == "mobile" ) {
try {
2014-07-24 02:29:35 +00:00
document . body . removeEventListener ( 'touchstart' , handleTapBefore , false ) ;
} catch ( e ) {
}
try {
2014-07-26 14:48:45 +00:00
document . body . removeEventListener ( 'touchstart' , handleTap , false ) ;
2014-07-24 02:00:46 +00:00
} catch ( e ) {
}
2014-07-26 14:48:45 +00:00
document . body . addEventListener ( 'touchstart' , handleTapBefore , false ) ;
2014-07-24 02:00:46 +00:00
}
else {
2014-07-24 02:29:35 +00:00
try {
document . body . removeEventListener ( 'mousedown' , handleClickBefore , false ) ;
} catch ( e ) {
}
2014-07-24 02:00:46 +00:00
try {
document . body . removeEventListener ( 'mousedown' , handleClick , false ) ;
} catch ( e ) {
}
2014-07-24 02:29:35 +00:00
document . body . addEventListener ( 'mousedown' , handleClickBefore , false ) ;
2014-07-24 02:00:46 +00:00
}
} , 1 ) ;
2014-07-19 23:48:28 +00:00
}
}
2014-07-22 13:21:16 +00:00
function startBtnHandler ( ) {
2014-07-24 02:29:35 +00:00
setTimeout ( function ( ) {
if ( settings . platform == "mobile" ) {
try {
document . body . removeEventListener ( 'touchstart' , handleTapBefore , false ) ;
} catch ( e ) {
}
try {
2014-07-26 14:48:45 +00:00
document . body . removeEventListener ( 'touchstart' , handleTap , false ) ;
2014-07-24 02:29:35 +00:00
} catch ( e ) {
}
document . body . addEventListener ( 'touchstart' , handleTap , false ) ;
}
else {
try {
document . body . removeEventListener ( 'mousedown' , handleClickBefore , false ) ;
} catch ( e ) {
}
try {
document . body . removeEventListener ( 'mousedown' , handleClick , false ) ;
} catch ( e ) {
}
2014-07-26 14:48:45 +00:00
document . body . addEventListener ( 'mousedown' , handleClick , false ) ;
2014-07-24 02:29:35 +00:00
}
2014-07-26 14:48:45 +00:00
} , 5 ) ;
2014-07-24 02:37:31 +00:00
2014-07-22 13:21:16 +00:00
if ( ! canRestart ) return false ;
if ( $ ( '#helpScreen' ) . is ( ':visible' ) ) {
$ ( '#helpScreen' ) . fadeOut ( 150 , "linear" ) ;
}
if ( importing == 1 ) {
init ( 1 ) ;
} else {
resumeGame ( ) ;
}
}
2014-07-19 23:48:28 +00:00
function handlePause ( ) {
if ( gameState == 1 || gameState == 2 ) {
2014-07-20 02:03:22 +00:00
pause ( ) ;
2014-07-19 21:36:43 +00:00
}
2014-07-19 22:03:16 +00:00
}
function handleTap ( e ) {
2014-07-24 02:00:46 +00:00
handleClickTap ( e . changedTouches [ 0 ] . clientX , e . changedTouches [ 0 ] . clientY ) ;
2014-07-19 22:03:16 +00:00
}
function handleClick ( e ) {
2014-07-24 02:00:46 +00:00
handleClickTap ( e . clientX , e . clientY ) ;
2014-07-19 23:12:28 +00:00
}
2014-07-24 02:29:35 +00:00
function handleTapBefore ( e ) {
var x = e . changedTouches [ 0 ] . clientX ;
var y = e . changedTouches [ 0 ] . clientY ;
if ( x < 120 && y < 50 && $ ( '.helpText' ) . is ( ':visible' ) ) {
showHelp ( ) ;
return ;
}
}
function handleClickBefore ( e ) {
var x = e . clientX ;
var y = e . clientY ;
if ( x < 120 && y < 50 && $ ( '.helpText' ) . is ( ':visible' ) ) {
showHelp ( ) ;
return ;
}
}