-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
456 lines (348 loc) · 14.1 KB
/
index.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
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
<html><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" href="./favicon.ico">
<title>Andrei Bui Dots SpaceX</title>
<style>
html{color:#000;background:#222222;} a{cursor:pointer;} html,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;} table{border-collapse:collapse;border-spacing:0;} fieldset,img{border:0;} address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;} li{list-style:none;} caption,th{text-align:left;} /* h1,h2,h3,h4,h5,h6{font-size:100%;} */ q:before,q:after{content:'';} abbr,acronym {border:0;font-variant:normal;} sup {vertical-align:text-top;} sub {vertical-align:text-bottom;} input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;outline-style:none;outline-width:0pt;} legend{color:#000;} a:focus,object,h1,h2,h3,h4,h5,h6{-moz-outline-style: none; border:0px;} /*input[type="Submit"]{cursor:pointer;}*/ strong {font-weight: bold;} body {overflow: hidden; font-family: Helvetica, Arial, sans-serif; color: #333333; font-size: 11px; background-color: #222222;} canvas {background-color: #111111;} .ui {font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #999999; text-align: left; padding: 8px; background-color: rgba(0,0,0,0.5); position: absolute; z-index: 2; margin: 0;} #message {padding: 16px;} #message p {color:lime;font-size:12px;animation:blink 880ms ease-in-out infinite;} #status {width: 100%; height: 15px; padding: 8px; display: none;} #status span {color: dodgerblue; font-weight: bold; margin-right: 5px;} #title {margin-bottom: 20px; color: #eeeeee;} .ui ul {margin: 10px 0 10px 0;} .ui a {outline: none; font-family: Arial, Helvetica, sans-serif; font-size: 38px; text-decoration: none; color: #bbbbbb; padding: 2px; display: block;background: goldenrod;border-radius: 12px;text-align: center;} .ui a:hover {color: #000; background-color: #4bde35;}@keyframes blink {0%{color:lime;}100%{color:transparent;}}
</style>
</head>
<body>
<canvas id="world"></canvas>
<div id="status" class="ui"></div>
<div id="message" class="ui">
<h2 id="title"></h2>
<h2 id="result">Andrei Bui Dot SpaceX 🚀</h2>
<ul>
<li>🔴 Avoid RED dots.</li>
<br>
<li>🔴 Touch GREEN dots for invulnerability.</li>
<br>
<li>🔴 Use invulnerability to destroy RED dots.</li>
<br>
<li>🔴 Score EXTRA points by moving around a lot.</li>
<br>
<li>🔴 STAY ALIVE !</li>
</ul>
<h3>💡 Enter your name</h3>
<br>
<input id="name" value="Andrei handsome" type="text" size = "45" placeholder="Enter your name"> <br><br>
<h3 id="high"></h3>
<br>
<br>
<a href="#" id="startButton">Starttt!!!</a>
<br>
</div>
<script type="text/javascript">
Spacedots = new function(){
var isMobile = (navigator.userAgent.toLowerCase().indexOf('android') != -1) || (navigator.userAgent.toLowerCase().indexOf('iphone') != -1);
var SCREEN_WIDTH = window.innerWidth;
var SCREEN_HEIGHT = window.innerHeight;
var canvas;
var context;
var status;
var message;
var title;
var startButton;
var enemies = [];
var boosts = [];
var particles = [];
var player;
var mouseX = (window.innerWidth - SCREEN_WIDTH);
var mouseY = (window.innerHeight - SCREEN_HEIGHT);
var mouseIsDown = false;
var playing = false;
var score = 0;
var highscore = 0;
var time = 0;
var velocity = { x: -1.5, y: 1 };
var difficulty = 1;
this.init = function(){
canvas = document.getElementById('world');
status = document.getElementById('status');
message = document.getElementById('message');
title = document.getElementById('title');
startButton = document.getElementById('startButton');
dis = '';
dis += "High Score: " + Math.round(localStorage.getItem("highscore"));
document.getElementById("high").innerHTML = dis;
if (canvas && canvas.getContext) {
context = canvas.getContext('2d');
// Register event listeners
document.addEventListener('mousemove', documentMouseMoveHandler, false);
document.addEventListener('mousedown', documentMouseDownHandler, false);
document.addEventListener('mouseup', documentMouseUpHandler, false);
canvas.addEventListener('touchstart', documentTouchStartHandler, false);
document.addEventListener('touchmove', documentTouchMoveHandler, false);
document.addEventListener('touchend', documentTouchEndHandler, false);
window.addEventListener('resize', windowResizeHandler, false);
startButton.addEventListener('click', startButtonClickHandler, false);
player = new Player();
windowResizeHandler();
setInterval(loop, 1000 / 70);
}
};
function startButtonClickHandler(event){
event.preventDefault();
if( playing == false ) {
playing = true;
enemies = [];
boosts = [];
score = 0;
difficulty = 1;
player.trail = [];
player.position.x = mouseX;
player.position.y = mouseY;
player.boost = 0;
message.style.display = 'none';
status.style.display = 'block';
time = new Date().getTime();
}
}
function gameOver() {
playing = false;
message.style.display = 'block';
display = 'Game Over!' + ' ' + document.getElementById("name").value + ' ' + Math.round( score ) + ' points' ;
title.innerHTML = display;
var highscore = localStorage.getItem("highscore");
if(highscore !== null){
if (score > highscore) {
localStorage.setItem("highscore", score);
}
}
else{
localStorage.setItem("highscore", score);
}
dis = '';
dis += "High Score: " + Math.round(localStorage.getItem("highscore"));
document.getElementById("high").innerHTML = dis;
}
function documentMouseMoveHandler(event){
mouseX = event.clientX - (window.innerWidth - SCREEN_WIDTH) * .5 - 10;
mouseY = event.clientY - (window.innerHeight - SCREEN_HEIGHT) * .5 - 10;
}
function documentMouseDownHandler(event){
mouseIsDown = true;
}
function documentMouseUpHandler(event) {
mouseIsDown = false;
}
function documentTouchStartHandler(event) {
if(event.touches.length == 1) {
event.preventDefault();
mouseX = event.touches[0].pageX - (window.innerWidth - SCREEN_WIDTH) * .5;
mouseY = event.touches[0].pageY - (window.innerHeight - SCREEN_HEIGHT) * .5;
mouseIsDown = true;
}
}
function documentTouchMoveHandler(event) {
if(event.touches.length == 1) {
event.preventDefault();
mouseX = event.touches[0].pageX - (window.innerWidth - SCREEN_WIDTH) * .5;
mouseY = event.touches[0].pageY - (window.innerHeight - SCREEN_HEIGHT) * .5;
}
}
function documentTouchEndHandler(event) {
mouseIsDown = false;
}
function windowResizeHandler() {
SCREEN_WIDTH = window.innerWidth;
SCREEN_HEIGHT = window.innerHeight;
canvas.width = SCREEN_WIDTH;
canvas.height = SCREEN_HEIGHT;
var cvx = (window.innerWidth - SCREEN_WIDTH) * .5;
var cvy = (window.innerHeight - SCREEN_HEIGHT) * .5;
canvas.style.position = 'absolute';
canvas.style.left = cvx + 'px';
canvas.style.top = cvy + 'px';
message.style.left = cvx + 'px';
message.style.top = cvy + 200 + 'px';
}
function createParticles( position, spread, color ) {
var q = 10 + ( Math.random() * 15 );
while( --q >= 0 ) {
var p = new Particle();
p.position.x = position.x + ( Math.sin(q) * spread );
p.position.y = position.y + ( Math.cos(q) * spread );
p.velocity = { x: -4 + Math.random() * 8, y: - 4 + Math.random() * 8 };
p.alpha = 1;
particles.push( p );
}
}
function loop() {
context.clearRect(0,0,canvas.width,canvas.height);
var svelocity = { x: velocity.x * difficulty, y: velocity.y * difficulty };
var i, j, ilen, jlen;
if( playing ) {
difficulty += 0.0008;
pp = player.clonePosition();
player.position.x += ( mouseX - player.position.x ) * 0.13;
player.position.y += ( mouseY - player.position.y ) * 0.13;
score += 0.4 * difficulty;
score += player.distanceTo( pp ) * 0.1;
player.boost = Math.max( player.boost - 1, 0 );
if( player.boost > 0 && ( player.boost > 100 || player.boost % 3 != 0 ) ) {
context.beginPath();
context.fillStyle = '#167a66';//couleur interne au stade augmenter
context.strokeStyle = 'yellow';//couleur de la bordure au stade augmenter
context.arc(player.position.x, player.position.y, player.size*2, 0, Math.PI*2, true);
context.fill();
context.stroke();
}
player.trail.push( new Point( player.position.x, player.position.y ) );
context.beginPath();
context.strokeStyle = 'gold';// couleur du fil
context.lineWidth = 2;
for( i = 0, ilen = player.trail.length; i < ilen; i++ ) {
p = player.trail[i];
context.lineTo( p.position.x, p.position.y );
p.position.x += svelocity.x;
p.position.y += svelocity.y;
}
context.stroke();
context.closePath();
if( player.trail.length > 60 ) {
player.trail.shift();
}
context.beginPath();
context.fillStyle = 'orange';//couleur du noyau au stade normal
context.arc(player.position.x, player.position.y, player.size/2, 0, Math.PI*2, true);
context.fill();
}
if( playing && ( player.position.x < 0 || player.position.x > SCREEN_WIDTH || player.position.y < 0 || player.position.y > SCREEN_HEIGHT ) ) {
gameOver();
}
for( i = 0; i < enemies.length; i++ ) {
p = enemies[i];
if( playing ) {
if( player.boost > 0 && p.distanceTo( player.position ) < ( ( player.size * 4 ) + p.size ) * 0.5 ) {
createParticles( p.position, 10 );
enemies.splice( i, 1 );
i --;
score += 10;
continue;
}
else if( p.distanceTo( player.position ) < ( player.size + p.size ) * 0.5 ) {
createParticles( player.position, 10 );
gameOver();
}
}
context.beginPath();
context.fillStyle = 'red';//couleur des balles ennemies diminue
context.arc(p.position.x, p.position.y, p.size/2, 0, Math.PI*2, true);
context.fill();
p.position.x += svelocity.x * p.force;
p.position.y += svelocity.y * p.force;
if( p.position.x < 0 || p.position.y > SCREEN_HEIGHT ) {
enemies.splice( i, 1 );
i --;
}
}
for( i = 0; i < boosts.length; i++ ) {
p = boosts[i];
if( p.distanceTo( player.position ) < ( player.size + p.size ) * 0.5 && playing ) {
player.boost = 300;
for( j = 0; j < enemies.length; j++ ) {
e = enemies[j];
if( e.distanceTo( p.position ) < 100 ) {
createParticles( e.position, 10 );
enemies.splice( j, 1 );
j--;
score += 10;
}
}
}
context.beginPath();
context.fillStyle = '#00ffcc';//couleur de la balle de point augmente
context.arc(p.position.x, p.position.y, p.size/2, 0, Math.PI*2, true);
context.fill();
p.position.x += svelocity.x * p.force;
p.position.y += svelocity.y * p.force;
if( p.position.x < 0 || p.position.y > SCREEN_HEIGHT || player.boost != 0 ) {
boosts.splice( i, 1 );
i --;
}
}
if( enemies.length < 25 * difficulty ) {
enemies.push( positionNewOrganism( new Enemy() ) );
}
if( boosts.length < 1 && Math.random() > 0.997 && player.boost == 0 ) {
boosts.push( positionNewOrganism( new Boost() ) );
}
for( i = 0; i < particles.length; i++ ) {
p = particles[i];
p.velocity.x += ( svelocity.x - p.velocity.x ) * 0.04;
p.velocity.y += ( svelocity.y - p.velocity.y ) * 0.04;
p.position.x += p.velocity.x;
p.position.y += p.velocity.y;
p.alpha -= 0.02;
context.fillStyle = 'red'+Math.max(p.alpha,0)+')';
context.fillRect( p.position.x, p.position.y, 1, 1 );
if( p.alpha <= 0 ) {
particles.splice( i, 1 );
}
}
if( playing ) {
scoreText = 'Score: <span>' + Math.round( score ) + '</span>';
scoreText += ' Time: <span>' + Math.round( ( ( new Date().getTime() - time ) / 1000 ) * 100 ) / 100 + 's</span>';
scoreText += ' <span>' + 'Good Luck ' + document.getElementById("name").value + '</span>';
status.innerHTML = scoreText;
}
}
function positionNewOrganism( p ) {
if( Math.random() > 0.5 ) {
p.position.x = Math.random() * SCREEN_WIDTH;
p.position.y = -20;
}
else {
p.position.x = SCREEN_WIDTH + 60;
p.position.y = (-SCREEN_HEIGHT * 0.2) + ( Math.random() * SCREEN_HEIGHT * 1.2 );
}
return p;
}
};
/****/
function Point( x, y ) {
this.position = { x: x, y: y };
}
Point.prototype.distanceTo = function(p) {
var dx = p.x-this.position.x;
var dy = p.y-this.position.y;
return Math.sqrt(dx*dx + dy*dy);
};
Point.prototype.clonePosition = function() {
return { x: this.position.x, y: this.position.y };
};
/****/
function Player() {
this.position = { x: 0, y: 0 };
this.trail = [];
this.size = 8;
this.boost = 0;
}
Player.prototype = new Point();
/****/
function Enemy() {
this.position = { x: 0, y: 0 };
this.size = 6 + ( Math.random() * 4 );
this.force = 1 + ( Math.random() * 0.4 );
}
Enemy.prototype = new Point();
/****/
function Boost() {
this.position = { x: 0, y: 0 };
this.size = 10 + ( Math.random() * 8 );
this.force = 1 + ( Math.random() * 0.4 );
}
Boost.prototype = new Point();
/****/
function Particle() {
this.position = { x: 0, y: 0 };
this.force = 1 + ( Math.random() * 0.4 );
this.color = '#ff0000';
}
Particle.prototype = new Point();
Spacedots.init();
</script>
</body></html>