-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdronefall.html
More file actions
735 lines (627 loc) · 24 KB
/
dronefall.html
File metadata and controls
735 lines (627 loc) · 24 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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DRONE FALL</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Orbitron', sans-serif;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
body {
background: #000000;
color: #00ff00;
overflow: hidden;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
touch-action: none;
}
#game-container {
position: relative;
width: 100%;
max-width: 1000px;
height: 80vh;
border: 2px solid #00ff00;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
}
#game-canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
image-rendering: -moz-crisp-edges;
image-rendering: -webkit-crisp-edges;
image-rendering: pixelated;
image-rendering: crisp-edges;
}
#ui-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 10;
}
.screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.9);
z-index: 20;
}
#menu-screen {
background: rgba(0, 0, 0, 0.95);
}
#game-over-screen {
display: none;
}
h1 {
font-size: 48px;
margin-bottom: 30px;
color: #00ff00;
text-shadow: 0 0 10px #00ff00, 0 0 20px #00ff00;
animation: pulse 2s infinite;
text-align: center;
}
@keyframes pulse {
0% { text-shadow: 0 0 10px #00ff00, 0 0 20px #00ff00; }
50% { text-shadow: 0 0 15px #00ff00, 0 0 30px #00ff00, 0 0 40px #00ff00; }
100% { text-shadow: 0 0 10px #00ff00, 0 0 20px #00ff00; }
}
.btn {
padding: 12px 30px;
margin: 10px;
background: transparent;
color: #00ff00;
border: 2px solid #00ff00;
border-radius: 30px;
font-size: 18px;
cursor: pointer;
transition: all 0.3s ease;
pointer-events: auto;
text-transform: uppercase;
letter-spacing: 2px;
}
.btn:hover {
background: #00ff00;
color: #000000;
box-shadow: 0 0 15px #00ff00;
}
.ui-element {
position: absolute;
color: #00ff00;
text-shadow: 0 0 5px #00ff00;
font-size: 18px;
font-weight: bold;
}
#timer {
top: 20px;
left: 20px;
font-size: 24px;
color: #00ff00;
text-shadow: 0 0 10px #00ff00;
}
#drones-destroyed {
top: 20px;
right: 20px;
font-size: 18px;
}
.hit-indicator {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 50px;
height: 50px;
border-radius: 50%;
background: rgba(0, 255, 0, 0.3);
pointer-events: none;
z-index: 14;
opacity: 0;
transition: all 0.3s ease;
}
.countdown {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 120px;
color: #00ff00;
text-shadow: 0 0 20px #00ff00;
z-index: 30;
display: none;
animation: pulse 1s infinite;
}
.instructions {
max-width: 600px;
text-align: center;
margin: 20px 0;
line-height: 1.6;
color: #00ff99;
}
@media (max-width: 768px) {
h1 {
font-size: 32px;
}
.btn {
padding: 10px 20px;
font-size: 14px;
}
.countdown {
font-size: 80px;
}
.instructions {
font-size: 14px;
padding: 0 10px;
}
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700;900&display=swap" rel="stylesheet">
</head>
<body>
<div id="game-container">
<canvas id="game-canvas"></canvas>
<div id="ui-overlay">
<div id="timer" class="ui-element">01:00</div>
<div id="drones-destroyed" class="ui-element">DRONES: 0</div>
<div class="hit-indicator"></div>
<div class="countdown" id="countdown">3</div>
</div>
<div id="menu-screen" class="screen">
<h1>DRONE FALL BETA TEST</h1>
<p class="instructions">
CLICK AND DRAG
the green laser to destroys red drones as possible!
DESTROY AS MANY RED DRONES AS POSSIBLE IN 60 SECONDS!<br><br>
</p>
<button class="btn" id="start-btn">PLAY</button>
</div>
<div id="game-over-screen" class="screen">
<h1>by webXOS 2025</h1>
<p class="instructions" id="final-score">DRONES DESTROYED: 0</p>
<button class="btn" id="restart-btn">NEW BATTLE</button>
<button class="btn" id="menu-btn">MAIN MENU</button>
</div>
</div>
<script>
// Game variables
let canvas, ctx;
let gameActive = false;
let dronesDestroyed = 0;
let player;
let enemies = [];
let particles = [];
let lastTime = 0;
let animationId;
let isMobile = false;
let gameTime = 60;
let timerInterval;
let countdownActive = false;
let spawnMultiplier = 1.0;
// Mouse/touch tracking
let mouseX = 0;
let mouseY = 0;
// Performance optimization
const MAX_PARTICLES = 20;
const MAX_ENEMIES = 25;
// Background elements (simplified for performance)
let stars = [];
// DOM elements
const menuScreen = document.getElementById('menu-screen');
const gameOverScreen = document.getElementById('game-over-screen');
const timerDisplay = document.getElementById('timer');
const dronesDestroyedDisplay = document.getElementById('drones-destroyed');
const startBtn = document.getElementById('start-btn');
const restartBtn = document.getElementById('restart-btn');
const menuBtn = document.getElementById('menu-btn');
const finalScoreDisplay = document.getElementById('final-score');
const hitIndicator = document.querySelector('.hit-indicator');
const countdown = document.getElementById('countdown');
// Initialize the game
function init() {
canvas = document.getElementById('game-canvas');
ctx = canvas.getContext('2d');
canvas.width = canvas.parentElement.clientWidth;
canvas.height = canvas.parentElement.clientHeight;
// Check if mobile
isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) || window.innerWidth < 768;
// Create player (sword drone) with broad sword design
player = {
x: canvas.width / 2,
y: canvas.height / 2,
bladeLength: 60,
bladeWidth: 12,
hiltLength: 15,
hiltWidth: 8,
handleLength: 20,
handleWidth: 6,
bladeColor: '#00ff00',
hiltColor: '#333333',
handleColor: '#555555'
};
// Generate simple background
generateBackground();
// Set up event listeners
setupEventListeners();
// Start game loop
gameLoop(0);
}
function generateBackground() {
// Create minimal stars for performance
stars = [];
for (let i = 0; i < 30; i++) {
stars.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 1.5 + 0.5,
brightness: Math.random() * 0.8 + 0.2
});
}
}
function setupEventListeners() {
// Button events
startBtn.addEventListener('click', startGame);
restartBtn.addEventListener('click', startGame);
menuBtn.addEventListener('click', showMenu);
// Window resize
window.addEventListener('resize', () => {
canvas.width = canvas.parentElement.clientWidth;
canvas.height = canvas.parentElement.clientHeight;
generateBackground();
});
// Mouse movement for desktop
if (!isMobile) {
canvas.addEventListener('mousemove', (e) => {
updateMousePosition(e);
if (gameActive) {
player.x = mouseX;
player.y = mouseY;
applyBoundaryConstraints();
}
e.preventDefault();
});
}
// Touch movement for mobile
if (isMobile) {
canvas.addEventListener('touchstart', (e) => {
if (!gameActive) return;
updateTouchPosition(e.touches[0]);
player.x = mouseX;
player.y = mouseY;
applyBoundaryConstraints();
e.preventDefault();
});
canvas.addEventListener('touchmove', (e) => {
if (!gameActive) return;
updateTouchPosition(e.touches[0]);
player.x = mouseX;
player.y = mouseY;
applyBoundaryConstraints();
e.preventDefault();
});
}
function updateMousePosition(e) {
const rect = canvas.getBoundingClientRect();
mouseX = e.clientX - rect.left;
mouseY = e.clientY - rect.top;
}
function updateTouchPosition(touch) {
const rect = canvas.getBoundingClientRect();
mouseX = touch.clientX - rect.left;
mouseY = touch.clientY - rect.top;
}
}
function applyBoundaryConstraints() {
// Calculate the actual boundaries based on sword dimensions
// This prevents the sword from getting stuck in corners
// X boundaries - account for blade width
const minX = player.bladeWidth / 2;
const maxX = canvas.width - player.bladeWidth / 2;
// Y boundaries - account for blade length at top and handle at bottom
const minY = player.bladeLength / 2;
const maxY = canvas.height - player.handleLength / 2;
// Apply constraints
player.x = Math.max(minX, Math.min(maxX, player.x));
player.y = Math.max(minY, Math.min(maxY, player.y));
}
function startGame() {
gameActive = false;
dronesDestroyed = 0;
spawnMultiplier = 1.0;
player.x = canvas.width / 2;
player.y = canvas.height / 2;
enemies = [];
particles = [];
dronesDestroyedDisplay.textContent = 'DRONES: 0';
timerDisplay.textContent = '01:00';
timerDisplay.style.color = '#00ff00';
menuScreen.style.display = 'none';
gameOverScreen.style.display = 'none';
// Start countdown
startCountdown();
}
function startCountdown() {
countdownActive = true;
countdown.style.display = 'block';
let count = 3;
countdown.textContent = count;
const countdownInterval = setInterval(() => {
count--;
if (count > 0) {
countdown.textContent = count;
} else {
countdown.textContent = 'GO!';
setTimeout(() => {
countdown.style.display = 'none';
countdownActive = false;
gameActive = true;
// Start enemy spawning
spawnEnemy();
// Start game timer
startTimer();
}, 500);
clearInterval(countdownInterval);
}
}, 1000);
}
function startTimer() {
clearInterval(timerInterval);
gameTime = 60;
updateTimerDisplay();
timerInterval = setInterval(() => {
gameTime--;
updateTimerDisplay();
// Increase spawn multiplier every 10 seconds
if (gameTime % 10 === 0 && gameTime < 60) {
spawnMultiplier += 0.5;
}
if (gameTime <= 0) {
clearInterval(timerInterval);
gameOver();
}
}, 1000);
}
function updateTimerDisplay() {
const minutes = Math.floor(gameTime / 60);
const seconds = gameTime % 60;
timerDisplay.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Change color when time is running out
if (gameTime <= 10) {
timerDisplay.style.color = '#ff0000';
} else {
timerDisplay.style.color = '#00ff00';
}
}
function showMenu() {
clearInterval(timerInterval);
gameActive = false;
menuScreen.style.display = 'flex';
gameOverScreen.style.display = 'none';
}
function gameOver() {
gameActive = false;
finalScoreDisplay.textContent = `DRONES DESTROYED: ${dronesDestroyed}`;
gameOverScreen.style.display = 'flex';
}
function spawnEnemy() {
if (!gameActive) return;
// Spawn enemies at a rate that increases over time
// Base count increases with spawn multiplier
const baseCount = 2;
const enemyCount = Math.min(
Math.floor(baseCount * spawnMultiplier),
MAX_ENEMIES - enemies.length
);
for (let i = 0; i < enemyCount; i++) {
// Limit total enemies for performance
if (enemies.length >= MAX_ENEMIES) break;
const enemy = {
x: Math.random() * canvas.width,
y: -30 - Math.random() * 100,
width: 20,
height: 20,
speed: 2 + Math.random() * 2,
color: '#ff0000',
health: 1
};
enemies.push(enemy);
}
// Continue spawning enemies with adjusted rate based on multiplier
const spawnInterval = Math.max(500, 1500 / spawnMultiplier);
setTimeout(spawnEnemy, spawnInterval);
}
function updateEnemies() {
for (let i = enemies.length - 1; i >= 0; i--) {
const enemy = enemies[i];
// Move enemy
enemy.y += enemy.speed;
// Remove if off screen
if (enemy.y > canvas.height + 50) {
enemies.splice(i, 1);
continue;
}
// Calculate blade collision area
const bladeTop = player.y - (player.bladeLength + player.hiltLength/2 + 15);
const bladeBottom = player.y - player.hiltLength/2;
const bladeLeft = player.x - player.bladeWidth/2;
const bladeRight = player.x + player.bladeWidth/2;
// Check if enemy is within the blade area
if (enemy.x + enemy.width/2 > bladeLeft - 5 &&
enemy.x - enemy.width/2 < bladeRight + 5 &&
enemy.y + enemy.height/2 > bladeTop - 5 &&
enemy.y - enemy.height/2 < bladeBottom + 5) {
// Destroy enemy on contact with blade
createExplosion(enemy.x, enemy.y, enemy.color);
enemies.splice(i, 1);
dronesDestroyed++;
dronesDestroyedDisplay.textContent = `DRONES: ${dronesDestroyed}`;
// Show hit indicator
showHitIndicator();
}
}
}
function updateParticles() {
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
// Update particle
particle.x += particle.vx;
particle.y += particle.vy;
particle.alpha -= 0.03; // Faster fade for performance
// Remove if faded out
if (particle.alpha <= 0 || particles.length > MAX_PARTICLES) {
particles.splice(i, 1);
}
}
}
function createExplosion(x, y, color) {
// Limit particles for performance
const particleCount = Math.min(8, MAX_PARTICLES - particles.length);
for (let i = 0; i < particleCount; i++) {
const angle = Math.random() * Math.PI * 2;
const speed = Math.random() * 3;
particles.push({
x: x,
y: y,
radius: Math.random() * 2 + 1,
color: color,
vx: Math.sin(angle) * speed,
vy: Math.cos(angle) * speed,
alpha: 1
});
}
}
function showHitIndicator() {
hitIndicator.style.opacity = '1';
hitIndicator.style.width = '50px';
hitIndicator.style.height = '50px';
setTimeout(() => {
hitIndicator.style.opacity = '0';
hitIndicator.style.width = '0px';
hitIndicator.style.height = '0px';
}, 200);
}
function drawBackground() {
// Draw a simple black background
ctx.fillStyle = '#000011';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw minimal stars
stars.forEach(star => {
ctx.fillStyle = `rgba(255, 255, 255, ${star.brightness})`;
ctx.beginPath();
ctx.arc(star.x, star.y, star.size, 0, Math.PI * 2);
ctx.fill();
});
}
function drawPlayer() {
ctx.save();
// Translate to player position
ctx.translate(player.x, player.y);
// Draw the sword - broad sword design with longer blade
// Draw handle (bottom part)
ctx.fillStyle = player.handleColor;
ctx.fillRect(
-player.handleWidth/2,
player.hiltLength/2,
player.handleWidth,
player.handleLength
);
// Draw hilt (middle part)
ctx.fillStyle = player.hiltColor;
ctx.fillRect(
-player.hiltWidth/2,
-player.hiltLength/2,
player.hiltWidth,
player.hiltLength
);
// Draw blade (top part) - longer blade
ctx.fillStyle = player.bladeColor;
ctx.shadowBlur = 8;
ctx.shadowColor = '#00ff00';
// Main blade
ctx.fillRect(
-player.bladeWidth/2,
-player.bladeLength - player.hiltLength/2,
player.bladeWidth,
player.bladeLength
);
// Blade tip
ctx.beginPath();
ctx.moveTo(-player.bladeWidth/2, -player.bladeLength - player.hiltLength/2);
ctx.lineTo(0, -player.bladeLength - player.hiltLength/2 - 15);
ctx.lineTo(player.bladeWidth/2, -player.bladeLength - player.hiltLength/2);
ctx.closePath();
ctx.fill();
ctx.restore();
}
function drawEnemies() {
enemies.forEach(enemy => {
ctx.fillStyle = enemy.color;
ctx.beginPath();
ctx.moveTo(enemy.x, enemy.y - enemy.height/2);
ctx.lineTo(enemy.x + enemy.width/2, enemy.y + enemy.height/2);
ctx.lineTo(enemy.x - enemy.width/2, enemy.y + enemy.height/2);
ctx.closePath();
ctx.fill();
});
}
function drawParticles() {
particles.forEach(particle => {
ctx.globalAlpha = particle.alpha;
ctx.fillStyle = particle.color;
ctx.beginPath();
ctx.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2);
ctx.fill();
});
ctx.globalAlpha = 1;
}
function update() {
if (!gameActive || countdownActive) return;
updateEnemies();
updateParticles();
}
function draw() {
drawBackground();
drawParticles();
drawEnemies();
drawPlayer();
}
function gameLoop(timestamp) {
// Performance optimization - limit updates for low-end devices
const deltaTime = timestamp - lastTime;
// Update at approximately 60fps
if (deltaTime > 16) {
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Update game state
update();
// Draw everything
draw();
lastTime = timestamp;
}
animationId = requestAnimationFrame(gameLoop);
}
// Start the game when the window loads
window.addEventListener('load', init);
</script>
</body>
</html>