cutechicken commited on
Commit
959eace
·
verified ·
1 Parent(s): 342d5b8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +280 -296
index.html CHANGED
@@ -1,381 +1,365 @@
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/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++) {
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>
 
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
+ <title>Tank Battle</title>
5
  <style>
6
  body {
7
  margin: 0;
8
  overflow: hidden;
 
 
 
 
 
 
 
 
 
 
 
 
9
  background: #333;
 
 
10
  }
11
+ #gameCanvas {
12
+ background-repeat: repeat;
 
 
 
13
  }
14
+ #instructions {
15
  position: fixed;
16
+ top: 10px;
17
+ right: 10px;
18
  color: white;
19
  background: rgba(0,0,0,0.7);
20
+ padding: 10px;
21
  border-radius: 5px;
22
+ font-family: Arial;
23
+ z-index: 1000;
24
  }
25
+ .button {
 
 
 
 
 
 
 
 
26
  position: fixed;
27
  top: 50%;
28
  left: 50%;
29
  transform: translate(-50%, -50%);
30
+ padding: 20px 40px;
31
+ font-size: 24px;
32
+ background: #4CAF50;
33
  color: white;
 
 
 
 
 
 
 
34
  border: none;
 
 
35
  border-radius: 5px;
36
  cursor: pointer;
37
+ display: none;
38
+ z-index: 1000;
39
  }
40
  </style>
41
  </head>
42
  <body>
43
+ <div id="instructions">
44
+ Controls:<br>
45
+ WASD - Move tank<br>
46
+ Mouse - Aim turret<br>
47
+ Space - Fire
 
 
 
 
 
 
 
 
 
 
48
  </div>
49
+ <button id="nextRound" class="button">Next Round</button>
50
+ <button id="restart" class="button">Restart Game</button>
51
+ <canvas id="gameCanvas"></canvas>
52
 
53
  <script>
54
+ const canvas = document.getElementById('gameCanvas');
55
  const ctx = canvas.getContext('2d');
56
+ const nextRoundBtn = document.getElementById('nextRound');
57
+ const restartBtn = document.getElementById('restart');
58
 
59
  canvas.width = window.innerWidth;
60
  canvas.height = window.innerHeight;
61
 
62
+ // Load images
63
+ const fieldImg = new Image();
64
+ fieldImg.src = 'field.png';
65
+
66
+ const bodyImg = new Image();
67
+ bodyImg.src = 'body.png';
68
+
69
+ const turretImg = new Image();
70
+ turretImg.src = 'turret.png';
71
+
72
+ const enemyImg = new Image();
73
+ enemyImg.src = 'enemy.png';
74
+
75
+ // Audio
76
+ const playerFireSound = new Audio('fire.mp3');
77
+ const enemyFireSound = new Audio('fire2.mp3');
78
+
79
+ // Game state
80
+ let currentRound = 1;
81
+ let gameOver = false;
82
+ let enemies = [];
83
+ let bullets = [];
84
+ let playerBullets = [];
85
+ let items = [];
86
+
87
+ // Tank properties
88
+ const player = {
89
+ x: canvas.width/2,
90
+ y: canvas.height/2,
91
+ speed: 5,
92
+ angle: 0,
93
+ turretAngle: 0,
94
+ width: 60,
95
+ height: 80,
96
+ health: 1000,
97
+ maxHealth: 1000
98
  };
99
 
100
+ class Enemy {
101
+ constructor() {
102
+ this.x = Math.random() * canvas.width;
103
+ this.y = Math.random() * canvas.height;
104
+ this.health = 1000;
105
+ this.maxHealth = 1000;
106
+ this.speed = 2;
107
+ this.lastShot = 0;
108
+ this.shootInterval = 2000;
109
+ this.angle = 0;
110
+ }
111
+
112
+ update() {
113
+ this.angle = Math.atan2(player.y - this.y, player.x - this.x);
114
+ this.x += Math.cos(this.angle) * this.speed * 0.5;
115
+ this.y += Math.sin(this.angle) * this.speed * 0.5;
116
+
117
+ this.x = Math.max(0, Math.min(canvas.width, this.x));
118
+ this.y = Math.max(0, Math.min(canvas.height, this.y));
119
+
120
+ const now = Date.now();
121
+ if (now - this.lastShot > this.shootInterval) {
122
+ this.shoot();
123
+ this.lastShot = now;
124
+ }
125
+ }
126
+
127
+ shoot() {
128
+ enemyFireSound.currentTime = 0;
129
+ enemyFireSound.play();
130
+ bullets.push({
131
+ x: this.x,
132
+ y: this.y,
133
+ angle: this.angle,
134
+ speed: 5,
135
+ isEnemy: true
136
  });
137
  }
138
  }
139
 
140
+ // Draw background pattern
141
+ function drawBackground() {
142
+ const pattern = ctx.createPattern(fieldImg, 'repeat');
143
+ ctx.fillStyle = pattern;
144
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
145
+ }
146
+
147
+ // Game controls
148
+ const keys = {};
149
+ let mouseX = 0;
150
+ let mouseY = 0;
151
+ let lastShot = 0;
152
+ const shootInterval = 1000;
153
+
154
+ document.addEventListener('keydown', (e) => {
155
+ keys[e.key] = true;
156
+ });
157
+
158
+ document.addEventListener('keyup', (e) => {
159
+ keys[e.key] = false;
160
+ });
161
+
162
+ canvas.addEventListener('mousemove', (e) => {
163
+ mouseX = e.clientX;
164
+ mouseY = e.clientY;
165
+ });
166
+
167
+ function fireBullet() {
168
+ const now = Date.now();
169
+ if (now - lastShot > shootInterval && keys[' ']) {
170
+ playerFireSound.currentTime = 0;
171
+ playerFireSound.play();
172
+ playerBullets.push({
173
+ x: player.x,
174
+ y: player.y,
175
+ angle: player.turretAngle,
176
+ speed: 10
177
+ });
178
+ lastShot = now;
179
  }
180
+ }
181
 
182
+ function initRound() {
183
+ enemies = [];
184
+ for(let i = 0; i < 5 * currentRound; i++) {
185
+ enemies.push(new Enemy());
186
+ }
187
+ player.health = player.maxHealth;
188
+ bullets = [];
189
+ playerBullets = [];
190
+ items = [];
191
+ }
192
 
193
+ function spawnHealthItem(x, y) {
194
+ items.push({
195
+ x: x,
196
+ y: y,
197
+ width: 20,
198
+ height: 20
199
+ });
200
+ }
201
+
202
+ function updateGame() {
203
+ if(gameOver) return;
204
+
205
+ if(keys['w']) player.y = Math.max(player.y - player.speed, player.height/2);
206
+ if(keys['s']) player.y = Math.min(player.y + player.speed, canvas.height - player.height/2);
207
+ if(keys['a']) player.x = Math.max(player.x - player.speed, player.width/2);
208
+ if(keys['d']) player.x = Math.min(player.x + player.speed, canvas.width - player.width/2);
209
+
210
+ player.turretAngle = Math.atan2(mouseY - player.y, mouseX - player.x);
211
+
212
+ if(keys[' ']) fireBullet();
213
+
214
+ enemies.forEach(enemy => enemy.update());
215
 
216
+ // Update bullets and collision detection
217
+ playerBullets = playerBullets.filter(bullet => {
218
+ bullet.x += Math.cos(bullet.angle) * bullet.speed;
219
+ bullet.y += Math.sin(bullet.angle) * bullet.speed;
220
+
221
+ enemies = enemies.filter(enemy => {
222
+ const dist = Math.hypot(bullet.x - enemy.x, bullet.y - enemy.y);
223
+ if(dist < 30) {
224
+ enemy.health -= enemy.maxHealth / 2;
225
  if(enemy.health <= 0) {
226
+ spawnHealthItem(enemy.x, enemy.y);
227
+ return false;
 
 
 
 
 
 
228
  }
229
+ return true;
230
  }
231
+ return true;
232
+ });
233
 
234
+ return bullet.x >= 0 && bullet.x <= canvas.width &&
235
+ bullet.y >= 0 && bullet.y <= canvas.height;
236
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
+ bullets = bullets.filter(bullet => {
239
+ bullet.x += Math.cos(bullet.angle) * bullet.speed;
240
+ bullet.y += Math.sin(bullet.angle) * bullet.speed;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
+ const dist = Math.hypot(bullet.x - player.x, bullet.y - player.y);
243
+ if(dist < 30) {
244
+ player.health -= 100;
245
+ if(player.health <= 0) {
246
+ gameOver = true;
247
+ restartBtn.style.display = 'block';
248
  }
249
+ return false;
250
  }
251
+
252
+ return bullet.x >= 0 && bullet.x <= canvas.width &&
253
+ bullet.y >= 0 && bullet.y <= canvas.height;
254
  });
255
 
256
+ items = items.filter(item => {
257
+ const dist = Math.hypot(item.x - player.x, item.y - player.y);
258
+ if(dist < 30) {
259
+ player.health = Math.min(player.health + 200, player.maxHealth);
260
+ return false;
 
 
 
 
 
 
 
 
261
  }
262
+ return true;
263
+ });
264
 
265
+ if(enemies.length === 0) {
266
+ if(currentRound < 10) {
267
+ nextRoundBtn.style.display = 'block';
268
+ } else {
269
+ gameOver = true;
270
+ restartBtn.style.display = 'block';
 
 
 
271
  }
272
  }
273
  }
274
 
275
+ function drawHealthBar(x, y, health, maxHealth, width, height, color) {
276
+ const barX = x - width/2;
277
+ const barY = y - 50;
278
+ ctx.fillStyle = '#333';
279
+ ctx.fillRect(barX, barY, width, height);
280
+ ctx.fillStyle = color;
281
+ ctx.fillRect(barX, barY, width * (health/maxHealth), height);
282
+ }
283
 
284
+ function drawGame() {
285
+ drawBackground();
286
+
287
  // Draw player
288
+ ctx.save();
289
+ ctx.translate(player.x, player.y);
290
+ ctx.drawImage(bodyImg, -player.width/2, -player.height/2, player.width, player.height);
291
+ ctx.rotate(player.turretAngle);
292
+ ctx.drawImage(turretImg, -player.width/2, -player.height/2, player.width, player.height);
293
+ ctx.restore();
294
+
295
+ // Draw player health bar
296
+ drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
297
+
298
+ // Draw enemies
299
+ enemies.forEach(enemy => {
300
+ ctx.save();
301
+ ctx.translate(enemy.x, enemy.y);
302
+ ctx.rotate(enemy.angle);
303
+ ctx.drawImage(enemyImg, -30, -40, 60, 80);
304
+ ctx.restore();
305
+ drawHealthBar(enemy.x, enemy.y, enemy.health, enemy.maxHealth, 60, 5, 'red');
306
+ });
307
 
308
+ // Draw bullets
309
  ctx.fillStyle = 'yellow';
310
+ [...playerBullets, ...bullets].forEach(bullet => {
311
  ctx.beginPath();
312
  ctx.arc(bullet.x, bullet.y, 3, 0, Math.PI * 2);
313
  ctx.fill();
314
  });
315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  // Draw items
317
  ctx.fillStyle = 'green';
318
+ items.forEach(item => {
319
+ ctx.beginPath();
320
+ ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
321
+ ctx.fill();
322
  });
323
+
324
+ // Draw round number
325
+ ctx.fillStyle = 'white';
326
+ ctx.font = '24px Arial';
327
+ ctx.fillText(`Round ${currentRound}/10`, 10, 30);
328
  }
329
 
330
  function gameLoop() {
331
+ updateGame();
332
+ drawGame();
 
 
333
  requestAnimationFrame(gameLoop);
334
  }
335
 
336
+ nextRoundBtn.addEventListener('click', () => {
337
+ currentRound++;
338
+ nextRoundBtn.style.display = 'none';
339
+ initRound();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  });
341
+
342
+ restartBtn.addEventListener('click', () => {
343
+ currentRound = 1;
344
+ gameOver = false;
345
+ restartBtn.style.display = 'none';
346
+ initRound();
347
  });
348
+
349
+ Promise.all([
350
+ new Promise(resolve => fieldImg.onload = resolve),
351
+ new Promise(resolve => bodyImg.onload = resolve),
352
+ new Promise(resolve => turretImg.onload = resolve),
353
+ new Promise(resolve => enemyImg.onload = resolve)
354
+ ]).then(() => {
355
+ initRound();
356
+ gameLoop();
357
  });
358
 
359
+ window.addEventListener('resize', () => {
360
+ canvas.width = window.innerWidth;
361
+ canvas.height = window.innerHeight;
362
+ });
363
  </script>
364
  </body>
365
+ </html>