Path: blob/main/public/games/files/hextris/js/initialization.js
1036 views
$(document).ready(function() {1initialize();2});3function initialize(a) {4window.rush = 1;5window.lastTime = Date.now();6window.iframHasLoaded = false;7window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"];8window.hexColorsToTintedColors = {9"#e74c3c": "rgb(241,163,155)",10"#f1c40f": "rgb(246,223,133)",11"#3498db": "rgb(151,201,235)",12"#2ecc71": "rgb(150,227,183)"13};1415window.rgbToHex = {16"rgb(231,76,60)": "#e74c3c",17"rgb(241,196,15)": "#f1c40f",18"rgb(52,152,219)": "#3498db",19"rgb(46,204,113)": "#2ecc71"20};2122window.rgbColorsToTintedColors = {23"rgb(231,76,60)": "rgb(241,163,155)",24"rgb(241,196,15)": "rgb(246,223,133)",25"rgb(52,152,219)": "rgb(151,201,235)",26"rgb(46,204,113)": "rgb(150,227,183)"27};2829window.hexagonBackgroundColor = 'rgb(236, 240, 241)';30window.hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)';31window.centerBlue = 'rgb(44,62,80)';32window.angularVelocityConst = 4;33window.scoreOpacity = 0;34window.textOpacity = 0;35window.prevGameState = undefined;36window.op = 0;37window.saveState = localStorage.getItem("saveState") || "{}";38if (saveState !== "{}") {39op = 1;40}4142window.textShown = false;43window.requestAnimFrame = (function() {44return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {45window.setTimeout(callback, 1000 / framerate);46};47})();48$('#clickToExit').bind('click', toggleDevTools);49window.settings;50if (/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {51$('.rrssb-email').remove();52settings = {53os: "other",54platform: "mobile",55startDist: 227,56creationDt: 60,57baseScale: 1.4,58scale: 1,59prevScale: 1,60baseHexWidth: 87,61hexWidth: 87,62baseBlockHeight: 20,63blockHeight: 20,64rows: 7,65speedModifier: 0.73,66speedUpKeyHeld: false,67creationSpeedModifier: 0.73,68comboTime: 31069};70} else {71settings = {72os: "other",73platform: "nonmobile",74baseScale: 1,75startDist: 340,76creationDt: 9,77scale: 1,78prevScale: 1,79hexWidth: 65,80baseHexWidth: 87,81baseBlockHeight: 20,82blockHeight: 15,83rows: 8,84speedModifier: 0.65,85speedUpKeyHeld: false,86creationSpeedModifier: 0.65,87comboTime: 31088};8990}91if(/Android/i.test(navigator.userAgent)) {92settings.os = "android";93}9495if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i)){96settings.os="ios";97}9899window.canvas = document.getElementById('canvas');100window.ctx = canvas.getContext('2d');101window.trueCanvas = {102width: canvas.width,103height: canvas.height104};105scaleCanvas();106107window.framerate = 60;108window.history = {};109window.score = 0;110window.scoreAdditionCoeff = 1;111window.prevScore = 0;112window.numHighScores = 3;113114highscores = [];115if (localStorage.getItem('highscores')) {116try {117highscores = JSON.parse(localStorage.getItem('highscores'));118} catch (e) {119highscores = [];120}121}122window.blocks = [];123window.MainHex;124window.gdx = 0;125window.gdy = 0;126window.devMode = 0;127window.lastGen = undefined;128window.prevTimeScored = undefined;129window.nextGen = undefined;130window.spawnLane = 0;131window.importing = 0;132window.importedHistory = undefined;133window.startTime = undefined;134window.gameState;135setStartScreen();136if (a != 1) {137window.canRestart = 1;138window.onblur = function(e) {139if (gameState == 1) {140pause();141}142};143$('#startBtn').off();144if (settings.platform == 'mobile') {145$('#startBtn').on('touchstart', startBtnHandler);146} else {147$('#startBtn').on('mousedown', startBtnHandler);148}149150document.addEventListener('touchmove', function(e) {151e.preventDefault();152}, false);153$(window).resize(scaleCanvas);154$(window).unload(function() {155156if (gameState == 1 || gameState == -1 || gameState === 0) localStorage.setItem("saveState", exportSaveState());157else localStorage.setItem("saveState", "{}");158});159160addKeyListeners();161(function(i, s, o, g, r, a, m) {162i['GoogleAnalyticsObject'] = r;163i[r] = i[r] || function() {164(i[r].q = i[r].q || []).push(arguments)165}, i[r].l = 1 * new Date();166a = s.createElement(o), m = s.getElementsByTagName(o)[0];167a.async = 1;168a.src = g;169m.parentNode.insertBefore(a, m)170})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');171ga('create', 'UA-51272720-1', 'teamsnowman.github.io');172ga('send', 'pageview');173174document.addEventListener("pause", handlePause, false);175document.addEventListener("backbutton", handlePause, false);176document.addEventListener("menubutton", handlePause, false); //menu button on android177178setTimeout(function() {179if (settings.platform == "mobile") {180try {181document.body.removeEventListener('touchstart', handleTapBefore, false);182} catch (e) {183184}185186try {187document.body.removeEventListener('touchstart', handleTap, false);188} catch (e) {189190}191192document.body.addEventListener('touchstart', handleTapBefore, false);193} else {194try {195document.body.removeEventListener('mousedown', handleClickBefore, false);196} catch (e) {197198}199200try {201document.body.removeEventListener('mousedown', handleClick, false);202} catch (e) {203204}205206document.body.addEventListener('mousedown', handleClickBefore, false);207}208}, 1);209}210}211212function startBtnHandler() {213setTimeout(function() {214if (settings.platform == "mobile") {215try {216document.body.removeEventListener('touchstart', handleTapBefore, false);217} catch (e) {218219}220221try {222document.body.removeEventListener('touchstart', handleTap, false);223} catch (e) {224225}226227document.body.addEventListener('touchstart', handleTap, false);228} else {229try {230document.body.removeEventListener('mousedown', handleClickBefore, false);231} catch (e) {232233}234235try {236document.body.removeEventListener('mousedown', handleClick, false);237} catch (e) {238239}240241document.body.addEventListener('mousedown', handleClick, false);242}243}, 5);244245if (!canRestart) return false;246247if ($('#openSideBar').is(':visible')) {248$('#openSideBar').fadeOut(150, "linear");249}250251if (importing == 1) {252init(1);253checkVisualElements(0);254} else {255resumeGame();256}257}258259function handlePause() {260if (gameState == 1 || gameState == 2) {261pause();262}263}264265function handleTap(e) {266handleClickTap(e.changedTouches[0].clientX, e.changedTouches[0].clientY);267}268269function handleClick(e) {270handleClickTap(e.clientX, e.clientY);271}272273function handleTapBefore(e) {274var x = e.changedTouches[0].clientX;275var y = e.changedTouches[0].clientY;276277if (x < 120 && y < 83 && $('.helpText').is(':visible')) {278showHelp();279return;280}281}282283function handleClickBefore(e) {284var x = e.clientX;285var y = e.clientY;286287if (x < 120 && y < 83 && $('.helpText').is(':visible')) {288showHelp();289return;290}291}292293294