cutechicken commited on
Commit
62cabf1
·
verified ·
1 Parent(s): ec0a41c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +380 -18
index.html CHANGED
@@ -1,19 +1,381 @@
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>
3
+ <head>
4
+ <style>
5
+ body {
6
+ margin: 0;
7
+ overflow: hidden;
8
+ background: #1a1a1a;
9
+ font-family: Arial;
10
+ }
11
+ #hud {
12
+ position: fixed;
13
+ top: 20px;
14
+ left: 20px;
15
+ color: white;
16
+ }
17
+ #healthBar {
18
+ width: 200px;
19
+ height: 20px;
20
+ background: #333;
21
+ border-radius: 10px;
22
+ overflow: hidden;
23
+ }
24
+ #health {
25
+ width: 100%;
26
+ height: 100%;
27
+ background: #2ecc71;
28
+ transition: width 0.2s;
29
+ }
30
+ #controls {
31
+ position: fixed;
32
+ top: 20px;
33
+ right: 20px;
34
+ color: white;
35
+ background: rgba(0,0,0,0.7);
36
+ padding: 15px;
37
+ border-radius: 5px;
38
+ }
39
+ #round {
40
+ position: fixed;
41
+ top: 20px;
42
+ left: 50%;
43
+ transform: translateX(-50%);
44
+ color: white;
45
+ font-size: 24px;
46
+ }
47
+ #gameOver {
48
+ position: fixed;
49
+ top: 50%;
50
+ left: 50%;
51
+ transform: translate(-50%, -50%);
52
+ background: rgba(0,0,0,0.8);
53
+ color: white;
54
+ padding: 20px;
55
+ border-radius: 10px;
56
+ text-align: center;
57
+ display: none;
58
+ }
59
+ #restart {
60
+ background: #2ecc71;
61
+ border: none;
62
+ color: white;
63
+ padding: 10px 20px;
64
+ border-radius: 5px;
65
+ cursor: pointer;
66
+ margin-top: 10px;
67
+ }
68
+ </style>
69
+ </head>
70
+ <body>
71
+ <canvas id="game"></canvas>
72
+ <div id="hud">
73
+ <div id="healthBar">
74
+ <div id="health"></div>
75
+ </div>
76
+ </div>
77
+ <div id="round">Round 1</div>
78
+ <div id="controls">
79
+ WASD - Move<br>
80
+ Mouse - Aim<br>
81
+ Space - Shoot
82
+ </div>
83
+ <div id="gameOver">
84
+ Game Over!<br>
85
+ <button id="restart" onclick="restartGame()">Restart Game</button>
86
+ </div>
87
+
88
+ <script>
89
+ const canvas = document.getElementById('game');
90
+ const ctx = canvas.getContext('2d');
91
+
92
+ canvas.width = window.innerWidth;
93
+ canvas.height = window.innerHeight;
94
+
95
+ const PLAYER_SIZE = 30;
96
+ const BULLET_SPEED = 10;
97
+ const ENEMY_SPEED = 2;
98
+ const SHOOTING_INTERVAL = 333; // 3 shots per second
99
+
100
+ let game = {
101
+ player: {
102
+ x: canvas.width/2,
103
+ y: canvas.height/2,
104
+ speed: 5,
105
+ health: 1000,
106
+ maxHealth: 1000,
107
+ bullets: [],
108
+ bulletsPerShot: 1
109
+ },
110
+ enemies: [],
111
+ items: [],
112
+ round: 1,
113
+ keys: {},
114
+ mouse: {x: 0, y: 0},
115
+ lastShot: 0,
116
+ shooting: false
117
+ };
118
+
119
+ const gunSound = new Audio('data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YWoGAACBhYqFbF1pbphwX4WqY0J0zGYhdPV3I2vyd5qCvHKTlZJ0j6p+cJGYhIaHmH1li6R9YH6hooCEjaB0f4SOo3yLkZSCeq+bXY/FdWt9tnhcl69yZ5mfdGSSoYKEkZuBdYqgeIKEm4Joe6GJfX+VmnuBjZaFhqmQYY7Hc36QiXd6kpWLgpSieIeQnICEkZeEhJOcfH6Om4GBjZWEgpOYfICLl4OBjZSEgZKYfICKloKBjJODgZGXe3+JlYGAi5KCgJCWen+IlICAfoh+gY2ScICBjX+ChImFhYuJhYeHhoeHh4iIiIiIiIiIiIiIiIiIiIiIiIiHh4aGhYSCgYB/fn18fHx9fn+AgYKEhYeIiYuMjo+RkpSVl5iZmptcW15hZGhrbW5vcHFydHZ4enx+gIKEh4mMj5GSk5OTkpGQjo2LiomIiImKi4yOj5GSlJWXmJqbnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tf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.round * 5;
123
+ for(let i = 0; i < enemyCount; i++) {
124
+ game.enemies.push({
125
+ x: Math.random() * canvas.width,
126
+ y: Math.random() * canvas.height,
127
+ health: 1000,
128
+ maxHealth: 1000,
129
+ bullets: [],
130
+ lastShot: 0,
131
+ direction: {
132
+ x: Math.random() * 2 - 1,
133
+ y: Math.random() * 2 - 1
134
+ }
135
+ });
136
+ }
137
+ }
138
+
139
+ function update() {
140
+ // Player movement
141
+ if(game.keys['w'] && game.player.y > PLAYER_SIZE)
142
+ game.player.y -= game.player.speed;
143
+ if(game.keys['s'] && game.player.y < canvas.height - PLAYER_SIZE)
144
+ game.player.y += game.player.speed;
145
+ if(game.keys['a'] && game.player.x > PLAYER_SIZE)
146
+ game.player.x -= game.player.speed;
147
+ if(game.keys['d'] && game.player.x < canvas.width - PLAYER_SIZE)
148
+ game.player.x += game.player.speed;
149
+
150
+ // Player shooting
151
+ if(game.shooting && Date.now() - game.lastShot > SHOOTING_INTERVAL) {
152
+ const angle = Math.atan2(
153
+ game.mouse.y - game.player.y,
154
+ game.mouse.x - game.player.x
155
+ );
156
+
157
+ for(let i = 0; i < game.player.bulletsPerShot; i++) {
158
+ game.player.bullets.push({
159
+ x: game.player.x,
160
+ y: game.player.y,
161
+ angle: angle + (Math.random() - 0.5) * 0.2
162
+ });
163
+ }
164
+ gunSound.cloneNode().play();
165
+ game.lastShot = Date.now();
166
+ }
167
+
168
+ // Update bullets and check collisions
169
+ for(let i = game.player.bullets.length - 1; i >= 0; i--) {
170
+ const bullet = game.player.bullets[i];
171
+ bullet.x += Math.cos(bullet.angle) * BULLET_SPEED;
172
+ bullet.y += Math.sin(bullet.angle) * BULLET_SPEED;
173
+
174
+ // Remove out of bounds bullets
175
+ if(bullet.x < 0 || bullet.x > canvas.width ||
176
+ bullet.y < 0 || bullet.y > canvas.height) {
177
+ game.player.bullets.splice(i, 1);
178
+ }
179
+
180
+ // Check enemy hits
181
+ for(let j = game.enemies.length - 1; j >= 0; j--) {
182
+ const enemy = game.enemies[j];
183
+ const dx = bullet.x - enemy.x;
184
+ const dy = bullet.y - enemy.y;
185
+ if(Math.sqrt(dx*dx + dy*dy) < PLAYER_SIZE/2) {
186
+ enemy.health -= 100;
187
+ game.player.bullets.splice(i, 1);
188
+ if(enemy.health <= 0) {
189
+ game.enemies.splice(j, 1);
190
+ game.player.bulletsPerShot++;
191
+ // Drop health item
192
+ game.items.push({
193
+ x: enemy.x,
194
+ y: enemy.y,
195
+ type: 'health'
196
+ });
197
+ }
198
+ break;
199
+ }
200
+ }
201
+ }
202
+
203
+ // Update enemies
204
+ game.enemies.forEach(enemy => {
205
+ // Movement
206
+ enemy.x += enemy.direction.x * ENEMY_SPEED;
207
+ enemy.y += enemy.direction.y * ENEMY_SPEED;
208
+
209
+ // Bounce off walls
210
+ if(enemy.x < 0 || enemy.x > canvas.width) enemy.direction.x *= -1;
211
+ if(enemy.y < 0 || enemy.y > canvas.height) enemy.direction.y *= -1;
212
+
213
+ // Shooting
214
+ if(Date.now() - enemy.lastShot > 1000) {
215
+ const angle = Math.atan2(
216
+ game.player.y - enemy.y,
217
+ game.player.x - enemy.x
218
+ );
219
+ enemy.bullets.push({
220
+ x: enemy.x,
221
+ y: enemy.y,
222
+ angle: angle
223
+ });
224
+ enemy.lastShot = Date.now();
225
+ }
226
+
227
+ // Update enemy bullets
228
+ for(let i = enemy.bullets.length - 1; i >= 0; i--) {
229
+ const bullet = enemy.bullets[i];
230
+ bullet.x += Math.cos(bullet.angle) * BULLET_SPEED/2;
231
+ bullet.y += Math.sin(bullet.angle) * BULLET_SPEED/2;
232
+
233
+ // Check player hit
234
+ const dx = bullet.x - game.player.x;
235
+ const dy = bullet.y - game.player.y;
236
+ if(Math.sqrt(dx*dx + dy*dy) < PLAYER_SIZE/2) {
237
+ game.player.health -= 50;
238
+ enemy.bullets.splice(i, 1);
239
+ document.getElementById('health').style.width =
240
+ (game.player.health/game.player.maxHealth * 100) + '%';
241
+
242
+ if(game.player.health <= 0) {
243
+ document.getElementById('gameOver').style.display = 'block';
244
+ }
245
+ }
246
+
247
+ // Remove out of bounds bullets
248
+ if(bullet.x < 0 || bullet.x > canvas.width ||
249
+ bullet.y < 0 || bullet.y > canvas.height) {
250
+ enemy.bullets.splice(i, 1);
251
+ }
252
+ }
253
+ });
254
+
255
+ // Update items
256
+ for(let i = game.items.length - 1; i >= 0; i--) {
257
+ const item = game.items[i];
258
+ const dx = item.x - game.player.x;
259
+ const dy = item.y - game.player.y;
260
+ if(Math.sqrt(dx*dx + dy*dy) < PLAYER_SIZE) {
261
+ game.player.health = Math.min(
262
+ game.player.maxHealth,
263
+ game.player.health + 200
264
+ );
265
+ document.getElementById('health').style.width =
266
+ (game.player.health/game.player.maxHealth * 100) + '%';
267
+ game.items.splice(i, 1);
268
+ }
269
+ }
270
+
271
+ // Check round completion
272
+ if(game.enemies.length === 0) {
273
+ if(game.round < 10) {
274
+ game.round++;
275
+ document.getElementById('round').textContent = `Round ${game.round}`;
276
+ game.player.health = game.player.maxHealth;
277
+ document.getElementById('health').style.width = '100%';
278
+ game.player.bulletsPerShot = 1; // Reset bullets per shot
279
+ spawnEnemies();
280
+ }
281
+ }
282
+ }
283
+
284
+ function draw() {
285
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
286
+
287
+ // Draw player
288
+ ctx.fillStyle = 'white';
289
+ ctx.font = '30px Arial';
290
+ ctx.fillText('🐭', game.player.x - 15, game.player.y + 15);
291
+
292
+ // Draw player bullets
293
+ ctx.fillStyle = 'yellow';
294
+ game.player.bullets.forEach(bullet => {
295
+ ctx.beginPath();
296
+ ctx.arc(bullet.x, bullet.y, 3, 0, Math.PI * 2);
297
+ ctx.fill();
298
+ });
299
+
300
+ // Draw enemies
301
+ game.enemies.forEach(enemy => {
302
+ // Enemy
303
+ ctx.fillStyle = 'white';
304
+ ctx.fillText('🐱', enemy.x - 15, enemy.y + 15);
305
+
306
+ // Health bar
307
+ ctx.fillStyle = '#600';
308
+ ctx.fillRect(enemy.x - 25, enemy.y - 30, 50, 5);
309
+ ctx.fillStyle = '#f00';
310
+ ctx.fillRect(enemy.x - 25, enemy.y - 30,
311
+ (enemy.health/enemy.maxHealth) * 50, 5);
312
+
313
+ // Enemy bullets
314
+ ctx.fillStyle = 'red';
315
+ enemy.bullets.forEach(bullet => {
316
+ ctx.beginPath();
317
+ ctx.arc(bullet.x, bullet.y, 3, 0, Math.PI * 2);
318
+ ctx.fill();
319
+ });
320
+ });
321
+
322
+ // Draw items
323
+ ctx.fillStyle = 'green';
324
+ game.items.forEach(item => {
325
+ ctx.fillText('✚', item.x - 10, item.y + 10);
326
+ });
327
+ }
328
+
329
+ function gameLoop() {
330
+ if(game.player.health > 0) {
331
+ update();
332
+ draw();
333
+ }
334
+ requestAnimationFrame(gameLoop);
335
+ }
336
+
337
+ function restartGame() {
338
+ game = {
339
+ player: {
340
+ x: canvas.width/2,
341
+ y: canvas.height/2,
342
+ speed: 5,
343
+ health: 1000,
344
+ maxHealth: 1000,
345
+ bullets: [],
346
+ bulletsPerShot: 1
347
+ },
348
+ enemies: [],
349
+ items: [],
350
+ round: 1,
351
+ keys: game.keys,
352
+ mouse: game.mouse,
353
+ lastShot: 0,
354
+ shooting: false
355
+ };
356
+ document.getElementById('health').style.width = '100%';
357
+ document.getElementById('round').textContent = 'Round 1';
358
+ document.getElementById('gameOver').style.display = 'none';
359
+ spawnEnemies();
360
+ }
361
+
362
+ // Event listeners
363
+ window.addEventListener('keydown', e => game.keys[e.key] = true);
364
+ window.addEventListener('keyup', e => game.keys[e.key] = false);
365
+ window.addEventListener('mousemove', e => {
366
+ game.mouse.x = e.clientX;
367
+ game.mouse.y = e.clientY;
368
+ });
369
+ window.addEventListener('keydown', e => {
370
+ if(e.code === 'Space') game.shooting = true;
371
+ });
372
+ window.addEventListener('keyup', e => {
373
+ if(e.code === 'Space') game.shooting = false;
374
+ });
375
+
376
+ // Start game
377
+ spawnEnemies();
378
+ gameLoop();
379
+ </script>
380
+ </body>
381
+ </html><script async data-explicit-opt-in="true" data-cookie-opt-in="true" src="https://vercel.live/_next-live/feedback/feedback.js"></script>