cutechicken commited on
Commit
e0225d2
·
verified ·
1 Parent(s): ec04c94

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +18 -32
index.html CHANGED
@@ -95,7 +95,7 @@
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: {
@@ -116,8 +116,6 @@
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/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drbAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+f4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5ebn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8=');
120
-
121
  function spawnEnemies() {
122
  const enemyCount = game.round * 5;
123
  for(let i = 0; i < enemyCount; i++) {
@@ -136,6 +134,13 @@
136
  }
137
  }
138
 
 
 
 
 
 
 
 
139
  function update() {
140
  // Player movement
141
  if(game.keys['w'] && game.player.y > PLAYER_SIZE)
@@ -161,7 +166,6 @@
161
  angle: angle + (Math.random() - 0.5) * 0.2
162
  });
163
  }
164
- gunSound.cloneNode().play();
165
  game.lastShot = Date.now();
166
  }
167
 
@@ -171,13 +175,11 @@
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;
@@ -188,7 +190,6 @@
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,
@@ -202,15 +203,12 @@
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,
@@ -224,13 +222,11 @@
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) {
@@ -244,7 +240,6 @@
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);
@@ -275,7 +270,7 @@
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
  }
@@ -284,24 +279,19 @@
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';
@@ -311,18 +301,14 @@
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
 
@@ -378,4 +364,4 @@
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>
 
95
  const PLAYER_SIZE = 30;
96
  const BULLET_SPEED = 10;
97
  const ENEMY_SPEED = 2;
98
+ const SHOOTING_INTERVAL = 333;
99
 
100
  let game = {
101
  player: {
 
116
  shooting: false
117
  };
118
 
 
 
119
  function spawnEnemies() {
120
  const enemyCount = game.round * 5;
121
  for(let i = 0; i < enemyCount; i++) {
 
134
  }
135
  }
136
 
137
+ function drawCircle(x, y, radius, color) {
138
+ ctx.fillStyle = color;
139
+ ctx.beginPath();
140
+ ctx.arc(x, y, radius, 0, Math.PI * 2);
141
+ ctx.fill();
142
+ }
143
+
144
  function update() {
145
  // Player movement
146
  if(game.keys['w'] && game.player.y > PLAYER_SIZE)
 
166
  angle: angle + (Math.random() - 0.5) * 0.2
167
  });
168
  }
 
169
  game.lastShot = Date.now();
170
  }
171
 
 
175
  bullet.x += Math.cos(bullet.angle) * BULLET_SPEED;
176
  bullet.y += Math.sin(bullet.angle) * BULLET_SPEED;
177
 
 
178
  if(bullet.x < 0 || bullet.x > canvas.width ||
179
  bullet.y < 0 || bullet.y > canvas.height) {
180
  game.player.bullets.splice(i, 1);
181
  }
182
 
 
183
  for(let j = game.enemies.length - 1; j >= 0; j--) {
184
  const enemy = game.enemies[j];
185
  const dx = bullet.x - enemy.x;
 
190
  if(enemy.health <= 0) {
191
  game.enemies.splice(j, 1);
192
  game.player.bulletsPerShot++;
 
193
  game.items.push({
194
  x: enemy.x,
195
  y: enemy.y,
 
203
 
204
  // Update enemies
205
  game.enemies.forEach(enemy => {
 
206
  enemy.x += enemy.direction.x * ENEMY_SPEED;
207
  enemy.y += enemy.direction.y * ENEMY_SPEED;
208
 
 
209
  if(enemy.x < 0 || enemy.x > canvas.width) enemy.direction.x *= -1;
210
  if(enemy.y < 0 || enemy.y > canvas.height) enemy.direction.y *= -1;
211
 
 
212
  if(Date.now() - enemy.lastShot > 1000) {
213
  const angle = Math.atan2(
214
  game.player.y - enemy.y,
 
222
  enemy.lastShot = Date.now();
223
  }
224
 
 
225
  for(let i = enemy.bullets.length - 1; i >= 0; i--) {
226
  const bullet = enemy.bullets[i];
227
  bullet.x += Math.cos(bullet.angle) * BULLET_SPEED/2;
228
  bullet.y += Math.sin(bullet.angle) * BULLET_SPEED/2;
229
 
 
230
  const dx = bullet.x - game.player.x;
231
  const dy = bullet.y - game.player.y;
232
  if(Math.sqrt(dx*dx + dy*dy) < PLAYER_SIZE/2) {
 
240
  }
241
  }
242
 
 
243
  if(bullet.x < 0 || bullet.x > canvas.width ||
244
  bullet.y < 0 || bullet.y > canvas.height) {
245
  enemy.bullets.splice(i, 1);
 
270
  document.getElementById('round').textContent = `Round ${game.round}`;
271
  game.player.health = game.player.maxHealth;
272
  document.getElementById('health').style.width = '100%';
273
+ game.player.bulletsPerShot = 1;
274
  spawnEnemies();
275
  }
276
  }
 
279
  function draw() {
280
  ctx.clearRect(0, 0, canvas.width, canvas.height);
281
 
282
+ // Draw player (blue circle)
283
+ drawCircle(game.player.x, game.player.y, PLAYER_SIZE/2, '#3498db');
 
 
284
 
285
  // Draw player bullets
286
  ctx.fillStyle = 'yellow';
287
  game.player.bullets.forEach(bullet => {
288
+ drawCircle(bullet.x, bullet.y, 3, 'yellow');
 
 
289
  });
290
 
291
  // Draw enemies
292
  game.enemies.forEach(enemy => {
293
+ // Enemy (red circle)
294
+ drawCircle(enemy.x, enemy.y, PLAYER_SIZE/2, '#e74c3c');
 
295
 
296
  // Health bar
297
  ctx.fillStyle = '#600';
 
301
  (enemy.health/enemy.maxHealth) * 50, 5);
302
 
303
  // Enemy bullets
 
304
  enemy.bullets.forEach(bullet => {
305
+ drawCircle(bullet.x, bullet.y, 3, 'red');
 
 
306
  });
307
  });
308
 
309
+ // Draw items (green circles)
 
310
  game.items.forEach(item => {
311
+ drawCircle(item.x, item.y, PLAYER_SIZE/3, '#2ecc71');
312
  });
313
  }
314
 
 
364
  gameLoop();
365
  </script>
366
  </body>
367
+ </html>