-
Notifications
You must be signed in to change notification settings - Fork 0
/
jogo.html
297 lines (294 loc) · 9.36 KB
/
jogo.html
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
<html>
<head>
<meta charset="UTF-8">
<title>Slack Defenders - Game</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<script src="./js/jogo.js"></script>
<script src="./js/SAT.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body bgcolor="#000000" onresize="updateEarth()">
<div class="scene" >
<div class="stars"></div>
<div class="twinkling"></div>
<div class="acid transparent ">
<img id="acid" src="./acid2.gif"/>
</div>
<h3 class="titulo">Aperte espaço para mudar a direção e enter para atirar</h3>
<h3 class="pontuacao">Score: <span id="minha-pontuacao-linda">0</span></h3>
<h3 class="levelup template">CREEPYPASTA!</h3>
<div class="terradiv shadow" id="cf2">
<img class="3" id="terra" src="./hypno.png"/>
<img class="2" id="terra" src="./eye-026.png"/>
<img class="1" id="terra" src="./Earth-Free-Download-PNG.png"/>
</div>
<div class="image1">
<img id="eric" src="https://emoji.slack-edge.com/T0NGK4FPS/eric/8a5698b1bd5ce9be.png"/>
</div>
</div>
<div class="villain template">
<img id="vilaoimg" src="https://emoji.slack-edge.com/T0NGK4FPS/salles/eefac6cd78a94882.png" />
</div>
<div class="smiley template">
<img src="./smiley.png" />
</div>
</body>
<script>
window.addEventListener("keydown", change, false);
window.addEventListener("keyup", shootdetector, false);
var $elie = $('.image1');
var $earth = $('.terradiv');
var degree = 0;
var degree2 = 0;
var direction = true;
var shoots = [];
var id = 1;
var salesnum = 1;
var enemies = [];
var score = 0;
var multiplier = 1;
var level = 1;
var acidtrip = false;
var earthbody = new EarthBody({x:$earth.position().left,y:$earth.position().top},75);
var stop = false;
var specialLevel = false;
var special = "";
var vilao = "sales";
var CREEPYSCORE = 2000;
var QueryString = function () {
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = decodeURIComponent(pair[1]);
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
}();
if(QueryString.hero == "manas"){
$('#eric')[0].src = "https://emoji.slack-edge.com/T0NGK4FPS/manas/61d334f422c2c01d.png";
} else if (QueryString.hero == "nakajo"){
$('#eric')[0].src = "https://emoji.slack-edge.com/T0NGK4FPS/nakajo/a48bf7355ff2519b.png"
} // Eric é o padrão
if(QueryString.villain == "roma"){
$('#vilaoimg')[0].src = "https://emoji.slack-edge.com/T0NGK4FPS/roma/69e76a7cf0bacf90.png";
vilao = "roma";
} // Sales é o padrão
function change(e){
if(e.keyCode == '32'){
direction = !direction;
} else if(e.keyCode == '13'){
if (multiplier == 1){
setTimeout(function(){
multiplier = 10*multiplier;
if (multiplier > 10)
multiplier = 10;
},2000);
}
}
}
function shootdetector(e){
if (e.keyCode == '13'){
shoot(multiplier);
multiplier = 1;
}
}
function invertcolors(){
if (acidtrip) {
setTimeout(function(){
$("#eric").toggleClass("invert");
$(".villain").toggleClass("invert");
$(".tiro").toggleClass("invert");
invertcolors()
},200);
}
if (!acidtrip){
if ($('#eric').hasClass("invert")){
$("#eric").toggleClass("invert");
}
}
}
function superscore(){
if (specialLevel){
setTimeout(function(){
score += 1;
superscore();
},500);
}
}
function updateEarth(){
earthbody.update({x:$earth.position().left,y:$earth.position().top});
}
console.log("%cLEVY!", "color: red; font-family: sans-serif; font-size: 30em; font-weight: bolder; text-shadow: #000 1px 1px;");
function explode(){
$elie.hide();
$earth.hide();
$('.stars').hide();
$('.twinkling').hide();
for (j=0;j<enemies.length;j++){
enemies[j].div.hide();
}
enemies = [];
for (j=0;j<shoots.length;j++){
shoots[j].div.hide();
}
shoots = [];
stop = true;
if (!acidtrip && !(level == 2)) {
var oImg = "<img class='explosao' src='./exploding_earth1.gif' />";
$('.scene').append(oImg);
}
}
function rotateearth(){
if (degree2 == 360 || degree2 == -360){
degree2 = 0;
}
$earth.css({ WebkitTransform: 'rotate(' + degree2 + 'deg)'});
timer = setTimeout(function() {
if(!specialLevel){
degree2 += 0.005;
} else {
degree2 += 8;
}
for (i=0; i<enemies.length; i++){
for (j=0; j<shoots.length; j++){
if (enemies[i].contact(shoots[j])){
enemies[i].collide(shoots[j]);
document.getElementById(shoots[j].div[0].id).remove();
shoots.splice(j,1);
if (enemies[i].acid){
// Está ativando a acid trip
specialLevel = true;
special = "acid";
setTimeout(function(){
specialLevel = false;
acidtrip = false;
if (level == 1){
$("#cf2 img.1").toggleClass("transparent");
$("#cf2 img.2").toggleClass("transparent");
$(".stars").toggleClass("transparent");
$(".twinkling").toggleClass("transparent");
} else if (level == 2 ){
$("#cf2 img.2").toggleClass("transparent");
}
$(".acid").toggleClass("transparent");
},10000); // Timer dos niveis especiais
if (!acidtrip){
$(".acid").toggleClass("transparent"); // Vai mostrar o bg sempre
if (level == 1){ //se estiver a Terra e estrelas ali
$("#cf2 img.1").toggleClass("transparent");
$("#cf2 img.2").toggleClass("transparent");
$(".stars").toggleClass("transparent");
$(".twinkling").toggleClass("transparent");
} else if (level == 2){ //senão só esconde o olho
$("#cf2 img.2").toggleClass("transparent");
}
}
if (!acidtrip){
acidtrip = true;
invertcolors();
superscore();
}
}
}
}
};
for (i=0; i<enemies.length; i++){
enemies[i].move(1/60);
enemies[i].updateUI();
};
for (i=0; i<shoots.length; i++){
shoots[i].move(1/60);
shoots[i].updateUI();
};
for (i=0;i<enemies.length;i++){
var wd = $('.scene').width();
var ht = $('.scene').height();
if ( earthbody.contact(enemies[i]) && !enemies[i].acid ){
explode();
return;
}
if ( enemies[i].collided && (enemies[i].position.x < -enemies[i].width || enemies[i].position.x > wd || enemies[i].position.y < -enemies[i].height || enemies[i].position.y > ht )){
enemies[i].div.hide()
enemies.splice(i,1);
score += 20;
$('#minha-pontuacao-linda').html(score);
if (score == CREEPYSCORE && level < 3 ){
level ++;
var div = $('.levelup.template').clone();
div.removeClass('template');
$('.scene').append(div);
div.show();
$("#cf2 img.1").toggleClass("transparent");
$(".stars").toggleClass("transparent");
$(".twinkling").toggleClass("transparent");
}
}
};
rotateearth();
},(1/60));
}
function rotate(){
if (degree == 360 || degree == -360){
degree = 0;
}
if (degree < 0){
degree = 360 + degree;
}
$elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});
if (stop){
return;
}
timer = setTimeout(function() {
if(direction){
if (level < 3){
degree-=0.5; rotate();
} else {
degree-=1; rotate();
}
} else {
if (level < 3){
degree+=0.5; rotate();
} else {
degree+=1; rotate();
}
}
},1/120);
}
function shoot(multiplicador){
var shootdiv = document.createElement('div');
shootdiv.id = id;
shootdiv.className = 'tiro';
document.getElementsByTagName('body')[0].appendChild(shootdiv);
$divshoot = $("#"+id);
id ++;
$divshoot.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});
x = Math.cos(degree*Math.PI/180);
y = Math.sin(degree*Math.PI/180);
var speed = { x: x*500, y: y*500 };
var pos = { x: $earth.position().left+80*Math.cos(degree*Math.PI/180), y: $earth.position().top+80*Math.sin(degree*Math.PI/180) };
//var pos = { x: $earth.position().left, y: $earth.position().top };
tiro = new ElasticBody($divshoot, pos, speed, 50, 5, multiplicador, false);
tiro.hitpolygon.angle = degree;
shoots.push(tiro);
if ( shoots.length > 10 ) {
shoots.shift();
}
if (id > 10 && document.getElementById(String(id-10))) {
document.getElementById(String(id-10)).remove();
}
}
$(document).ready(start)
</script>
</html>