-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameunits.js
230 lines (208 loc) · 8.7 KB
/
gameunits.js
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
function initProgressBar(init_dist) {
if ($('status') != undefined) {
$('status').dispose();
}
if ($('progress_bar') != undefined) {
$('progress_bar').dispose();
}
window.initialDistance = init_dist;
// Make a table with 31 cells: the first 5 are when you go negative, the 6th is 0, the rest for progress towards the goal
$('status_bar').grab(new Element('table', {
id: 'progress_bar',
style: 'border-collapse:collapse;border-width: 1px; border-color:#000000; border-style: solid; position: relative; width:80%; height:40%; top:10px; left:10%;',
border: "0",
html: "<tr><td></td><td></td><td></td><td></td><td></td><td id='pl_first_cell'>0</td>"+
"<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>"+
"</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>"+
"<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>"+
"</td><td id='pl_last_cell'>"+init_dist.toFixed(0)+"</td></tr>"
}));
$('pl_first_cell').setStyle('border','1px solid black');
$('pl_first_cell').setStyle('width','30px');
$('pl_first_cell').setStyle('backgroundColor','yellow');
$('pl_last_cell').setStyle('border','1px solid black');
$('pl_last_cell').setStyle('width','60px');
if (window.gamemode == 'MultiPlayer') {
// Init opponent bar too
if ($('opp_progress_bar') != undefined) {
$('opp_progress_bar').dispose();
}
window.initialDistance = init_dist;
// Make a table with 31 cells: the first 5 are when you go negative, the 6th is 0, the rest for progress towards the goal
$('status_bar').grab(new Element('table', {
id: 'opp_progress_bar',
style: 'border-collapse:collapse;border-width: 1px; border-color:#000000; border-style: solid; position: relative; width:80%; height:40%; top:18px; left:10%;',
border: "0",
html: "<tr><td></td><td></td><td></td><td></td><td></td><td id='opp_first_cell'>0</td>"+
"<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>"+
"</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>"+
"<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>"+
"</td><td id='opp_last_cell'>"+init_dist.toFixed(0)+"</td></tr>"
}));
$('opp_first_cell').setStyle('border','1px solid black');
$('opp_first_cell').setStyle('width','30px');
$('opp_first_cell').setStyle('backgroundColor','yellow');
$('opp_last_cell').setStyle('border','1px solid black');
$('opp_last_cell').setStyle('width','60px');
}
}
function updateProgressBar(dist) {
var table_cells = $('progress_bar').getElements('td');
if (dist > window.initialDistance) {
// indicate your progress
table_cells[4].setStyle('backgroundColor','red');
// Negative progress
var no_blocks = Math.min(Math.round(10.0*(dist - window.initialDistance)/window.initialDistance),4);
for (var i=3;i>=0;i--) {
if (i>=(4-no_blocks)) {
table_cells[i].setStyle('backgroundColor','red');
} else {
table_cells[i].setStyle('backgroundColor','white');
}
}
for (var i=6;i<=30;i++) {
table_cells[i].setStyle('backgroundColor','white');
}
} else {
// positive progress
table_cells[6].setStyle('backgroundColor','green');
var no_blocks = Math.round(24.0*(1-(dist/window.initialDistance)));
for (var i=7;i<=30;i++) {
if (i<no_blocks+7) {
table_cells[i].setStyle('backgroundColor','green');
} else {
table_cells[i].setStyle('backgroundColor','white');
}
}
for (var i=4;i>=0;i--) {
table_cells[i].setStyle('backgroundColor','white');
}
}
}
function updateOpponentProgressBar(dist) {
var table_cells = $('opp_progress_bar').getElements('td');
if (dist > window.initialDistance) {
// indicate your progress
table_cells[4].setStyle('backgroundColor','red');
// Negative progress
var no_blocks = Math.min(Math.round(10.0*(dist - window.initialDistance)/window.initialDistance),4);
for (var i=3;i>=0;i--) {
if (i>=(4-no_blocks)) {
table_cells[i].setStyle('backgroundColor','red');
} else {
table_cells[i].setStyle('backgroundColor','white');
}
}
for (var i=6;i<=30;i++) {
table_cells[i].setStyle('backgroundColor','white');
}
} else {
// positive progress
table_cells[6].setStyle('backgroundColor','green');
var no_blocks = Math.round(24.0*(1-(dist/window.initialDistance)));
for (var i=7;i<=30;i++) {
if (i<no_blocks+7) {
table_cells[i].setStyle('backgroundColor','green');
} else {
table_cells[i].setStyle('backgroundColor','white');
}
}
for (var i=4;i>=0;i--) {
table_cells[i].setStyle('backgroundColor','white');
}
}
}
function updateHeatOMeter(dist) {
if (dist < window.previousDistance) {
$('heatometer').set('html', 'Warmer!');
$('heat_box').highlight('#f88', '#fff');
} else {
$('heatometer').set('html', 'Colder!');
$('heat_box').highlight('#88f', '#fff');
}
}
function updateSpeedOMeter(currentLocation) {
// Calculate Speed
var diff = google.maps.geometry.spherical.computeDistanceBetween(
currentLocation, window.previousLocation);
var time = new Date().getTime() / 1000;
var timePassed = (time - window.previousTime);
window.speeds.push((diff / 1000) / (timePassed / 3600));
if (speeds.length > 6) {
speeds.shift();
}
var total = 0;
for (var i = 0; i < window.speeds.length; i++) {
total += window.speeds[i];
}
total = total / window.speeds.length;
$('speedometer').set('html', Math.round(total * 10) / 10 + ' km/h');
window.previousLocation = currentLocation;
window.previousTime = time;
}
function initMap(latlng) {
var peg = new google.maps.MarkerImage('peggie.png');
peg.anchor = new google.maps.Point(6, 16);
peg.size = new google.maps.Size(24, 47);
peg.scaledSize = new google.maps.Size(12, 23);
window.peg = new google.maps.Marker({
position: latlng,
map: window.map,
icon: peg,
clickable: false,
});
if (window.gamemode == "MultiPlayer") {
var opp_peg = new google.maps.MarkerImage('peggie_opp.png');
opp_peg.anchor = new google.maps.Point(6,16);
opp_peg.size = new google.maps.Size(24,47);
opp_peg.scaledSize = new google.maps.Size(12,23);
window.opp_peg = new google.maps.Marker({
position: window.opponentPos,
map: window.map,
icon: opp_peg,
clickable: false,
});
}
}
function updateMap(currentLocation) {
window.peg.setPosition(currentLocation);
window.map.setCenter(currentLocation);
}
function compassChanged() {
var panoheading = window.panorama.getPov().heading;
panoheading = ((panoheading + 180) % 360) - 180;
var curlocation = window.panorama.getPosition();
var goalheading = google.maps.geometry.spherical.computeHeading(
curlocation, window.goalPosition);
var heading = ((goalheading - panoheading + 180) % 360) - 180;
if (heading < -180 || heading > 180) {
console.log('diff: ' + (goalheading - panoheading));
console.log('head: ' + (((goalheading - panoheading + 180) % 360) - 180));
}
if (heading < 0) {
var l_r = 'left';
} else {
var l_r = 'right';
}
$('compass-txt').set('html', 'Goal ' + Math.abs(Math.round(heading)) + '° to the ' + l_r);
var img = document.getElementById('cps_im');
//[-180 -135 -90 -45 0]
//[-157.5 112.5 67.5 22.5]
if (heading < -157.5 || heading > 157.5) {
$('cps_im').set('src', "compass180.png");
} else if (heading < -112.5) {
$('cps_im').set('src', "compass225.png");
} else if (heading < -67.5) {
$('cps_im').set('src', "compass270.png");
} else if (heading < -22.5) {
$('cps_im').set('src', "compass315.png");
} else if (heading < 22.5) {
$('cps_im').set('src', "compass0.png");
} else if (heading < 67.5) {
$('cps_im').set('src', "compass45.png");
} else if (heading < 112.5) {
$('cps_im').set('src', "compass90.png");
} else if (heading < 157.5) {
$('cps_im').set('src', "compass135.png");
}
}