Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/hextris/js/initialization.js
1036 views
1
$(document).ready(function() {
2
initialize();
3
});
4
function initialize(a) {
5
window.rush = 1;
6
window.lastTime = Date.now();
7
window.iframHasLoaded = false;
8
window.colors = ["#e74c3c", "#f1c40f", "#3498db", "#2ecc71"];
9
window.hexColorsToTintedColors = {
10
"#e74c3c": "rgb(241,163,155)",
11
"#f1c40f": "rgb(246,223,133)",
12
"#3498db": "rgb(151,201,235)",
13
"#2ecc71": "rgb(150,227,183)"
14
};
15
16
window.rgbToHex = {
17
"rgb(231,76,60)": "#e74c3c",
18
"rgb(241,196,15)": "#f1c40f",
19
"rgb(52,152,219)": "#3498db",
20
"rgb(46,204,113)": "#2ecc71"
21
};
22
23
window.rgbColorsToTintedColors = {
24
"rgb(231,76,60)": "rgb(241,163,155)",
25
"rgb(241,196,15)": "rgb(246,223,133)",
26
"rgb(52,152,219)": "rgb(151,201,235)",
27
"rgb(46,204,113)": "rgb(150,227,183)"
28
};
29
30
window.hexagonBackgroundColor = 'rgb(236, 240, 241)';
31
window.hexagonBackgroundColorClear = 'rgba(236, 240, 241, 0.5)';
32
window.centerBlue = 'rgb(44,62,80)';
33
window.angularVelocityConst = 4;
34
window.scoreOpacity = 0;
35
window.textOpacity = 0;
36
window.prevGameState = undefined;
37
window.op = 0;
38
window.saveState = localStorage.getItem("saveState") || "{}";
39
if (saveState !== "{}") {
40
op = 1;
41
}
42
43
window.textShown = false;
44
window.requestAnimFrame = (function() {
45
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
46
window.setTimeout(callback, 1000 / framerate);
47
};
48
})();
49
$('#clickToExit').bind('click', toggleDevTools);
50
window.settings;
51
if (/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
52
$('.rrssb-email').remove();
53
settings = {
54
os: "other",
55
platform: "mobile",
56
startDist: 227,
57
creationDt: 60,
58
baseScale: 1.4,
59
scale: 1,
60
prevScale: 1,
61
baseHexWidth: 87,
62
hexWidth: 87,
63
baseBlockHeight: 20,
64
blockHeight: 20,
65
rows: 7,
66
speedModifier: 0.73,
67
speedUpKeyHeld: false,
68
creationSpeedModifier: 0.73,
69
comboTime: 310
70
};
71
} else {
72
settings = {
73
os: "other",
74
platform: "nonmobile",
75
baseScale: 1,
76
startDist: 340,
77
creationDt: 9,
78
scale: 1,
79
prevScale: 1,
80
hexWidth: 65,
81
baseHexWidth: 87,
82
baseBlockHeight: 20,
83
blockHeight: 15,
84
rows: 8,
85
speedModifier: 0.65,
86
speedUpKeyHeld: false,
87
creationSpeedModifier: 0.65,
88
comboTime: 310
89
};
90
91
}
92
if(/Android/i.test(navigator.userAgent)) {
93
settings.os = "android";
94
}
95
96
if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i)){
97
settings.os="ios";
98
}
99
100
window.canvas = document.getElementById('canvas');
101
window.ctx = canvas.getContext('2d');
102
window.trueCanvas = {
103
width: canvas.width,
104
height: canvas.height
105
};
106
scaleCanvas();
107
108
window.framerate = 60;
109
window.history = {};
110
window.score = 0;
111
window.scoreAdditionCoeff = 1;
112
window.prevScore = 0;
113
window.numHighScores = 3;
114
115
highscores = [];
116
if (localStorage.getItem('highscores')) {
117
try {
118
highscores = JSON.parse(localStorage.getItem('highscores'));
119
} catch (e) {
120
highscores = [];
121
}
122
}
123
window.blocks = [];
124
window.MainHex;
125
window.gdx = 0;
126
window.gdy = 0;
127
window.devMode = 0;
128
window.lastGen = undefined;
129
window.prevTimeScored = undefined;
130
window.nextGen = undefined;
131
window.spawnLane = 0;
132
window.importing = 0;
133
window.importedHistory = undefined;
134
window.startTime = undefined;
135
window.gameState;
136
setStartScreen();
137
if (a != 1) {
138
window.canRestart = 1;
139
window.onblur = function(e) {
140
if (gameState == 1) {
141
pause();
142
}
143
};
144
$('#startBtn').off();
145
if (settings.platform == 'mobile') {
146
$('#startBtn').on('touchstart', startBtnHandler);
147
} else {
148
$('#startBtn').on('mousedown', startBtnHandler);
149
}
150
151
document.addEventListener('touchmove', function(e) {
152
e.preventDefault();
153
}, false);
154
$(window).resize(scaleCanvas);
155
$(window).unload(function() {
156
157
if (gameState == 1 || gameState == -1 || gameState === 0) localStorage.setItem("saveState", exportSaveState());
158
else localStorage.setItem("saveState", "{}");
159
});
160
161
addKeyListeners();
162
(function(i, s, o, g, r, a, m) {
163
i['GoogleAnalyticsObject'] = r;
164
i[r] = i[r] || function() {
165
(i[r].q = i[r].q || []).push(arguments)
166
}, i[r].l = 1 * new Date();
167
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
168
a.async = 1;
169
a.src = g;
170
m.parentNode.insertBefore(a, m)
171
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
172
ga('create', 'UA-51272720-1', 'teamsnowman.github.io');
173
ga('send', 'pageview');
174
175
document.addEventListener("pause", handlePause, false);
176
document.addEventListener("backbutton", handlePause, false);
177
document.addEventListener("menubutton", handlePause, false); //menu button on android
178
179
setTimeout(function() {
180
if (settings.platform == "mobile") {
181
try {
182
document.body.removeEventListener('touchstart', handleTapBefore, false);
183
} catch (e) {
184
185
}
186
187
try {
188
document.body.removeEventListener('touchstart', handleTap, false);
189
} catch (e) {
190
191
}
192
193
document.body.addEventListener('touchstart', handleTapBefore, false);
194
} else {
195
try {
196
document.body.removeEventListener('mousedown', handleClickBefore, false);
197
} catch (e) {
198
199
}
200
201
try {
202
document.body.removeEventListener('mousedown', handleClick, false);
203
} catch (e) {
204
205
}
206
207
document.body.addEventListener('mousedown', handleClickBefore, false);
208
}
209
}, 1);
210
}
211
}
212
213
function startBtnHandler() {
214
setTimeout(function() {
215
if (settings.platform == "mobile") {
216
try {
217
document.body.removeEventListener('touchstart', handleTapBefore, false);
218
} catch (e) {
219
220
}
221
222
try {
223
document.body.removeEventListener('touchstart', handleTap, false);
224
} catch (e) {
225
226
}
227
228
document.body.addEventListener('touchstart', handleTap, false);
229
} else {
230
try {
231
document.body.removeEventListener('mousedown', handleClickBefore, false);
232
} catch (e) {
233
234
}
235
236
try {
237
document.body.removeEventListener('mousedown', handleClick, false);
238
} catch (e) {
239
240
}
241
242
document.body.addEventListener('mousedown', handleClick, false);
243
}
244
}, 5);
245
246
if (!canRestart) return false;
247
248
if ($('#openSideBar').is(':visible')) {
249
$('#openSideBar').fadeOut(150, "linear");
250
}
251
252
if (importing == 1) {
253
init(1);
254
checkVisualElements(0);
255
} else {
256
resumeGame();
257
}
258
}
259
260
function handlePause() {
261
if (gameState == 1 || gameState == 2) {
262
pause();
263
}
264
}
265
266
function handleTap(e) {
267
handleClickTap(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
268
}
269
270
function handleClick(e) {
271
handleClickTap(e.clientX, e.clientY);
272
}
273
274
function handleTapBefore(e) {
275
var x = e.changedTouches[0].clientX;
276
var y = e.changedTouches[0].clientY;
277
278
if (x < 120 && y < 83 && $('.helpText').is(':visible')) {
279
showHelp();
280
return;
281
}
282
}
283
284
function handleClickBefore(e) {
285
var x = e.clientX;
286
var y = e.clientY;
287
288
if (x < 120 && y < 83 && $('.helpText').is(':visible')) {
289
showHelp();
290
return;
291
}
292
}
293
294