aired commited on
Commit
3f85fca
·
verified ·
1 Parent(s): b842324

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +956 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Defender
3
- emoji: 🐨
4
- colorFrom: green
5
- colorTo: yellow
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: defender
3
+ emoji: 🐳
4
+ colorFrom: blue
5
+ colorTo: blue
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,956 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Galaxy Defender</title>
7
+ <style>
8
+ @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');
9
+
10
+ * {
11
+ margin: 0;
12
+ padding: 0;
13
+ box-sizing: border-box;
14
+ }
15
+
16
+ body {
17
+ background-color: #000;
18
+ color: #0ff;
19
+ font-family: 'Orbitron', sans-serif;
20
+ overflow: hidden;
21
+ height: 100vh;
22
+ background-image:
23
+ radial-gradient(circle at 20% 30%, rgba(20, 20, 80, 0.8), transparent 40%),
24
+ radial-gradient(circle at 80% 70%, rgba(80, 20, 80, 0.6), transparent 40%),
25
+ url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><circle cx="20" cy="50" r="1" fill="white" opacity="0.8"/><circle cx="50" cy="20" r="1" fill="white" opacity="0.6"/><circle cx="80" cy="50" r="1" fill="white" opacity="0.7"/><circle cx="50" cy="80" r="1" fill="white" opacity="0.9"/></svg>');
26
+ background-size: 100% 100%, 100% 100%, 100px 100px;
27
+ }
28
+
29
+ #gameContainer {
30
+ position: relative;
31
+ width: 100%;
32
+ height: 100vh;
33
+ perspective: 1000px;
34
+ }
35
+
36
+ #gameCanvas {
37
+ position: absolute;
38
+ top: 0;
39
+ left: 0;
40
+ z-index: 1;
41
+ }
42
+
43
+ #uiOverlay {
44
+ position: absolute;
45
+ top: 0;
46
+ left: 0;
47
+ width: 100%;
48
+ height: 100%;
49
+ z-index: 2;
50
+ pointer-events: none;
51
+ }
52
+
53
+ #scoreDisplay {
54
+ position: absolute;
55
+ top: 20px;
56
+ left: 20px;
57
+ font-size: 24px;
58
+ color: #0ff;
59
+ text-shadow: 0 0 10px #0ff;
60
+ }
61
+
62
+ #healthBar {
63
+ position: absolute;
64
+ top: 20px;
65
+ right: 20px;
66
+ width: 200px;
67
+ height: 20px;
68
+ background-color: rgba(255, 0, 0, 0.3);
69
+ border: 2px solid #f00;
70
+ border-radius: 10px;
71
+ overflow: hidden;
72
+ }
73
+
74
+ #healthFill {
75
+ height: 100%;
76
+ width: 100%;
77
+ background-color: #f00;
78
+ transition: width 0.3s;
79
+ }
80
+
81
+ #startScreen, #gameOverScreen {
82
+ position: absolute;
83
+ top: 0;
84
+ left: 0;
85
+ width: 100%;
86
+ height: 100%;
87
+ display: flex;
88
+ flex-direction: column;
89
+ justify-content: center;
90
+ align-items: center;
91
+ background-color: rgba(0, 0, 0, 0.8);
92
+ z-index: 3;
93
+ }
94
+
95
+ #gameOverScreen {
96
+ display: none;
97
+ }
98
+
99
+ h1 {
100
+ font-size: 3rem;
101
+ margin-bottom: 2rem;
102
+ color: #0ff;
103
+ text-shadow: 0 0 15px #0ff;
104
+ text-align: center;
105
+ }
106
+
107
+ p {
108
+ font-size: 1.2rem;
109
+ margin-bottom: 2rem;
110
+ color: #fff;
111
+ max-width: 600px;
112
+ text-align: center;
113
+ line-height: 1.6;
114
+ }
115
+
116
+ .btn {
117
+ padding: 12px 30px;
118
+ background: linear-gradient(45deg, #0ff, #00aaff);
119
+ border: none;
120
+ border-radius: 30px;
121
+ color: #000;
122
+ font-family: 'Orbitron', sans-serif;
123
+ font-size: 1.2rem;
124
+ font-weight: bold;
125
+ cursor: pointer;
126
+ transition: all 0.3s;
127
+ pointer-events: auto;
128
+ box-shadow: 0 0 15px #0ff;
129
+ }
130
+
131
+ .btn:hover {
132
+ transform: scale(1.05);
133
+ box-shadow: 0 0 25px #0ff;
134
+ }
135
+
136
+ #finalScore {
137
+ font-size: 2rem;
138
+ color: #0ff;
139
+ margin: 20px 0;
140
+ text-shadow: 0 0 10px #0ff;
141
+ }
142
+
143
+ #powerups {
144
+ position: absolute;
145
+ bottom: 20px;
146
+ left: 20px;
147
+ display: flex;
148
+ gap: 10px;
149
+ }
150
+
151
+ .powerup-icon {
152
+ width: 30px;
153
+ height: 30px;
154
+ border-radius: 50%;
155
+ display: flex;
156
+ justify-content: center;
157
+ align-items: center;
158
+ font-size: 16px;
159
+ color: #000;
160
+ background: #ff0;
161
+ box-shadow: 0 0 10px #ff0;
162
+ }
163
+
164
+ #earth {
165
+ position: absolute;
166
+ bottom: -50px;
167
+ left: 50%;
168
+ transform: translateX(-50%);
169
+ width: 300px;
170
+ height: 300px;
171
+ background: radial-gradient(circle at 30% 30%, #1a66ff, #003399 60%, #001a33);
172
+ border-radius: 50%;
173
+ box-shadow:
174
+ 0 0 60px rgba(0, 150, 255, 0.6),
175
+ inset 0 0 100px rgba(255, 255, 255, 0.3);
176
+ z-index: 0;
177
+ }
178
+
179
+ #earth::before {
180
+ content: '';
181
+ position: absolute;
182
+ top: 0;
183
+ left: 0;
184
+ width: 100%;
185
+ height: 100%;
186
+ background-image:
187
+ url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M20,50 Q35,40 50,50 T80,50" fill="none" stroke="%23007733" stroke-width="2"/><path d="M40,30 Q45,25 50,30 T60,30" fill="none" stroke="%23007733" stroke-width="1"/><path d="M25,65 Q35,60 45,65 T60,65" fill="none" stroke="%23007733" stroke-width="1"/></svg>');
188
+ background-size: 100%;
189
+ opacity: 0.6;
190
+ }
191
+ </style>
192
+ </head>
193
+ <body>
194
+ <div id="gameContainer">
195
+ <div id="earth"></div>
196
+ <canvas id="gameCanvas"></canvas>
197
+ <div id="uiOverlay">
198
+ <div id="scoreDisplay">SCORE: 0</div>
199
+ <div id="healthBar">
200
+ <div id="healthFill"></div>
201
+ </div>
202
+ <div id="powerups">
203
+ <!-- Power-up icons will be added here dynamically -->
204
+ </div>
205
+ </div>
206
+
207
+ <div id="startScreen">
208
+ <h1>GALAXY DEFENDER</h1>
209
+ <p>Aliens are attacking Earth from all directions! Take control of the state-of-the-art starfighter and defend our planet.</p>
210
+ <p>Controls: Arrow keys to move, Spacebar to shoot</p>
211
+ <button class="btn" id="startBtn">LAUNCH STARFIGHTER</button>
212
+ </div>
213
+
214
+ <div id="gameOverScreen">
215
+ <h1>MISSION FAILED</h1>
216
+ <p>The alien invasion was too strong. Earth has fallen under their control.</p>
217
+ <div id="finalScore">SCORE: 0</div>
218
+ <button class="btn" id="restartBtn">TRY AGAIN</button>
219
+ </div>
220
+ </div>
221
+
222
+ <audio id="laserSound" src="https://assets.mixkit.co/active_storage/sfx/2347/2347-preview.mp3" preload="auto"></audio>
223
+ <audio id="explosionSound" src="https://assets.mixkit.co/active_storage/sfx/2099/2099-preview.mp3" preload="auto"></audio>
224
+ <audio id="powerupSound" src="https://assets.mixkit.co/active_storage/sfx/2329/2329-preview.mp3" preload="auto"></audio>
225
+ <audio id="backgroundMusic" loop>
226
+ <source src="https://assets.mixkit.co/music/preview/mixkit-space-game-668.mp3" type="audio/mpeg">
227
+ </audio>
228
+
229
+ <script>
230
+ // Game constants
231
+ const GAME_WIDTH = window.innerWidth;
232
+ const GAME_HEIGHT = window.innerHeight;
233
+ const PLAYER_WIDTH = 60;
234
+ const PLAYER_HEIGHT = 40;
235
+ const BULLET_SIZE = 8;
236
+ const ENEMY_SIZE = 40;
237
+ const POWERUP_SIZE = 30;
238
+ const ENEMY_SPAWN_RATE = 2000; // ms
239
+ const POWERUP_SPAWN_RATE = 15000; // ms
240
+ const POWERUP_DURATION = 10000; // ms
241
+
242
+ // Game variables
243
+ let score = 0;
244
+ let health = 100;
245
+ let gameOver = false;
246
+ let gameStarted = false;
247
+ let lastEnemySpawn = 0;
248
+ let lastPowerupSpawn = 0;
249
+ let powerupsActive = {
250
+ tripleShot: false,
251
+ rapidFire: false,
252
+ shield: false
253
+ };
254
+
255
+ // DOM elements
256
+ const canvas = document.getElementById('gameCanvas');
257
+ const ctx = canvas.getContext('2d');
258
+ const scoreDisplay = document.getElementById('scoreDisplay');
259
+ const healthFill = document.getElementById('healthFill');
260
+ const startScreen = document.getElementById('startScreen');
261
+ const gameOverScreen = document.getElementById('gameOverScreen');
262
+ const startBtn = document.getElementById('startBtn');
263
+ const restartBtn = document.getElementById('restartBtn');
264
+ const finalScore = document.getElementById('finalScore');
265
+ const powerupsContainer = document.getElementById('powerups');
266
+
267
+ // Audio elements
268
+ const laserSound = document.getElementById('laserSound');
269
+ const explosionSound = document.getElementById('explosionSound');
270
+ const powerupSound = document.getElementById('powerupSound');
271
+ const backgroundMusic = document.getElementById('backgroundMusic');
272
+
273
+ // Set canvas size
274
+ canvas.width = GAME_WIDTH;
275
+ canvas.height = GAME_HEIGHT;
276
+
277
+ // Game objects
278
+ const player = {
279
+ x: GAME_WIDTH / 2,
280
+ y: GAME_HEIGHT - 100,
281
+ width: PLAYER_WIDTH,
282
+ height: PLAYER_HEIGHT,
283
+ speed: 8,
284
+ color: '#0ff',
285
+ bullets: [],
286
+ lastShot: 0,
287
+ shootDelay: 500, // ms
288
+ isAlive: true
289
+ };
290
+
291
+ const enemies = [];
292
+ const powerups = [];
293
+ const explosions = [];
294
+
295
+ // Keyboard state
296
+ const keys = {
297
+ ArrowLeft: false,
298
+ ArrowRight: false,
299
+ ArrowUp: false,
300
+ ArrowDown: false,
301
+ Space: false
302
+ };
303
+
304
+ // Event listeners
305
+ window.addEventListener('resize', () => {
306
+ canvas.width = window.innerWidth;
307
+ canvas.height = window.innerHeight;
308
+ player.y = canvas.height - 100;
309
+ });
310
+
311
+ document.addEventListener('keydown', (e) => {
312
+ if (keys.hasOwnProperty(e.key)) {
313
+ keys[e.key] = true;
314
+ e.preventDefault();
315
+ }
316
+ });
317
+
318
+ document.addEventListener('keyup', (e) => {
319
+ if (keys.hasOwnProperty(e.key)) {
320
+ keys[e.key] = false;
321
+ e.preventDefault();
322
+ }
323
+ });
324
+
325
+ startBtn.addEventListener('click', startGame);
326
+ restartBtn.addEventListener('click', startGame);
327
+
328
+ function startGame() {
329
+ // Reset game state
330
+ score = 0;
331
+ health = 100;
332
+ gameOver = false;
333
+ gameStarted = true;
334
+ player.isAlive = true;
335
+ player.bullets = [];
336
+ enemies.length = 0;
337
+ powerups.length = 0;
338
+ explosions.length = 0;
339
+ powerupsActive = {
340
+ tripleShot: false,
341
+ rapidFire: false,
342
+ shield: false
343
+ };
344
+ updatePowerupDisplay();
345
+
346
+ // Clear powerups container
347
+ while (powerupsContainer.firstChild) {
348
+ powerupsContainer.removeChild(powerupsContainer.firstChild);
349
+ }
350
+
351
+ // Reset player position
352
+ player.x = canvas.width / 2;
353
+ player.y = canvas.height - 100;
354
+ player.lastShot = 0;
355
+
356
+ // Reset UI
357
+ scoreDisplay.textContent = `SCORE: ${score}`;
358
+ healthFill.style.width = '100%';
359
+
360
+ // Hide screens
361
+ startScreen.style.display = 'none';
362
+ gameOverScreen.style.display = 'none';
363
+
364
+ // Start game loop
365
+ requestAnimationFrame(gameLoop);
366
+
367
+ // Start background music
368
+ backgroundMusic.volume = 0.3;
369
+ backgroundMusic.play().catch(e => console.log("Audio play failed:", e));
370
+ }
371
+
372
+ function gameLoop(timestamp) {
373
+ if (gameOver) {
374
+ endGame();
375
+ return;
376
+ }
377
+
378
+ // Clear canvas
379
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
380
+
381
+ // Spawn enemies
382
+ if (timestamp - lastEnemySpawn > ENEMY_SPAWN_RATE) {
383
+ spawnEnemy();
384
+ lastEnemySpawn = timestamp;
385
+
386
+ // Increase spawn rate as score increases
387
+ ENEMY_SPAWN_RATE = Math.max(500, 2000 - Math.floor(score / 10) * 50);
388
+ }
389
+
390
+ // Spawn powerups
391
+ if (timestamp - lastPowerupSpawn > POWERUP_SPAWN_RATE) {
392
+ spawnPowerup();
393
+ lastPowerupSpawn = timestamp;
394
+ }
395
+
396
+ // Update player
397
+ updatePlayer();
398
+
399
+ // Update bullets
400
+ updateBullets();
401
+
402
+ // Update enemies
403
+ updateEnemies();
404
+
405
+ // Update powerups
406
+ updatePowerups();
407
+
408
+ // Update explosions
409
+ updateExplosions();
410
+
411
+ // Draw player
412
+ drawPlayer();
413
+
414
+ // Draw bullets
415
+ drawBullets();
416
+
417
+ // Draw enemies
418
+ drawEnemies();
419
+
420
+ // Draw powerups
421
+ drawPowerups();
422
+
423
+ // Draw explosions
424
+ drawExplosions();
425
+
426
+ // Continue game loop
427
+ requestAnimationFrame(gameLoop);
428
+ }
429
+
430
+ function spawnEnemy() {
431
+ const size = Math.random() * 30 + 30;
432
+ const x = Math.random() * (canvas.width - size);
433
+ const y = -size;
434
+ const speed = Math.random() * 3 + 1;
435
+ const health = Math.floor(Math.random() * 2) + 1;
436
+
437
+ enemies.push({
438
+ x: x,
439
+ y: y,
440
+ width: size,
441
+ height: size,
442
+ speed: speed,
443
+ health: health,
444
+ origX: x,
445
+ movePattern: Math.random() > 0.5 ? 'straight' : 'zigzag',
446
+ zigzagSpeed: Math.random() * 0.1,
447
+ zigzagAmplitude: Math.random() * 100 + 50
448
+ });
449
+ }
450
+
451
+ function spawnPowerup() {
452
+ const x = Math.random() * (canvas.width - POWERUP_SIZE);
453
+ const y = -POWERUP_SIZE;
454
+ const types = ['tripleShot', 'rapidFire', 'shield'];
455
+ const type = types[Math.floor(Math.random() * types.length)];
456
+
457
+ powerups.push({
458
+ x: x,
459
+ y: y,
460
+ width: POWERUP_SIZE,
461
+ height: POWERUP_SIZE,
462
+ speed: 3,
463
+ type: type
464
+ });
465
+ }
466
+
467
+ function updatePlayer() {
468
+ // Movement
469
+ if (keys.ArrowLeft && player.x > 0) {
470
+ player.x -= player.speed;
471
+ }
472
+ if (keys.ArrowRight && player.x < canvas.width - player.width) {
473
+ player.x += player.speed;
474
+ }
475
+ if (keys.ArrowUp && player.y > canvas.height / 2) {
476
+ player.y -= player.speed;
477
+ }
478
+ if (keys.ArrowDown && player.y < canvas.height - player.height) {
479
+ player.y += player.speed;
480
+ }
481
+
482
+ // Shooting
483
+ if (keys.Space && Date.now() - player.lastShot > (powerupsActive.rapidFire ? 100 : player.shootDelay)) {
484
+ shoot();
485
+ player.lastShot = Date.now();
486
+ }
487
+ }
488
+
489
+ function shoot() {
490
+ if (powerupsActive.tripleShot) {
491
+ // Three spread shots
492
+ player.bullets.push({
493
+ x: player.x + player.width / 2 - BULLET_SIZE / 2,
494
+ y: player.y,
495
+ width: BULLET_SIZE,
496
+ height: BULLET_SIZE,
497
+ speed: -10,
498
+ angle: -0.1
499
+ });
500
+ player.bullets.push({
501
+ x: player.x + player.width / 2 - BULLET_SIZE / 2,
502
+ y: player.y,
503
+ width: BULLET_SIZE,
504
+ height: BULLET_SIZE,
505
+ speed: -10,
506
+ angle: 0
507
+ });
508
+ player.bullets.push({
509
+ x: player.x + player.width / 2 - BULLET_SIZE / 2,
510
+ y: player.y,
511
+ width: BULLET_SIZE,
512
+ height: BULLET_SIZE,
513
+ speed: -10,
514
+ angle: 0.1
515
+ });
516
+ } else {
517
+ // Single shot
518
+ player.bullets.push({
519
+ x: player.x + player.width / 2 - BULLET_SIZE / 2,
520
+ y: player.y,
521
+ width: BULLET_SIZE,
522
+ height: BULLET_SIZE,
523
+ speed: -10,
524
+ angle: 0
525
+ });
526
+ }
527
+
528
+ // Play laser sound
529
+ laserSound.currentTime = 0;
530
+ laserSound.play().catch(e => console.log("Audio play failed:", e));
531
+ }
532
+
533
+ function updateBullets() {
534
+ for (let i = player.bullets.length - 1; i >= 0; i--) {
535
+ const bullet = player.bullets[i];
536
+ bullet.y += bullet.speed;
537
+ if (bullet.angle !== 0) {
538
+ bullet.x += Math.sin(bullet.angle) * 5;
539
+ }
540
+
541
+ // Remove bullets that go off screen
542
+ if (bullet.y + bullet.height < 0) {
543
+ player.bullets.splice(i, 1);
544
+ }
545
+ }
546
+ }
547
+
548
+ function updateEnemies() {
549
+ for (let i = enemies.length - 1; i >= 0; i--) {
550
+ const enemy = enemies[i];
551
+
552
+ // Update position based on movement pattern
553
+ if (enemy.movePattern === 'straight') {
554
+ enemy.y += enemy.speed;
555
+ } else if (enemy.movePattern === 'zigzag') {
556
+ enemy.y += enemy.speed;
557
+ enemy.x = enemy.origX + Math.sin(enemy.y * enemy.zigzagSpeed) * enemy.zigzagAmplitude;
558
+ }
559
+
560
+ // Check if enemy hits player
561
+ if (
562
+ player.isAlive &&
563
+ enemy.y + enemy.height > player.y &&
564
+ enemy.y < player.y + player.height &&
565
+ enemy.x + enemy.width > player.x &&
566
+ enemy.x < player.x + player.width
567
+ ) {
568
+ takeDamage(10);
569
+ // Create explosion at enemy position
570
+ createExplosion(enemy.x + enemy.width/2, enemy.y + enemy.height/2, enemy.width * 1.5);
571
+ enemies.splice(i, 1);
572
+
573
+ // Play explosion sound
574
+ explosionSound.currentTime = 0;
575
+ explosionSound.play().catch(e => console.log("Audio play failed:", e));
576
+ continue;
577
+ }
578
+
579
+ // Remove enemies that go off screen
580
+ if (enemy.y > canvas.height) {
581
+ enemies.splice(i, 1);
582
+ continue;
583
+ }
584
+
585
+ // Check bullet collisions
586
+ for (let j = player.bullets.length - 1; j >= 0; j--) {
587
+ const bullet = player.bullets[j];
588
+
589
+ if (
590
+ bullet.y + bullet.height > enemy.y &&
591
+ bullet.y < enemy.y + enemy.height &&
592
+ bullet.x + bullet.width > enemy.x &&
593
+ bullet.x < enemy.x + enemy.width
594
+ ) {
595
+ // Hit detected
596
+ enemy.health--;
597
+
598
+ if (enemy.health <= 0) {
599
+ // Enemy destroyed
600
+ score += 10;
601
+ scoreDisplay.textContent = `SCORE: ${score}`;
602
+ enemies.splice(i, 1);
603
+ createExplosion(enemy.x + enemy.width/2, enemy.y + enemy.height/2, enemy.width);
604
+
605
+ // Play explosion sound
606
+ explosionSound.currentTime = 0;
607
+ explosionSound.play().catch(e => console.log("Audio play failed:", e));
608
+ }
609
+
610
+ player.bullets.splice(j, 1);
611
+ break;
612
+ }
613
+ }
614
+ }
615
+ }
616
+
617
+ function updatePowerups() {
618
+ for (let i = powerups.length - 1; i >= 0; i--) {
619
+ const powerup = powerups[i];
620
+ powerup.y += powerup.speed;
621
+
622
+ // Check if player collects powerup
623
+ if (
624
+ player.isAlive &&
625
+ powerup.y + powerup.height > player.y &&
626
+ powerup.y < player.y + player.height &&
627
+ powerup.x + powerup.width > player.x &&
628
+ powerup.x < player.x + player.width
629
+ ) {
630
+ activatePowerup(powerup.type);
631
+ powerups.splice(i, 1);
632
+
633
+ // Play powerup sound
634
+ powerupSound.currentTime = 0;
635
+ powerupSound.play().catch(e => console.log("Audio play failed:", e));
636
+ continue;
637
+ }
638
+
639
+ // Remove powerups that go off screen
640
+ if (powerup.y > canvas.height) {
641
+ powerups.splice(i, 1);
642
+ }
643
+ }
644
+
645
+ // Check if powerups should expire
646
+ const now = Date.now();
647
+ for (const type in powerupsActive) {
648
+ if (powerupsActive[type] && now - powerupsActive[type] > POWERUP_DURATION) {
649
+ powerupsActive[type] = false;
650
+ updatePowerupDisplay();
651
+ }
652
+ }
653
+ }
654
+
655
+ function activatePowerup(type) {
656
+ powerupsActive[type] = Date.now();
657
+ updatePowerupDisplay();
658
+
659
+ // Display powerup notification
660
+ const notification = document.createElement('div');
661
+ notification.className = 'powerup-notification';
662
+ notification.textContent = type === 'tripleShot' ? 'TRIPLE SHOT ACTIVATED' :
663
+ type === 'rapidFire' ? 'RAPID FIRE ACTIVATED' :
664
+ 'SHIELD ACTIVATED';
665
+ notification.style.position = 'absolute';
666
+ notification.style.left = '50%';
667
+ notification.style.top = '30%';
668
+ notification.style.transform = 'translateX(-50%)';
669
+ notification.style.color = '#ff0';
670
+ notification.style.fontSize = '24px';
671
+ notification.style.textShadow = '0 0 10px #ff0';
672
+ notification.style.opacity = '0';
673
+ notification.style.transition = 'opacity 1s';
674
+
675
+ document.getElementById('uiOverlay').appendChild(notification);
676
+
677
+ // Fade in
678
+ setTimeout(() => {
679
+ notification.style.opacity = '1';
680
+ }, 10);
681
+
682
+ // Fade out and remove
683
+ setTimeout(() => {
684
+ notification.style.opacity = '0';
685
+ setTimeout(() => {
686
+ notification.remove();
687
+ }, 1000);
688
+ }, 3000);
689
+ }
690
+
691
+ function updatePowerupDisplay() {
692
+ // Clear existing icons
693
+ powerupsContainer.innerHTML = '';
694
+
695
+ // Add icons for active powerups
696
+ for (const type in powerupsActive) {
697
+ if (powerupsActive[type]) {
698
+ const icon = document.createElement('div');
699
+ icon.className = 'powerup-icon';
700
+ icon.textContent = type === 'tripleShot' ? '3x' :
701
+ type === 'rapidFire' ? 'RF' :
702
+ 'S';
703
+ icon.title = type === 'tripleShot' ? 'Triple Shot' :
704
+ type === 'rapidFire' ? 'Rapid Fire' :
705
+ 'Shield';
706
+
707
+ // Add progress bar
708
+ const progress = document.createElement('div');
709
+ progress.style.position = 'absolute';
710
+ progress.style.bottom = '-5px';
711
+ progress.style.left = '0';
712
+ progress.style.width = '100%';
713
+ progress.style.height = '3px';
714
+ progress.style.backgroundColor = '#ff0';
715
+ progress.style.transformOrigin = 'left center';
716
+
717
+ // Calculate remaining time
718
+ const durationLeft = Math.max(0, POWERUP_DURATION - (Date.now() - powerupsActive[type]));
719
+ const percentageLeft = (durationLeft / POWERUP_DURATION) * 100;
720
+ progress.style.transform = `scaleX(${percentageLeft / 100})`;
721
+
722
+ icon.appendChild(progress);
723
+ powerupsContainer.appendChild(icon);
724
+
725
+ // Update progress bar
726
+ const interval = setInterval(() => {
727
+ const timeLeft = Math.max(0, POWERUP_DURATION - (Date.now() - powerupsActive[type]));
728
+ const percentage = (timeLeft / POWERUP_DURATION) * 100;
729
+ progress.style.transform = `scaleX(${percentage / 100})`;
730
+
731
+ if (timeLeft <= 0) {
732
+ clearInterval(interval);
733
+ }
734
+ }, 100);
735
+ }
736
+ }
737
+ }
738
+
739
+ function createExplosion(x, y, radius) {
740
+ explosions.push({
741
+ x: x,
742
+ y: y,
743
+ radius: radius,
744
+ maxRadius: radius * 1.5,
745
+ alpha: 1,
746
+ life: 1
747
+ });
748
+ }
749
+
750
+ function updateExplosions() {
751
+ for (let i = explosions.length - 1; i >= 0; i--) {
752
+ const explosion = explosions[i];
753
+ explosion.radius += 0.5;
754
+ explosion.life -= 0.02;
755
+
756
+ if (explosion.life <= 0) {
757
+ explosions.splice(i, 1);
758
+ }
759
+ }
760
+ }
761
+
762
+ function takeDamage(amount) {
763
+ if (powerupsActive.shield) return;
764
+
765
+ health = Math.max(0, health - amount);
766
+ healthFill.style.width = `${health}%`;
767
+
768
+ if (health <= 0) {
769
+ player.isAlive = false;
770
+ gameOver = true;
771
+ createExplosion(player.x + player.width/2, player.y + player.height/2, player.width * 2);
772
+ }
773
+ }
774
+
775
+ function drawPlayer() {
776
+ if (!player.isAlive) return;
777
+
778
+ // Draw ship body
779
+ ctx.fillStyle = player.color;
780
+ ctx.beginPath();
781
+ ctx.moveTo(player.x + player.width/2, player.y);
782
+ ctx.lineTo(player.x + player.width, player.y + player.height);
783
+ ctx.lineTo(player.x, player.y + player.height);
784
+ ctx.closePath();
785
+ ctx.fill();
786
+
787
+ // Draw cockpit
788
+ ctx.fillStyle = '#0af';
789
+ ctx.beginPath();
790
+ ctx.arc(player.x + player.width/2, player.y + player.height/2, player.width/4, 0, Math.PI * 2);
791
+ ctx.fill();
792
+
793
+ // Draw engine glow
794
+ if (Date.now() % 200 < 100) {
795
+ ctx.fillStyle = '#f80';
796
+ ctx.beginPath();
797
+ ctx.moveTo(player.x + player.width/3, player.y + player.height);
798
+ ctx.lineTo(player.x + player.width/2, player.y + player.height + 10);
799
+ ctx.lineTo(player.x + 2*player.width/3, player.y + player.height);
800
+ ctx.closePath();
801
+ ctx.fill();
802
+ }
803
+
804
+ // Draw shield if active
805
+ if (powerupsActive.shield) {
806
+ ctx.strokeStyle = '#0ff';
807
+ ctx.lineWidth = 2;
808
+ ctx.beginPath();
809
+ ctx.arc(player.x + player.width/2, player.y + player.height/2, player.width, 0, Math.PI * 2);
810
+ ctx.stroke();
811
+
812
+ ctx.strokeStyle = '#0ff';
813
+ ctx.lineWidth = 1;
814
+ ctx.beginPath();
815
+ ctx.arc(player.x + player.width/2, player.y + player.height/2, player.width * 1.3, 0, Math.PI * 2);
816
+ ctx.stroke();
817
+ }
818
+ }
819
+
820
+ function drawBullets() {
821
+ ctx.fillStyle = '#ff0';
822
+ for (const bullet of player.bullets) {
823
+ ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
824
+
825
+ // Add trail effect
826
+ ctx.fillStyle = 'rgba(255, 255, 0, 0.5)';
827
+ ctx.fillRect(bullet.x, bullet.y + bullet.height, bullet.width, bullet.height/2);
828
+ ctx.fillStyle = '#ff0';
829
+ }
830
+ }
831
+
832
+ function drawEnemies() {
833
+ for (const enemy of enemies) {
834
+ // Different colors for different health levels
835
+ ctx.fillStyle = enemy.health === 2 ? '#f60' : '#f06';
836
+
837
+ // Draw alien ship
838
+ ctx.beginPath();
839
+ ctx.moveTo(enemy.x + enemy.width/2, enemy.y);
840
+ ctx.lineTo(enemy.x + enemy.width, enemy.y + enemy.height);
841
+ ctx.lineTo(enemy.x, enemy.y + enemy.height);
842
+ ctx.closePath();
843
+ ctx.fill();
844
+
845
+ // Draw alien markings
846
+ if (enemy.health === 2) {
847
+ ctx.strokeStyle = '#0f0';
848
+ ctx.lineWidth = 2;
849
+ ctx.beginPath();
850
+ ctx.moveTo(enemy.x + enemy.width/3, enemy.y + enemy.height/2);
851
+ ctx.lineTo(enemy.x + 2*enemy.width/3, enemy.y + enemy.height/2);
852
+ ctx.stroke();
853
+ }
854
+
855
+ // Draw glow effect
856
+ ctx.fillStyle = 'rgba(255, 0, 0, 0.2)';
857
+ ctx.beginPath();
858
+ ctx.arc(enemy.x + enemy.width/2, enemy.y + enemy.height/2, enemy.width * 0.8, 0, Math.PI * 2);
859
+ ctx.fill();
860
+ }
861
+ }
862
+
863
+ function drawPowerups() {
864
+ for (const powerup of powerups) {
865
+ let color;
866
+ let symbol;
867
+
868
+ if (powerup.type === 'tripleShot') {
869
+ color = '#0f0';
870
+ symbol = '3x';
871
+ } else if (powerup.type === 'rapidFire') {
872
+ color = '#00f';
873
+ symbol = 'RF';
874
+ } else {
875
+ color = '#0ff';
876
+ symbol = 'S';
877
+ }
878
+
879
+ // Draw powerup background
880
+ ctx.fillStyle = color;
881
+ ctx.beginPath();
882
+ ctx.arc(powerup.x + powerup.width/2, powerup.y + powerup.height/2, powerup.width/2, 0, Math.PI * 2);
883
+ ctx.fill();
884
+
885
+ // Draw symbol
886
+ ctx.fillStyle = '#000';
887
+ ctx.font = 'bold 12px Orbitron';
888
+ ctx.textAlign = 'center';
889
+ ctx.textBaseline = 'middle';
890
+ ctx.fillText(symbol, powerup.x + powerup.width/2, powerup.y + powerup.height/2);
891
+
892
+ // Add pulsing glow effect
893
+ const pulse = Math.sin(Date.now() / 200) * 0.3 + 0.7;
894
+ ctx.strokeStyle = `rgba(${color === '#0f0' ? '0,255,0' : color === '#00f' ? '0,0,255' : '0,255,255'},${pulse})`;
895
+ ctx.lineWidth = 2;
896
+ ctx.beginPath();
897
+ ctx.arc(powerup.x + powerup.width/2, powerup.y + powerup.height/2, powerup.width/2 + 2, 0, Math.PI * 2);
898
+ ctx.stroke();
899
+ }
900
+ }
901
+
902
+ function drawExplosions() {
903
+ for (const explosion of explosions) {
904
+ const gradient = ctx.createRadialGradient(
905
+ explosion.x,
906
+ explosion.y,
907
+ 0,
908
+ explosion.x,
909
+ explosion.y,
910
+ explosion.radius
911
+ );
912
+
913
+ gradient.addColorStop(0, `rgba(255, 255, 0, ${explosion.life})`);
914
+ gradient.addColorStop(0.5, `rgba(255, 100, 0, ${explosion.life * 0.7})`);
915
+ gradient.addColorStop(1, `rgba(255, 0, 0, 0)`);
916
+
917
+ ctx.beginPath();
918
+ ctx.fillStyle = gradient;
919
+ ctx.arc(explosion.x, explosion.y, explosion.radius, 0, Math.PI * 2);
920
+ ctx.fill();
921
+
922
+ // Add secondary explosion ring
923
+ if (explosion.life > 0.5) {
924
+ const outerRadius = explosion.radius * 1.5;
925
+ const outerAlpha = (explosion.life - 0.5) * 2;
926
+
927
+ const outerGradient = ctx.createRadialGradient(
928
+ explosion.x,
929
+ explosion.y,
930
+ 0,
931
+ explosion.x,
932
+ explosion.y,
933
+ outerRadius
934
+ );
935
+
936
+ outerGradient.addColorStop(0, `rgba(255, 255, 255, ${outerAlpha})`);
937
+ outerGradient.addColorStop(1, `rgba(255, 255, 255, 0)`);
938
+
939
+ ctx.beginPath();
940
+ ctx.fillStyle = outerGradient;
941
+ ctx.arc(explosion.x, explosion.y, outerRadius, 0, Math.PI * 2);
942
+ ctx.fill();
943
+ }
944
+ }
945
+ }
946
+
947
+ function endGame() {
948
+ gameOver = true;
949
+ gameOverScreen.style.display = 'flex';
950
+ finalScore.textContent = `SCORE: ${score}`;
951
+ backgroundMusic.pause();
952
+ backgroundMusic.currentTime = 0;
953
+ }
954
+ </script>
955
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <a href="https://enzostvs-deepsite.hf.space" style="color: #fff;" target="_blank" >DeepSite</a> <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;"></p></body>
956
+ </html>