SignorNessuno commited on
Commit
42d0306
·
verified ·
1 Parent(s): 92df7f4

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +693 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Spaxa
3
- emoji: 💻
4
- colorFrom: indigo
5
- colorTo: pink
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: spaxa
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,693 @@
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>Space Battle 2D</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ overflow: hidden;
11
+ background-color: #000;
12
+ font-family: 'Arial', sans-serif;
13
+ touch-action: none;
14
+ }
15
+
16
+ #gameContainer {
17
+ position: relative;
18
+ width: 100vw;
19
+ height: 100vh;
20
+ }
21
+
22
+ #gameCanvas {
23
+ background-color: #000;
24
+ display: block;
25
+ background-image: radial-gradient(circle at center, #111 0%, #000 100%);
26
+ position: absolute;
27
+ top: 0;
28
+ left: 0;
29
+ }
30
+
31
+ #uiContainer {
32
+ position: absolute;
33
+ top: 0;
34
+ left: 0;
35
+ width: 100%;
36
+ height: 100%;
37
+ pointer-events: none;
38
+ }
39
+
40
+ .health-bar {
41
+ position: absolute;
42
+ top: 20px;
43
+ height: 30px;
44
+ border: 2px solid #fff;
45
+ border-radius: 5px;
46
+ overflow: hidden;
47
+ }
48
+
49
+ #player1Health {
50
+ left: 20px;
51
+ width: 200px;
52
+ }
53
+
54
+ #player2Health {
55
+ right: 20px;
56
+ width: 200px;
57
+ }
58
+
59
+ .health-fill {
60
+ height: 100%;
61
+ transition: width 0.3s;
62
+ }
63
+
64
+ #player1Health .health-fill {
65
+ background: linear-gradient(to right, #f00, #f80);
66
+ }
67
+
68
+ #player2Health .health-fill {
69
+ background: linear-gradient(to right, #0af, #08f);
70
+ }
71
+
72
+ #timer {
73
+ position: absolute;
74
+ top: 20px;
75
+ left: 50%;
76
+ transform: translateX(-50%);
77
+ color: #fff;
78
+ font-size: 24px;
79
+ text-shadow: 0 0 5px #0ff;
80
+ }
81
+
82
+ #startScreen {
83
+ position: absolute;
84
+ top: 0;
85
+ left: 0;
86
+ width: 100%;
87
+ height: 100%;
88
+ background-color: rgba(0, 0, 0, 0.8);
89
+ display: flex;
90
+ flex-direction: column;
91
+ justify-content: center;
92
+ align-items: center;
93
+ color: white;
94
+ z-index: 10;
95
+ }
96
+
97
+ #startButton {
98
+ margin-top: 20px;
99
+ padding: 15px 30px;
100
+ font-size: 20px;
101
+ background: linear-gradient(to right, #f80, #f00);
102
+ border: none;
103
+ border-radius: 10px;
104
+ color: white;
105
+ cursor: pointer;
106
+ transition: transform 0.2s;
107
+ }
108
+
109
+ #startButton:hover {
110
+ transform: scale(1.05);
111
+ }
112
+
113
+ .controls {
114
+ margin-top: 30px;
115
+ text-align: center;
116
+ background-color: rgba(0, 0, 0, 0.5);
117
+ padding: 15px;
118
+ border-radius: 10px;
119
+ max-width: 80%;
120
+ }
121
+
122
+ .player-controls {
123
+ display: inline-block;
124
+ margin: 0 20px;
125
+ vertical-align: top;
126
+ }
127
+
128
+ #gameOverScreen {
129
+ position: absolute;
130
+ top: 0;
131
+ left: 0;
132
+ width: 100%;
133
+ height: 100%;
134
+ background-color: rgba(0, 0, 0, 0.8);
135
+ display: none;
136
+ flex-direction: column;
137
+ justify-content: center;
138
+ align-items: center;
139
+ color: white;
140
+ z-index: 10;
141
+ }
142
+
143
+ #winnerText {
144
+ font-size: 36px;
145
+ margin-bottom: 20px;
146
+ text-shadow: 0 0 10px #0ff;
147
+ }
148
+
149
+ #restartButton {
150
+ margin-top: 20px;
151
+ padding: 15px 30px;
152
+ font-size: 20px;
153
+ background: linear-gradient(to right, #0af, #08f);
154
+ border: none;
155
+ border-radius: 10px;
156
+ color: white;
157
+ cursor: pointer;
158
+ transition: transform 0.2s;
159
+ }
160
+
161
+ #restartButton:hover {
162
+ transform: scale(1.05);
163
+ }
164
+
165
+ .mobile-controls {
166
+ position: absolute;
167
+ bottom: 20px;
168
+ width: 100%;
169
+ display: none;
170
+ justify-content: space-between;
171
+ padding: 0 20px;
172
+ box-sizing: border-box;
173
+ }
174
+
175
+ .mobile-joystick {
176
+ width: 100px;
177
+ height: 100px;
178
+ background-color: rgba(255, 255, 255, 0.2);
179
+ border-radius: 50%;
180
+ position: relative;
181
+ }
182
+
183
+ .mobile-fire {
184
+ width: 80px;
185
+ height: 80px;
186
+ background-color: rgba(255, 0, 0, 0.5);
187
+ border-radius: 50%;
188
+ display: flex;
189
+ justify-content: center;
190
+ align-items: center;
191
+ font-size: 24px;
192
+ color: white;
193
+ }
194
+
195
+ @media (max-width: 768px) {
196
+ .mobile-controls {
197
+ display: flex;
198
+ }
199
+
200
+ .controls {
201
+ display: none;
202
+ }
203
+ }
204
+ </style>
205
+ </head>
206
+ <body>
207
+ <div id="gameContainer">
208
+ <canvas id="gameCanvas"></canvas>
209
+
210
+ <div id="uiContainer">
211
+ <div id="player1Health" class="health-bar">
212
+ <div class="health-fill" style="width: 100%"></div>
213
+ </div>
214
+
215
+ <div id="player2Health" class="health-bar">
216
+ <div class="health-fill" style="width: 100%"></div>
217
+ </div>
218
+
219
+ <div id="timer">02:00</div>
220
+
221
+ <div class="mobile-controls">
222
+ <div class="mobile-joystick" id="player1Joystick"></div>
223
+ <div class="mobile-fire" id="player1Fire">FIRE</div>
224
+ </div>
225
+ </div>
226
+
227
+ <div id="startScreen">
228
+ <h1>SPACE BATTLE</h1>
229
+ <p>Defeat your opponent before time runs out!</p>
230
+
231
+ <div class="controls">
232
+ <div class="player-controls">
233
+ <h3>Player 1 (Red)</h3>
234
+ <p>Move: WASD</p>
235
+ <p>Fire: Space</p>
236
+ </div>
237
+
238
+ <div class="player-controls">
239
+ <h3>Player 2 (Blue)</h3>
240
+ <p>Move: Arrow Keys</p>
241
+ <p>Fire: Enter</p>
242
+ </div>
243
+ </div>
244
+
245
+ <button id="startButton">START BATTLE</button>
246
+ </div>
247
+
248
+ <div id="gameOverScreen">
249
+ <h1>GAME OVER</h1>
250
+ <div id="winnerText"></div>
251
+ <button id="restartButton">PLAY AGAIN</button>
252
+ </div>
253
+ </div>
254
+
255
+ <script>
256
+ // Game setup
257
+ const canvas = document.getElementById('gameCanvas');
258
+ const ctx = canvas.getContext('2d');
259
+ const startScreen = document.getElementById('startScreen');
260
+ const startButton = document.getElementById('startButton');
261
+ const gameOverScreen = document.getElementById('gameOverScreen');
262
+ const restartButton = document.getElementById('restartButton');
263
+ const winnerText = document.getElementById('winnerText');
264
+ const timerElement = document.getElementById('timer');
265
+ const player1HealthFill = document.querySelector('#player1Health .health-fill');
266
+ const player2HealthFill = document.querySelector('#player2Health .health-fill');
267
+
268
+ // Set canvas size
269
+ function resizeCanvas() {
270
+ canvas.width = window.innerWidth;
271
+ canvas.height = window.innerHeight;
272
+ }
273
+
274
+ window.addEventListener('resize', resizeCanvas);
275
+ resizeCanvas();
276
+
277
+ // Game state
278
+ let gameRunning = false;
279
+ let gameTime = 120; // 2 minutes in seconds
280
+ let lastTime = 0;
281
+
282
+ // Players
283
+ const players = {
284
+ player1: {
285
+ x: 200,
286
+ y: canvas.height / 2,
287
+ width: 40,
288
+ height: 30,
289
+ color: '#f80',
290
+ speed: 5,
291
+ health: 100,
292
+ maxHealth: 100,
293
+ lastShot: 0,
294
+ shotCooldown: 500, // ms
295
+ keys: {
296
+ up: 'w',
297
+ down: 's',
298
+ left: 'a',
299
+ right: 'd',
300
+ fire: ' '
301
+ },
302
+ activeKeys: {
303
+ up: false,
304
+ down: false,
305
+ left: false,
306
+ right: false
307
+ }
308
+ },
309
+ player2: {
310
+ x: canvas.width - 200,
311
+ y: canvas.height / 2,
312
+ width: 40,
313
+ height: 30,
314
+ color: '#08f',
315
+ speed: 5,
316
+ health: 100,
317
+ maxHealth: 100,
318
+ lastShot: 0,
319
+ shotCooldown: 500, // ms
320
+ keys: {
321
+ up: 'ArrowUp',
322
+ down: 'ArrowDown',
323
+ left: 'ArrowLeft',
324
+ right: 'ArrowRight',
325
+ fire: 'Enter'
326
+ },
327
+ activeKeys: {
328
+ up: false,
329
+ down: false,
330
+ left: false,
331
+ right: false
332
+ }
333
+ }
334
+ };
335
+
336
+ // Projectiles
337
+ const projectiles = [];
338
+ const projectileSpeed = 10;
339
+ const projectileSize = 5;
340
+
341
+ // Stars for background
342
+ const stars = [];
343
+ for (let i = 0; i < 100; i++) {
344
+ stars.push({
345
+ x: Math.random() * canvas.width,
346
+ y: Math.random() * canvas.height,
347
+ size: Math.random() * 2,
348
+ opacity: Math.random()
349
+ });
350
+ }
351
+
352
+ // Input handling
353
+ const keysPressed = {};
354
+
355
+ window.addEventListener('keydown', (e) => {
356
+ keysPressed[e.key] = true;
357
+
358
+ // Check player 1 controls
359
+ if (e.key === players.player1.keys.up) players.player1.activeKeys.up = true;
360
+ if (e.key === players.player1.keys.down) players.player1.activeKeys.down = true;
361
+ if (e.key === players.player1.keys.left) players.player1.activeKeys.left = true;
362
+ if (e.key === players.player1.keys.right) players.player1.activeKeys.right = true;
363
+
364
+ // Check player 2 controls
365
+ if (e.key === players.player2.keys.up) players.player2.activeKeys.up = true;
366
+ if (e.key === players.player2.keys.down) players.player2.activeKeys.down = true;
367
+ if (e.key === players.player2.keys.left) players.player2.activeKeys.left = true;
368
+ if (e.key === players.player2.keys.right) players.player2.activeKeys.right = true;
369
+
370
+ // Fire controls
371
+ if (gameRunning) {
372
+ const now = Date.now();
373
+ if (e.key === players.player1.keys.fire && now - players.player1.lastShot > players.player1.shotCooldown) {
374
+ fireProjectile(players.player1);
375
+ players.player1.lastShot = now;
376
+ }
377
+
378
+ if (e.key === players.player2.keys.fire && now - players.player2.lastShot > players.player2.shotCooldown) {
379
+ fireProjectile(players.player2);
380
+ players.player2.lastShot = now;
381
+ }
382
+ }
383
+ });
384
+
385
+ window.addEventListener('keyup', (e) => {
386
+ keysPressed[e.key] = false;
387
+
388
+ // Check player 1 controls
389
+ if (e.key === players.player1.keys.up) players.player1.activeKeys.up = false;
390
+ if (e.key === players.player1.keys.down) players.player1.activeKeys.down = false;
391
+ if (e.key === players.player1.keys.left) players.player1.activeKeys.left = false;
392
+ if (e.key === players.player1.keys.right) players.player1.activeKeys.right = false;
393
+
394
+ // Check player 2 controls
395
+ if (e.key === players.player2.keys.up) players.player2.activeKeys.up = false;
396
+ if (e.key === players.player2.keys.down) players.player2.activeKeys.down = false;
397
+ if (e.key === players.player2.keys.left) players.player2.activeKeys.left = false;
398
+ if (e.key === players.player2.keys.right) players.player2.activeKeys.right = false;
399
+ });
400
+
401
+ // Mobile touch controls
402
+ const player1Joystick = document.getElementById('player1Joystick');
403
+ const player1Fire = document.getElementById('player1Fire');
404
+ let joystickActive = false;
405
+ let joystickStartX = 0;
406
+ let joystickStartY = 0;
407
+ let joystickX = 0;
408
+ let joystickY = 0;
409
+
410
+ player1Joystick.addEventListener('touchstart', (e) => {
411
+ const rect = player1Joystick.getBoundingClientRect();
412
+ joystickStartX = rect.left + rect.width / 2;
413
+ joystickStartY = rect.top + rect.height / 2;
414
+ joystickActive = true;
415
+ handleJoystickMove(e.touches[0]);
416
+ e.preventDefault();
417
+ });
418
+
419
+ document.addEventListener('touchmove', (e) => {
420
+ if (joystickActive) {
421
+ handleJoystickMove(e.touches[0]);
422
+ e.preventDefault();
423
+ }
424
+ });
425
+
426
+ document.addEventListener('touchend', () => {
427
+ joystickActive = false;
428
+ players.player1.activeKeys.up = false;
429
+ players.player1.activeKeys.down = false;
430
+ players.player1.activeKeys.left = false;
431
+ players.player1.activeKeys.right = false;
432
+ });
433
+
434
+ player1Fire.addEventListener('touchstart', (e) => {
435
+ const now = Date.now();
436
+ if (now - players.player1.lastShot > players.player1.shotCooldown) {
437
+ fireProjectile(players.player1);
438
+ players.player1.lastShot = now;
439
+ }
440
+ e.preventDefault();
441
+ });
442
+
443
+ function handleJoystickMove(touch) {
444
+ if (!joystickActive) return;
445
+
446
+ const dx = touch.clientX - joystickStartX;
447
+ const dy = touch.clientY - joystickStartY;
448
+ const distance = Math.sqrt(dx * dx + dy * dy);
449
+ const maxDistance = 50;
450
+
451
+ if (distance > maxDistance) {
452
+ joystickX = (dx / distance) * maxDistance;
453
+ joystickY = (dy / distance) * maxDistance;
454
+ } else {
455
+ joystickX = dx;
456
+ joystickY = dy;
457
+ }
458
+
459
+ // Update player controls based on joystick position
460
+ const threshold = 20;
461
+ players.player1.activeKeys.up = joystickY < -threshold;
462
+ players.player1.activeKeys.down = joystickY > threshold;
463
+ players.player1.activeKeys.left = joystickX < -threshold;
464
+ players.player1.activeKeys.right = joystickX > threshold;
465
+ }
466
+
467
+ // Projectile functions
468
+ function fireProjectile(player) {
469
+ const direction = player === players.player1 ? 1 : -1;
470
+ projectiles.push({
471
+ x: player.x + (player.width / 2 * direction),
472
+ y: player.y,
473
+ width: projectileSize,
474
+ height: projectileSize,
475
+ speed: projectileSpeed * direction,
476
+ color: player.color,
477
+ owner: player === players.player1 ? 'player1' : 'player2'
478
+ });
479
+ }
480
+
481
+ // Collision detection
482
+ function checkCollisions() {
483
+ for (let i = projectiles.length - 1; i >= 0; i--) {
484
+ const proj = projectiles[i];
485
+
486
+ // Check if projectile is out of bounds
487
+ if (proj.x < 0 || proj.x > canvas.width) {
488
+ projectiles.splice(i, 1);
489
+ continue;
490
+ }
491
+
492
+ // Check collision with player 1
493
+ if (proj.owner === 'player2' &&
494
+ proj.x < players.player1.x + players.player1.width &&
495
+ proj.x + proj.width > players.player1.x &&
496
+ proj.y < players.player1.y + players.player1.height &&
497
+ proj.y + proj.height > players.player1.y) {
498
+
499
+ players.player1.health -= 10;
500
+ player1HealthFill.style.width = `${(players.player1.health / players.player1.maxHealth) * 100}%`;
501
+ projectiles.splice(i, 1);
502
+
503
+ if (players.player1.health <= 0) {
504
+ endGame('Player 2 (Blue)');
505
+ }
506
+ continue;
507
+ }
508
+
509
+ // Check collision with player 2
510
+ if (proj.owner === 'player1' &&
511
+ proj.x < players.player2.x + players.player2.width &&
512
+ proj.x + proj.width > players.player2.x &&
513
+ proj.y < players.player2.y + players.player2.height &&
514
+ proj.y + proj.height > players.player2.y) {
515
+
516
+ players.player2.health -= 10;
517
+ player2HealthFill.style.width = `${(players.player2.health / players.player2.maxHealth) * 100}%`;
518
+ projectiles.splice(i, 1);
519
+
520
+ if (players.player2.health <= 0) {
521
+ endGame('Player 1 (Red)');
522
+ }
523
+ }
524
+ }
525
+ }
526
+
527
+ // Game control functions
528
+ function startGame() {
529
+ gameRunning = true;
530
+ gameTime = 120;
531
+ lastTime = Date.now();
532
+ startScreen.style.display = 'none';
533
+ gameOverScreen.style.display = 'none';
534
+
535
+ // Reset players
536
+ players.player1.x = 200;
537
+ players.player1.y = canvas.height / 2;
538
+ players.player1.health = 100;
539
+ player1HealthFill.style.width = '100%';
540
+
541
+ players.player2.x = canvas.width - 200;
542
+ players.player2.y = canvas.height / 2;
543
+ players.player2.health = 100;
544
+ player2HealthFill.style.width = '100%';
545
+
546
+ // Clear projectiles
547
+ projectiles.length = 0;
548
+
549
+ // Start game loop
550
+ requestAnimationFrame(gameLoop);
551
+ }
552
+
553
+ function endGame(winner) {
554
+ gameRunning = false;
555
+ winnerText.textContent = `${winner} Wins!`;
556
+ gameOverScreen.style.display = 'flex';
557
+ }
558
+
559
+ function updateTimer() {
560
+ const now = Date.now();
561
+ const delta = (now - lastTime) / 1000;
562
+ lastTime = now;
563
+
564
+ if (gameRunning) {
565
+ gameTime -= delta;
566
+
567
+ if (gameTime <= 0) {
568
+ gameTime = 0;
569
+ gameRunning = false;
570
+
571
+ if (players.player1.health > players.player2.health) {
572
+ endGame('Player 1 (Red)');
573
+ } else if (players.player2.health > players.player1.health) {
574
+ endGame('Player 2 (Blue)');
575
+ } else {
576
+ endGame('Draw!');
577
+ }
578
+ }
579
+
580
+ const minutes = Math.floor(gameTime / 60);
581
+ const seconds = Math.floor(gameTime % 60);
582
+ timerElement.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
583
+ }
584
+ }
585
+
586
+ // Drawing functions
587
+ function drawBackground() {
588
+ ctx.fillStyle = '#000';
589
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
590
+
591
+ // Draw stars
592
+ ctx.save();
593
+ stars.forEach(star => {
594
+ ctx.fillStyle = `rgba(255, 255, 255, ${star.opacity})`;
595
+ ctx.beginPath();
596
+ ctx.arc(star.x, star.y, star.size, 0, Math.PI * 2);
597
+ ctx.fill();
598
+
599
+ // Move stars for parallax effect
600
+ star.y += 0.5;
601
+ if (star.y > canvas.height) {
602
+ star.y = 0;
603
+ star.x = Math.random() * canvas.width;
604
+ }
605
+ });
606
+ ctx.restore();
607
+ }
608
+
609
+ function drawPlayers() {
610
+ // Player 1
611
+ ctx.save();
612
+ ctx.fillStyle = players.player1.color;
613
+ ctx.translate(players.player1.x, players.player1.y);
614
+ ctx.beginPath();
615
+ ctx.moveTo(players.player1.width, players.player1.height / 2);
616
+ ctx.lineTo(0, 0);
617
+ ctx.lineTo(0, players.player1.height);
618
+ ctx.closePath();
619
+ ctx.fill();
620
+ ctx.restore();
621
+
622
+ // Player 2
623
+ ctx.save();
624
+ ctx.fillStyle = players.player2.color;
625
+ ctx.translate(players.player2.x, players.player2.y);
626
+ ctx.beginPath();
627
+ ctx.moveTo(0, players.player2.height / 2);
628
+ ctx.lineTo(players.player2.width, 0);
629
+ ctx.lineTo(players.player2.width, players.player2.height);
630
+ ctx.closePath();
631
+ ctx.fill();
632
+ ctx.restore();
633
+ }
634
+
635
+ function drawProjectiles() {
636
+ projectiles.forEach(proj => {
637
+ ctx.fillStyle = proj.color;
638
+ ctx.fillRect(proj.x, proj.y, proj.width, proj.height);
639
+ });
640
+ }
641
+
642
+ // Game loop
643
+ function gameLoop() {
644
+ if (!gameRunning) return;
645
+
646
+ // Update game state
647
+ updateTimer();
648
+ updatePlayers();
649
+ updateProjectiles();
650
+ checkCollisions();
651
+
652
+ // Draw everything
653
+ drawBackground();
654
+ drawPlayers();
655
+ drawProjectiles();
656
+
657
+ // Continue the game loop
658
+ requestAnimationFrame(gameLoop);
659
+ }
660
+
661
+ function updatePlayers() {
662
+ // Player 1 movement
663
+ if (players.player1.activeKeys.up) players.player1.y -= players.player1.speed;
664
+ if (players.player1.activeKeys.down) players.player1.y += players.player1.speed;
665
+ if (players.player1.activeKeys.left) players.player1.x -= players.player1.speed;
666
+ if (players.player1.activeKeys.right) players.player1.x += players.player1.speed;
667
+
668
+ // Player 2 movement
669
+ if (players.player2.activeKeys.up) players.player2.y -= players.player2.speed;
670
+ if (players.player2.activeKeys.down) players.player2.y += players.player2.speed;
671
+ if (players.player2.activeKeys.left) players.player2.x -= players.player2.speed;
672
+ if (players.player2.activeKeys.right) players.player2.x += players.player2.speed;
673
+
674
+ // Keep players within bounds
675
+ players.player1.x = Math.max(0, Math.min(canvas.width - players.player1.width, players.player1.x));
676
+ players.player1.y = Math.max(0, Math.min(canvas.height - players.player1.height, players.player1.y));
677
+
678
+ players.player2.x = Math.max(0, Math.min(canvas.width - players.player2.width, players.player2.x));
679
+ players.player2.y = Math.max(0, Math.min(canvas.height - players.player2.height, players.player2.y));
680
+ }
681
+
682
+ function updateProjectiles() {
683
+ for (let i = 0; i < projectiles.length; i++) {
684
+ projectiles[i].x += projectiles[i].speed;
685
+ }
686
+ }
687
+
688
+ // Event listeners for buttons
689
+ startButton.addEventListener('click', startGame);
690
+ restartButton.addEventListener('click', startGame);
691
+ </script>
692
+ <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>
693
+ </html>