-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·550 lines (455 loc) · 19.6 KB
/
Copy pathindex.html
File metadata and controls
executable file
·550 lines (455 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<link href="style.css" rel="stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript" src="http://www.datejs.com/build/date.js"></script>
<!--<link rel="stylesheet" href="http://www.jacklmoore.com/colorbox/example1/colorbox.css" />-->
<link href="colorbox.css" rel="stylesheet" />
<script src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js"></script>
</head>
<body>
<div style="display:none;">
<div id="inline" class="popupBox">
<div class="start-info">
<div class="align-center">
<h1 class="blink">MICHIGAN IS IN TROUBLE!</h1>
<span>Flaming oil wells and contaminated sites abound.</span><br />
<p>
Help put out fires and clean up contaminated sites across the state.
You only have 15 seconds to click as many icons as possible and
advance to the next level. Avoid the veterans and police patrols!
</p>
</div>
<div id="images">
<div>
<img src="images/oil.png" class="popupImage" /><span class="popupText orange">OIL AND GAS WELLS: + 1 point</span>
</div>
<div>
<img src="images/toxic.png" class="popupImage" /><span class="popupText green">CONTAMINATED SITES: + 5 points</span>
</div>
<div>
<img src="images/vet.png" class="popupImage" /><span class="popupText blue">COUNTY VETERAN POP.: - 1 point</span>
</div>
<div>
<img src="images/police.png" class="popupImage" /><span class="popupText yellow">POLICE POST: Lose all points!</span>
</div>
</div>
</div>
<div class="start-buttons">
<div class="easy"> </div>
<div class="tough"> </div>
<div class="crazy"> </div>
</div>
</div>
<div id="diff" class="popupBox difficulty">
KENT
</div>
<div id="endGameLose" class="popupBox">
<h3 class="blink">GAME OVER: YOU LOST</h3>
<b>Final Score: </b><span class='finalScore'></span><br />
<span class="start">Play again</span>
</div>
<div id="endGameWin" class="popupBox">
<h3 class="blink-success">CONGRATULATIONS: YOU WON</h3>
<b>Final Score: </b><span class='finalScore'></span><br />
<span class="start">Play again</span>
</div>
</div>
<header class="align-center">
<b>Lvl <span id="spnLvl">0</span>
Score <span id="spnScore">0</span>
High Score <span id="spnHighScore">0</span></b>
<a class='inline' href="#inline" style="display:none;">Help</a>
<a class='endGameWin' href="#endGameWin" style="display:none;">Help</a>
<a class='endGameLose' href="#endGameLose" style="display:none;">Help</a>
<a class='difficulty' href="#difficulty" style="display:none;">difficulty</a>
</header>
<div id="notification-box"></div>
<div class="map-container">
<div id="map-canvas"></div>
</div>
<div id="info" style="display:none;"></div>
<footer>
Developed by Gravity Works <img id="gravWorks" src="images/smallgear.png" style="width: 20px; height: auto; vertical-align: middle" />
</footer>
</body>
<script>
var contaminantImage = 'images/toxic.png';
var oilImage = 'images/oil.png';
var vetImage = 'images/vet.png';
var policeImage = 'images/police.png';
$('#comtaminated').attr("src", contaminantImage);
$('#oil').attr("src", oilImage);
$('#veteran').attr("src", vetImage);
$('#police').attr("src", policeImage);
var markers = [];
var map;
var m_vetInterval = 0;
/* data sets */
var contaminant = [];
var oil = [];
var police = [];
var vet = [];
var contaminantLoaded = false;
var oilLoaded = false;
var policeLoaded = false;
var vetLoaded = false;
var m_contaminantInterval = 0;
var m_oilInterval = 0;
var m_policeInterval = 0;
var m_vetInterval = 0;
var m_gameLoopInterval = 0;
var m_contaminantSpeed = 1000;
var m_oilSpeed = 1000;
var m_policeSpeed = 3000;
var m_vetSpeed = 4000;
var fadeOutTime = 3000;
var difficulty = 1;
var m_contaminantDuration = 1000;
var m_oilDuration = 1000;
var m_policeDuration = 2000;
var m_vetDuration = 1000;
var m_vetSoundDuration = 30000;
var speedIncriment = .09;
var levelDuration = 15000; // level duration
var levelScore = 10;
var levelIncrease = 13;
var currLevel = 1;
var whatWasClicked = [];
var m_clickCount = 0;
var m_coin = document.createElement('audio');
var m_fireSound = document.createElement('audio');
var m_policeSound = document.createElement('audio');
var m_background = document.createElement('audio');
var m_levelUpSound = document.createElement('audio');
var m_gameOverSound = document.createElement('audio');
var m_endTime = new Date();
/* load datasets */
loadContaminant();
loadOil();
loadVets();
loadPolice();
$(window).load(function () {
var landingHeight = $("#inline").outerHeight();
var loseHeight = $("#endGameLose").outerHeight();
var winHeight = $("#endGameWin").outerHeight();
$(".inline").colorbox({ inline: true, width: "95%", innerHeight: landingHeight });
$(".endGameLose").colorbox({ inline: true, width: "95%", innerHeight: loseHeight });
$(".endGameWin").colorbox({ inline: true, width: "95%", innerHeight: winHeight });
$(".inline").click(); // initial lightbox
$('#cboxClose').remove();
if ('safari' in window && 'pushNotification' in window.safari) {
var permissionData = window.safari.pushNotification.permission('web.gravityworks.miforce');
checkRemotePermission(permissionData);
}
$(".easy").click(function () {
startGame(1);
positionNotifications();
});
$(".tough").click(function () {
startGame(2);
positionNotifications();
});
$(".crazy").click(function () {
startGame(3);
positionNotifications();
});
$(".start").click(function () {
startGame(difficulty);
positionNotifications();
});
loadSounds();
//onclick e.e.
$("#gravWorks").click(function () {
var canvasImage = $('#map-canvas img');
var canvasImagePosition = canvasImage.offset();
$("body").prepend("<img id='gravWorksLocation' src='images/smallgear.png' />");
$("#notification-box").append("<p id='gravWorksAddress'>1132 N. Washington Lansing, MI</p>");
$("#gravWorksLocation").css({
"left": (canvasImagePosition.left + 225) + "px",
"top": (canvasImagePosition.top + 325) + "px",
"z-index": 2000
});
$("#gravWorksAddress, #gravWorksLocation").delay(4000).fadeOut("slow");
});
});
var checkRemotePermission = function (permissionData) {
if (permissionData.permission === 'default') {
// This is a new web service URL and its validity is unknown.
window.safari.pushNotification.requestPermission(
'https://miforce.net/webservice', // The web service URL.
'web.gravityworks.miforce', // The Website Push ID.
{}, // Data that you choose to send to your server to help you identify the user.
checkRemotePermission // The callback function.
);
}
else if (permissionData.permission === 'denied') {
// The user said no.
}
else if (permissionData.permission === 'granted') {
// The web service URL is a valid push provider, and the user said yes.
// permissionData.deviceToken is now available to use.
}
};
function initialize() {
var styles = [
{
"stylers": [
{ "color": "#000000" }
]
}, {
"featureType": "water",
"stylers": [
{ "weight": 0.1 },
{ "color": "#00e7ff" }
]
}, {
"featureType": "water",
"stylers": [
{ "color": "#5ffff0" }
]
}, {
}
];
var styledMap = new google.maps.StyledMapType(styles, { name: "Styled Map" });
var mapOptions = {
zoom: 6,
scrollwheel: false,
panControl: false,
draggable: false,
disableDefaultUI: true,
disableDoubleClickZoom: true,
center: new google.maps.LatLng(44.130821, -85.749512),
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
}
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
var imageBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(41.31082388091818, -89.87939453125),
new google.maps.LatLng(47.08508535995383, -82.001953125));
styleOverlay = new google.maps.GroundOverlay('images/back.png', imageBounds);
styleOverlay.setMap(map);
google.maps.event.addListener(map, 'click', function () {
m_clickCount = m_clickCount + 1;
});
}
function positionNotifications() {
var canvasImage = $('#map-canvas img');
var canvasImagePosition = canvasImage.offset();
$("#notification-box").css({
"left": (canvasImagePosition.left + 20) + "px",
"top": (canvasImagePosition.top + 160) + "px"
});
}
function deleteMarker() {
markers[0].setMap(null);
}
function buildMapPoint(latitude, longitude, title, scoreValue, imagePath, timeToKeepOnScreen, sound) {
latLng = new google.maps.LatLng(latitude, longitude);
var image = new google.maps.MarkerImage(imagePath,
new google.maps.Size(43.0, 48.0),
new google.maps.Point(0, 0),
new google.maps.Point(21.0, 24.0)
);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: image,
title: title
});
markers.push(marker);
(function (marker, location) {
setInterval(function () { marker.setMap(null); }, timeToKeepOnScreen);
// Attaching a click event to the current marker
google.maps.event.addListener(marker, "click", function (e) {
$(".notification").fadeOut("slow");
var score = parseInt(jQuery("#spnScore").text());
sound.play();
score = score + scoreValue;
jQuery("#spnScore").text(score);
var highScore = jQuery("#spnHighScore").text();
if (highScore < score) {
jQuery("#spnHighScore").text(score);
}
var title = marker.getTitle();
$("#notification-box").show();
$("#notification-box").html("<p class='notification'>" + title + "</p>");
$("#notification-box").fadeOut(fadeOutTime);
marker.setMap(null);
whatWasClicked.push(marker.icon);
});
})(marker, location);
}
function endGame() {
clearIntervals();
clearInterval(m_gameLoopInterval);
currLevel = 1;
jQuery("#spnLvl").text("1");
$("#notification-box").empty();
$(".finalScore").text(jQuery("#spnScore").text());
var finalScore = jQuery("#spnScore").text();
var highScore = jQuery("#spnHighScore").text();
if (highScore == "0" || finalScore > highScore) {
$("#spnHighScore").text(finalScore);
}
m_background.pause();
m_background.currentTime = 0;
m_gameOverSound.play();
}
function gameLoop() {
if (currLevel >= 10) {
endGame();
$(".endGameWin").click();
$('#cboxClose').remove();
}
var currScore = parseInt(jQuery("#spnScore").text());
if (currScore > levelScore) {
m_contaminantSpeed = m_contaminantSpeed - (m_contaminantSpeed * speedIncriment);
m_oilSpeed = m_oilSpeed - (m_oilSpeed * speedIncriment);
m_policeSpeed = m_policeSpeed - (m_policeSpeed * speedIncriment);
m_vetSpeed = m_vetSpeed - (m_vetSpeed * speedIncriment);
m_contaminantDuration = m_contaminantDuration - (m_contaminantDuration * speedIncriment);
m_oilDuration = m_oilDuration - (m_oilDuration * speedIncriment);
m_policeDuration = m_policeDuration - (m_policeDuration * speedIncriment);
m_vetDuration = m_vetDuration - (m_vetDuration * speedIncriment);
updateLevelSpeed();
jQuery("#spnLvl").text(currLevel++);
levelScore = levelScore + levelIncrease;
} else {
// end game
endGame();
$(".endGameLose").click();
$('#cboxClose').remove();
}
}
function loadContaminant() {
jQuery.ajax({
type: "Get",
url: "http://opendata.socrata.com/resource/2brv-dhpz.json?",
dataType: "json",
success: function (json) {
contaminant = json;
contaminantLoaded = true;
}
});
}
function randomContaminant() {
var random = Math.floor(Math.random() * ((contaminant.length - 1) - 0 + 1)) + 0;
var rootItem = contaminant[random];
var location = rootItem.location_1;
var titleString = "Great Job! You helped eliminate " + rootItem.pollutants + " at " + rootItem.name;
$("#info").append("<span>" + rootItem.county + " - Michigan is contaminated at " + rootItem.name + " " + rootItem.score + "</span>");
// build the generic map point
buildMapPoint(location.latitude, location.longitude, titleString, 5, contaminantImage, m_contaminantDuration, m_fireSound);
}
function loadOil() {
jQuery.ajax({
type: "Get",
url: "http://opendata.socrata.com/resource/ixt6-qcyf.json",
dataType: "json",
success: function (json) {
oil = json;
oilLoaded = true;
}
});
}
function randomOil() {
var random = Math.floor(Math.random() * ((oil.length - 1) - 0 + 1)) + 0;
var rootItem = oil[random];
var location = rootItem.wellhole_top;
var titleString = "Great Job! You put out an oil fire at " + rootItem.coname + " in " + rootItem.county + " county";
// build the generic map point
buildMapPoint(location.latitude, location.longitude, titleString, 1, oilImage, m_oilDuration, m_coin);
}
function loadVets() {
m_loadVets = true;
jQuery.ajax({
type: "Get",
url: "http://opendata.socrata.com/resource/sh9h-hasz.json",
dataType: "json",
success: function (json) {
vet = json;
vetLoaded = true;
}
});
}
function randomVet() {
var random = Math.floor(Math.random() * ((vet.length - 1) - 0 + 1)) + 0;
var rootItem = vet[random];
var location = rootItem.location_1;
var titleString = "Oh no, you got in the way of a vet trying to put out a fire in "
+ rootItem.county + " county";
// build the generic map point
buildMapPoint(location.latitude, location.longitude, titleString, -1, vetImage, m_vetDuration, m_coin);
}
function loadPolice() {
jQuery.ajax({
type: "Get",
url: "http://opendata.socrata.com/resource/b877-bq25.json",
dataType: "json",
success: function (json) {
police = json;
policeLoaded = true;
}
});
}
function randomPolice() {
for (var i = 0; i < difficulty; i++) {
var random = Math.floor(Math.random() * ((police.length - 1) - 0 + 1)) + 0;
var rootItem = police[random];
var location = rootItem.location_1;
var titleString = "Oh, no! You distracted a police offer en route from " + rootItem.id;
// build the generic map point
var totalPoints = parseInt(jQuery("#spnScore").text()) * -1;
buildMapPoint(location.latitude, location.longitude, titleString, totalPoints, policeImage, m_policeDuration, m_policeSound);
}
}
function loadSounds() {
m_levelUpSound.setAttribute('src', 'sounds/levelup.wav');
m_gameOverSound.setAttribute('src', 'sounds/gameover.wav');
m_policeSound.setAttribute('src', 'sounds/police.wav');
m_fireSound.setAttribute('src', 'sounds/toxic.wav');
m_coin.setAttribute('src', 'sounds/coin.wav');
m_background.setAttribute('src', 'sounds/back.wav');
m_background.setAttribute('loop', 'loop');
}
function startGame(d) {
parent.$.fn.colorbox.close();
m_endTime = new Date(new Date().getTime() + (2 * 60000));
difficulty = parseInt(d);
var gameInterval = setInterval(function () {
if (contaminantLoaded && oilLoaded && vetLoaded && policeLoaded) {
clearInterval(gameInterval);
updateLevelSpeed(); // update the speed of icon sets
m_gameLoopInterval = setInterval(gameLoop, levelDuration); // increase level - increase speed by 10%
m_background.play();
jQuery("#spnScore").text("0");
jQuery("#status").text("");
}
}, 100);
}
function updateLevelSpeed() {
m_levelUpSound.play();
clearIntervals();
m_contaminantInterval = setInterval(randomContaminant, m_contaminantSpeed);
m_oilInterval = setInterval(randomOil, m_oilSpeed);
m_vetInterval = setInterval(randomVet, m_vetSpeed);
m_policeInterval = setInterval(randomPolice, m_policeSpeed);
}
function clearIntervals() {
clearInterval(m_contaminantInterval);
clearInterval(m_oilInterval);
clearInterval(m_vetInterval);
clearInterval(m_policeInterval);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</html>