Agung1453 commited on
Commit
1bdf6cd
·
verified ·
1 Parent(s): bd7d0ed

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +660 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Space Impact
3
- emoji: 🚀
4
- colorFrom: gray
5
  colorTo: blue
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: space-impact
3
+ emoji: 🐳
4
+ colorFrom: purple
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,660 @@
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
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Autopilot Space Impact</title>
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <style>
10
+ @keyframes scrollBackground {
11
+ 0% {
12
+ background-position: 0 0;
13
+ }
14
+
15
+ 100% {
16
+ background-position: -2048px 0;
17
+ }
18
+ }
19
+
20
+ .game-container {
21
+ position: relative;
22
+ width: 100%;
23
+ height: 100vh;
24
+ overflow: hidden;
25
+ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect width="64" height="64" fill="%2311141a"/><circle cx="8" cy="8" r="1" fill="%233d4554" opacity="0.6"/><circle cx="32" cy="16" r="1" fill="%233d4554" opacity="0.6"/><circle cx="56" cy="8" r="1" fill="%233d4554" opacity="0.6"/><circle cx="20" cy="40" r="1" fill="%233d4554" opacity="0.6"/><circle cx="44" cy="32" r="1" fill="%233d4554" opacity="0.6"/><circle cx="16" cy="56" r="1" fill="%233d4554" opacity="0.6"/><circle cx="40" cy="56" r="1" fill="%233d4554" opacity="0.6"/></svg>');
26
+ animation: scrollBackground 120s linear infinite;
27
+ }
28
+
29
+ .player {
30
+ position: absolute;
31
+ width: 40px;
32
+ height: 40px;
33
+ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><polygon points="0,20 10,10 10,30" fill="%2366f7ff"/><polygon points="10,10 40,20 10,30" fill="%2366f7ff" opacity="0.8"/><polygon points="30,20 40,15 40,25" fill="%23fff" opacity="0.6"/></svg>');
34
+ background-size: contain;
35
+ transition: top 0.2s ease-out;
36
+ z-index: 10;
37
+ }
38
+
39
+ .bullet {
40
+ position: absolute;
41
+ width: 8px;
42
+ height: 3px;
43
+ background-color: cyan;
44
+ border-radius: 2px;
45
+ box-shadow: 0 0 5px cyan;
46
+ }
47
+
48
+ .enemy {
49
+ position: absolute;
50
+ width: 40px;
51
+ height: 40px;
52
+ background-size: contain;
53
+ background-repeat: no-repeat;
54
+ }
55
+
56
+ .explosion {
57
+ position: absolute;
58
+ width: 50px;
59
+ height: 50px;
60
+ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><circle cx="25" cy="25" r="25" fill="%23ff8c00"/><circle cx="25" cy="25" r="20" fill="%23ffcc00"/><circle cx="25" cy="25" r="15" fill="%23fff"/></svg>');
61
+ background-size: contain;
62
+ animation: fadeOut 0.5s forwards;
63
+ z-index: 20;
64
+ }
65
+
66
+ @keyframes fadeOut {
67
+ to {
68
+ opacity: 0;
69
+ transform: scale(1.5);
70
+ }
71
+ }
72
+
73
+ #gameOverOverlay {
74
+ position: absolute;
75
+ top: 0;
76
+ left: 0;
77
+ width: 100%;
78
+ height: 100%;
79
+ background-color: rgba(0, 0, 0, 0.7);
80
+ display: none;
81
+ flex-direction: column;
82
+ justify-content: center;
83
+ align-items: center;
84
+ z-index: 100;
85
+ }
86
+
87
+ #gameOverOverlay h2 {
88
+ color: white;
89
+ font-size: 3rem;
90
+ margin-bottom: 2rem;
91
+ text-shadow: 0 0 10px red;
92
+ }
93
+
94
+ #restartBtn {
95
+ padding: 1rem 2rem;
96
+ background: linear-gradient(to right, #4facfe, #00f2fe);
97
+ border: none;
98
+ border-radius: 5px;
99
+ color: white;
100
+ font-weight: bold;
101
+ cursor: pointer;
102
+ transition: transform 0.2s;
103
+ }
104
+
105
+ #restartBtn:hover {
106
+ transform: scale(1.1);
107
+ }
108
+ </style>
109
+ </head>
110
+
111
+ <body class="bg-gray-900 text-white">
112
+ <div class="container mx-auto">
113
+ <div class="flex justify-between items-center p-4">
114
+ <h1 class="text-2xl font-bold">Autopilot Space Impact</h1>
115
+ <div id="score" class="text-xl">Score: 0</div>
116
+ </div>
117
+ <div class="flex gap-4 p-4">
118
+ <div id="lives" class="flex gap-2">
119
+ <div class="w-8 h-8 bg-red-500 rounded-full"></div>
120
+ <div class="w-8 h-8 bg-red-500 rounded-full"></div>
121
+ <div class="w-8 h-8 bg-red-500 rounded-full"></div>
122
+ </div>
123
+ <div id="level" class="text-xl">Level: 1</div>
124
+ </div>
125
+ </div>
126
+
127
+ <div class="game-container" id="gameContainer">
128
+ <div class="player" id="player"></div>
129
+ <div id="gameOverOverlay">
130
+ <h2>GAME OVER</h2>
131
+ <button id="restartBtn">Play Again</button>
132
+ </div>
133
+ </div>
134
+
135
+ <script>
136
+ // Game constants
137
+ const PLAYER_SPEED = 2;
138
+ const BULLET_SPEED = 10;
139
+ const ENEMY_SPEED = 3;
140
+ const ENEMY_SPAWN_RATE = 1000; // ms
141
+ const POWERUP_SPAWN_RATE = 8000; // ms
142
+
143
+ // Game variables
144
+ let score = 0;
145
+ let lives = 3;
146
+ let level = 1;
147
+ let gameOver = false;
148
+ let gameLoop;
149
+ let enemySpawnLoop;
150
+ let powerupSpawnLoop;
151
+
152
+ // DOM elements
153
+ const gameContainer = document.getElementById('gameContainer');
154
+ const player = document.getElementById('player');
155
+ const scoreDisplay = document.getElementById('score');
156
+ const livesDisplay = document.getElementById('lives');
157
+ const levelDisplay = document.getElementById('level');
158
+ const gameOverOverlay = document.getElementById('gameOverOverlay');
159
+ const restartBtn = document.getElementById('restartBtn');
160
+
161
+ // Game state
162
+ let bullets = [];
163
+ let enemies = [];
164
+ let powerups = [];
165
+ let explosions = [];
166
+ let moveDirection = 0; // -1 for up, 0 for none, 1 for down
167
+ let lastSpawnTime = 0;
168
+ let lastEnemySpawnTime = 0;
169
+ let lastPowerupSpawnTime = 0;
170
+
171
+ // Screen dimensions
172
+ const screenWidth = window.innerWidth;
173
+ const screenHeight = window.innerHeight;
174
+
175
+ // Initialize player position
176
+ function initPlayer() {
177
+ player.style.left = '50px';
178
+ player.style.top = `${screenHeight / 2 - 20}px`;
179
+ }
180
+
181
+ // Initialize game
182
+ function initGame() {
183
+ // Reset game state
184
+ score = 0;
185
+ lives = 3;
186
+ level = 1;
187
+ gameOver = false;
188
+ bullets = [];
189
+ enemies = [];
190
+ powerups = [];
191
+ explosions = [];
192
+
193
+ // Update UI
194
+ scoreDisplay.textContent = `Score: ${score}`;
195
+ levelDisplay.textContent = `Level: ${level}`;
196
+ livesDisplay.innerHTML = '<div class="w-8 h-8 bg-red-500 rounded-full"></div>'.repeat(lives);
197
+
198
+ // Clear existing game elements
199
+ document.querySelectorAll('.bullet').forEach(el => el.remove());
200
+ document.querySelectorAll('.enemy').forEach(el => el.remove());
201
+ document.querySelectorAll('.powerup').forEach(el => el.remove());
202
+ document.querySelectorAll('.explosion').forEach(el => el.remove());
203
+
204
+ // Initialize player
205
+ initPlayer();
206
+
207
+ // Hide game over overlay
208
+ gameOverOverlay.style.display = 'none';
209
+
210
+ // Start game loops
211
+ startGameLoops();
212
+ }
213
+
214
+ // Start game loops
215
+ function startGameLoops() {
216
+ if (gameLoop) clearInterval(gameLoop);
217
+ if (enemySpawnLoop) clearInterval(enemySpawnLoop);
218
+ if (powerupSpawnLoop) clearInterval(powerupSpawnLoop);
219
+
220
+ gameLoop = setInterval(updateGame, 16); // ~60fps
221
+ enemySpawnLoop = setInterval(spawnEnemy, ENEMY_SPAWN_RATE);
222
+ powerupSpawnLoop = setInterval(spawnPowerup, POWERUP_SPAWN_RATE);
223
+ }
224
+
225
+ // Spawn enemy
226
+ function spawnEnemy() {
227
+ if (gameOver) return;
228
+
229
+ const now = Date.now();
230
+ if (now - lastEnemySpawnTime < ENEMY_SPAWN_RATE / level) return;
231
+ lastEnemySpawnTime = now;
232
+
233
+ const enemyType = Math.random() < 0.2 ? 'strong' : 'weak';
234
+ const enemySize = enemyType === 'strong' ? 50 : 40;
235
+ const enemyHeight = Math.random() * (screenHeight - enemySize);
236
+
237
+ const enemy = document.createElement('div');
238
+ enemy.className = 'enemy';
239
+ enemy.dataset.type = enemyType;
240
+ enemy.style.left = `${screenWidth}px`;
241
+ enemy.style.top = `${enemyHeight}px`;
242
+
243
+ if (enemyType === 'strong') {
244
+ enemy.style.backgroundImage = 'url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><polygon points="50,25 10,0 10,10 0,10 0,40 10,40 10,50" fill="%23ff3355"/><circle cx="30" cy="25" r="15" fill="%23e63946"/><circle cx="30" cy="25" r="10" fill="%23ff758f"/></svg>\')';
245
+ } else {
246
+ enemy.style.backgroundImage = 'url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><polygon points="0,20 10,10 10,30" fill="%23ff5555"/></svg>\')';
247
+ }
248
+
249
+ gameContainer.appendChild(enemy);
250
+ enemies.push({
251
+ element: enemy,
252
+ x: screenWidth,
253
+ y: enemyHeight,
254
+ width: enemySize,
255
+ height: enemySize,
256
+ type: enemyType,
257
+ health: enemyType === 'strong' ? 3 : 1,
258
+ lastShot: 0,
259
+ canShoot: Math.random() < 0.3
260
+ });
261
+ }
262
+
263
+ // Spawn powerup (occasionally)
264
+ function spawnPowerup() {
265
+ if (gameOver || Math.random() > 0.3) return;
266
+
267
+ const now = Date.now();
268
+ if (now - lastPowerupSpawnTime < POWERUP_SPAWN_RATE * 3) return;
269
+ lastPowerupSpawnTime = now;
270
+
271
+ const powerupHeight = Math.random() * (screenHeight - 30);
272
+
273
+ const powerup = document.createElement('div');
274
+ powerup.className = 'powerup';
275
+ powerup.style.left = `${screenWidth}px`;
276
+ powerup.style.top = `${powerupHeight}px`;
277
+ powerup.style.width = '30px';
278
+ powerup.style.height = '30px';
279
+ powerup.style.backgroundImage = 'url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30"><circle cx="15" cy="15" r="15" fill="%23ffcc00"/><polygon points="15,5 19,15 15,25 11,15" fill="%23e63946"/></svg>\')';
280
+
281
+ gameContainer.appendChild(powerup);
282
+ powerups.push({
283
+ element: powerup,
284
+ x: screenWidth,
285
+ y: powerupHeight,
286
+ width: 30,
287
+ height: 30
288
+ });
289
+ }
290
+
291
+ // Fire bullet
292
+ function fireBullet() {
293
+ const playerRect = player.getBoundingClientRect();
294
+ const bulletX = playerRect.right;
295
+ const bulletY = playerRect.top + playerRect.height / 2 - 1.5;
296
+
297
+ const bullet = document.createElement('div');
298
+ bullet.className = 'bullet';
299
+ bullet.style.left = `${bulletX}px`;
300
+ bullet.style.top = `${bulletY}px`;
301
+
302
+ gameContainer.appendChild(bullet);
303
+ bullets.push({
304
+ element: bullet,
305
+ x: bulletX,
306
+ y: bulletY,
307
+ width: 8,
308
+ height: 3,
309
+ speed: BULLET_SPEED
310
+ });
311
+ }
312
+
313
+ // Enemy fire bullet
314
+ function enemyFireBullet(enemy) {
315
+ const enemyRect = enemy.element.getBoundingClientRect();
316
+ const bulletX = enemyRect.left;
317
+ const bulletY = enemyRect.top + enemyRect.height / 2 - 1.5;
318
+
319
+ const bullet = document.createElement('div');
320
+ bullet.className = 'bullet';
321
+ bullet.style.left = `${bulletX}px`;
322
+ bullet.style.top = `${bulletY}px`;
323
+ bullet.style.backgroundColor = 'red';
324
+ bullet.style.boxShadow = '0 0 5px red';
325
+
326
+ gameContainer.appendChild(bullet);
327
+ bullets.push({
328
+ element: bullet,
329
+ x: bulletX,
330
+ y: bulletY,
331
+ width: 8,
332
+ height: 3,
333
+ speed: -BULLET_SPEED,
334
+ fromEnemy: true
335
+ });
336
+
337
+ enemy.lastShot = Date.now();
338
+ }
339
+
340
+ // Auto pilot logic
341
+ function autoPilot() {
342
+ const playerRect = player.getBoundingClientRect();
343
+ const playerX = playerRect.left;
344
+ const playerY = playerRect.top;
345
+ const playerWidth = playerRect.width;
346
+ const playerHeight = playerRect.height;
347
+
348
+ // Find closest enemy in front
349
+ let closestEnemyInPath = null;
350
+ let minDistance = Infinity;
351
+
352
+ for (const enemy of enemies) {
353
+ // Check if enemy is in front and roughly at same height
354
+ if (enemy.x > playerX &&
355
+ enemy.x - playerX < 300 && // Only consider enemies within certain distance
356
+ Math.abs(enemy.y + enemy.height / 2 - (playerY + playerHeight / 2)) < 100) {
357
+
358
+ const distance = enemy.x - playerX;
359
+ if (distance < minDistance) {
360
+ minDistance = distance;
361
+ closestEnemyInPath = enemy;
362
+ }
363
+ }
364
+ }
365
+
366
+ // Find closest bullet coming towards us
367
+ let closestEnemyBullet = null;
368
+ let bulletMinDistance = Infinity;
369
+
370
+ for (const bullet of bullets) {
371
+ if (bullet.fromEnemy) {
372
+ const distance = bullet.x - playerX;
373
+ if (distance < 300 && distance < bulletMinDistance &&
374
+ bullet.y + bullet.height > playerY && bullet.y < playerY + playerHeight) {
375
+ bulletMinDistance = distance;
376
+ closestEnemyBullet = bullet;
377
+ }
378
+ }
379
+ }
380
+
381
+ // Decision logic
382
+ if (closestEnemyBullet) {
383
+ // If bullet is above center, move down, else move up
384
+ const bulletCenterY = closestEnemyBullet.y + closestEnemyBullet.height / 2;
385
+ const playerCenterY = playerY + playerHeight / 2;
386
+
387
+ moveDirection = bulletCenterY < playerCenterY ? 1 : -1; // Move opposite to bullet
388
+ } else if (closestEnemyInPath) {
389
+ // Enemy is in path, avoid if too close
390
+ if (minDistance < 200) {
391
+ const enemyCenterY = closestEnemyInPath.y + closestEnemyInPath.height / 2;
392
+ const playerCenterY = playerY + playerHeight / 2;
393
+
394
+ moveDirection = enemyCenterY < playerCenterY ? 1 : -1; // Move opposite to enemy
395
+ } else {
396
+ // Enemy is far enough, aim to shoot
397
+ moveDirection = 0;
398
+
399
+ // If not currently moving, shoot at the enemy
400
+ if (Math.random() < 0.07) { // Limit firing rate
401
+ fireBullet();
402
+ }
403
+ }
404
+ } else {
405
+ // No immediate threat, random small movements
406
+ if (Math.random() < 0.05) {
407
+ moveDirection = Math.random() < 0.5 ? -1 : 1;
408
+ }
409
+
410
+ // Sometimes stop moving
411
+ if (Math.random() < 0.1) {
412
+ moveDirection = 0;
413
+ }
414
+
415
+ // Sometimes fire randomly
416
+ if (Math.random() < 0.03) {
417
+ fireBullet();
418
+ }
419
+ }
420
+
421
+ // Ensure we don't go out of bounds
422
+ if (moveDirection === -1 && playerY <= 0) {
423
+ moveDirection = 1;
424
+ } else if (moveDirection === 1 && playerY >= screenHeight - playerHeight) {
425
+ moveDirection = -1;
426
+ }
427
+ }
428
+
429
+ // Create explosion
430
+ function createExplosion(x, y) {
431
+ const explosion = document.createElement('div');
432
+ explosion.className = 'explosion';
433
+ explosion.style.left = `${x - 25}px`;
434
+ explosion.style.top = `${y - 25}px`;
435
+
436
+ gameContainer.appendChild(explosion);
437
+ explosions.push({
438
+ element: explosion,
439
+ time: Date.now()
440
+ });
441
+ }
442
+
443
+ // Check collisions
444
+ function checkCollisions() {
445
+ const playerRect = player.getBoundingClientRect();
446
+ const playerX = playerRect.left;
447
+ const playerY = playerRect.top;
448
+ const playerWidth = playerRect.width;
449
+ const playerHeight = playerRect.height;
450
+
451
+ // Check player collision with enemies
452
+ for (let i = enemies.length - 1; i >= 0; i--) {
453
+ const enemy = enemies[i];
454
+
455
+ if (playerX < enemy.x + enemy.width &&
456
+ playerX + playerWidth > enemy.x &&
457
+ playerY < enemy.y + enemy.height &&
458
+ playerY + playerHeight > enemy.y) {
459
+
460
+ // Collision detected
461
+ createExplosion(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2);
462
+ enemy.element.remove();
463
+ enemies.splice(i, 1);
464
+
465
+ decreaseLife();
466
+ continue;
467
+ }
468
+ }
469
+
470
+ // Check player collision with enemy bullets
471
+ for (let i = bullets.length - 1; i >= 0; i--) {
472
+ const bullet = bullets[i];
473
+
474
+ if (bullet.fromEnemy &&
475
+ playerX < bullet.x + bullet.width &&
476
+ playerX + playerWidth > bullet.x &&
477
+ playerY < bullet.y + bullet.height &&
478
+ playerY + playerHeight > bullet.y) {
479
+
480
+ // Collision detected
481
+ createExplosion(bullet.x, bullet.y);
482
+ bullet.element.remove();
483
+ bullets.splice(i, 1);
484
+
485
+ decreaseLife();
486
+ }
487
+ }
488
+
489
+ // Check player collision with powerups
490
+ for (let i = powerups.length - 1; i >= 0; i--) {
491
+ const powerup = powerups[i];
492
+
493
+ if (playerX < powerup.x + powerup.width &&
494
+ playerX + playerWidth > powerup.x &&
495
+ playerY < powerup.y + powerup.height &&
496
+ playerY + playerHeight > powerup.y) {
497
+
498
+ // Powerup collected
499
+ powerup.element.remove();
500
+ powerups.splice(i, 1);
501
+
502
+ increaseLife();
503
+ }
504
+ }
505
+
506
+ // Check bullet collisions with enemies
507
+ for (let i = bullets.length - 1; i >= 0; i--) {
508
+ const bullet = bullets[i];
509
+
510
+ if (bullet.fromEnemy) continue;
511
+
512
+ for (let j = enemies.length - 1; j >= 0; j--) {
513
+ const enemy = enemies[j];
514
+
515
+ if (bullet.x < enemy.x + enemy.width &&
516
+ bullet.x + bullet.width > enemy.x &&
517
+ bullet.y < enemy.y + enemy.height &&
518
+ bullet.y + bullet.height > enemy.y) {
519
+
520
+ // Hit enemy
521
+ createExplosion(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2);
522
+ enemy.health--;
523
+
524
+ if (enemy.health <= 0) {
525
+ enemy.element.remove();
526
+ enemies.splice(j, 1);
527
+ score += enemy.type === 'strong' ? 20 : 10;
528
+ scoreDisplay.textContent = `Score: ${score}`;
529
+
530
+ // Level up every 100 points
531
+ if (score >= level * 100) {
532
+ level++;
533
+ levelDisplay.textContent = `Level: ${level}`;
534
+ }
535
+ }
536
+
537
+ bullet.element.remove();
538
+ bullets.splice(i, 1);
539
+ break;
540
+ }
541
+ }
542
+ }
543
+ }
544
+
545
+ // Decrease player life
546
+ function decreaseLife() {
547
+ if (gameOver) return;
548
+
549
+ lives--;
550
+ livesDisplay.innerHTML = '<div class="w-8 h-8 bg-red-500 rounded-full"></div>'.repeat(lives);
551
+
552
+ if (lives <= 0) {
553
+ gameOver = true;
554
+ gameOverOverlay.style.display = 'flex';
555
+ clearInterval(gameLoop);
556
+ clearInterval(enemySpawnLoop);
557
+ clearInterval(powerupSpawnLoop);
558
+ }
559
+ }
560
+
561
+ // Increase player life
562
+ function increaseLife() {
563
+ if (lives < 5) { // Max 5 lives
564
+ lives++;
565
+ livesDisplay.innerHTML += '<div class="w-8 h-8 bg-red-500 rounded-full"></div>';
566
+ }
567
+ }
568
+
569
+ // Update game state
570
+ function updateGame() {
571
+ if (gameOver) return;
572
+
573
+ const now = Date.now();
574
+
575
+ // Handle auto-pilot
576
+ autoPilot();
577
+
578
+ // Move player based on autopilot decision
579
+ const playerTop = parseInt(player.style.top) || 0;
580
+ const newPlayerTop = playerTop + moveDirection * PLAYER_SPEED;
581
+
582
+ // Keep player within bounds
583
+ if (newPlayerTop >= 0 && newPlayerTop <= screenHeight - 40) {
584
+ player.style.top = `${newPlayerTop}px`;
585
+ }
586
+
587
+ // Move bullets
588
+ for (let i = bullets.length - 1; i >= 0; i--) {
589
+ const bullet = bullets[i];
590
+ bullet.x += bullet.speed;
591
+ bullet.element.style.left = `${bullet.x}px`;
592
+
593
+ // Remove bullets that go off screen
594
+ if (bullet.x > screenWidth || bullet.x < -bullet.width) {
595
+ bullet.element.remove();
596
+ bullets.splice(i, 1);
597
+ }
598
+ }
599
+
600
+ // Move enemies and have them shoot
601
+ for (let i = enemies.length - 1; i >= 0; i--) {
602
+ const enemy = enemies[i];
603
+ enemy.x -= ENEMY_SPEED * level * 0.5; // Enemies get faster with level
604
+ enemy.element.style.left = `${enemy.x}px`;
605
+
606
+ // Enemy shooting logic
607
+ if (enemy.canShoot && now - enemy.lastShot > 2000 && Math.random() < 0.02) {
608
+ enemyFireBullet(enemy);
609
+ }
610
+
611
+ // Remove enemies that go off screen
612
+ if (enemy.x < -enemy.width) {
613
+ enemy.element.remove();
614
+ enemies.splice(i, 1);
615
+ }
616
+ }
617
+
618
+ // Move powerups
619
+ for (let i = powerups.length - 1; i >= 0; i--) {
620
+ const powerup = powerups[i];
621
+ powerup.x -= 2;
622
+ powerup.element.style.left = `${powerup.x}px`;
623
+
624
+ // Remove powerups that go off screen
625
+ if (powerup.x < -powerup.width) {
626
+ powerup.element.remove();
627
+ powerups.splice(i, 1);
628
+ }
629
+ }
630
+
631
+ // Remove old explosions
632
+ for (let i = explosions.length - 1; i >= 0; i--) {
633
+ const explosion = explosions[i];
634
+ if (now - explosion.time > 500) {
635
+ explosion.element.remove();
636
+ explosions.splice(i, 1);
637
+ }
638
+ }
639
+
640
+ // Check collisions
641
+ checkCollisions();
642
+ }
643
+
644
+ // Start game on load
645
+ window.addEventListener('load', initGame);
646
+
647
+ // Restart game button
648
+ restartBtn.addEventListener('click', initGame);
649
+
650
+ // Handle window resize
651
+ window.addEventListener('resize', () => {
652
+ // Reinitialize player position to keep it visible
653
+ const playerRect = player.getBoundingClientRect();
654
+ const newY = Math.min(Math.max(playerRect.top, 0), screenHeight - playerRect.height);
655
+ player.style.top = `${newY}px`;
656
+ });
657
+ </script>
658
+ <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 <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Agung1453/space-impact" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
659
+
660
+ </html>