cutechicken commited on
Commit
d951e0c
·
verified ·
1 Parent(s): 44e9133

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +386 -1
index.html CHANGED
@@ -1 +1,386 @@
1
- <!DOCTYPE html><html><head><title>TB</title><style>body{margin:0;overflow:hidden;background:#333;font-family:Arial}._a{background-repeat:repeat}._b{position:fixed;color:#fff;background:rgba(0,0,0,.7);border-radius:5px;z-index:1e3}._c{top:10px;right:10px;padding:10px}._d{top:150px;right:10px;padding:10px;font-size:18px}._e{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);padding:20px 40px;font-size:24px;background:#4CAF50;color:#fff;border:none;border-radius:5px;cursor:pointer;display:none;z-index:1e3}._f{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);font-size:72px;color:#fff;text-shadow:2px 2px 4px rgba(0,0,0,.5);z-index:1e3;display:none}</style></head><body><div class="_b _c">Controls:<br>WASD - Move tank<br>Mouse - Aim<br>Space - Fire<br>C - Switch Weapon R - Toggle Auto-fire</div><div class="_b _d" id="_g">Current Weapon: Cannon</div><div class="_f" id="_h">3</div><button class="_e" id="_i">Next Round</button><button class="_e" id="_j">Restart Game</button><canvas id="_k"></canvas><script>(function(){var _0x4ae9=['getContext','width','height','innerWidth','innerHeight','getElementById','_k','_i','_j','_g','_h','city.png','player.png','enemy.png','firemn.ogg','firemg.ogg','fireenemy.ogg'];var _0x5f=function(_0x56b4){return _0x4ae9[_0x56b4]};var _c=document[_0x5f(5)](_0x5f(6));var _ctx=_c[_0x5f(0)]('2d');var _n=document[_0x5f(5)](_0x5f(7));var _r=document[_0x5f(5)](_0x5f(8));var _w=document[_0x5f(5)](_0x5f(9));var _cd=document[_0x5f(5)](_0x5f(10));_c[_0x5f(1)]=window[_0x5f(3)];_c[_0x5f(2)]=window[_0x5f(4)];var _cr=1,_go=!1,_cw='cannon',_e=[],_b=[],_i=[],_ls=0,_ic=!0,_ct=3,_af=!1;var _bg=new Image();_bg.src=_0x5f(11);var _p=new Image();_p.src=_0x5f(12);var _ei=new Image();_ei.src=_0x5f(13);var _cs=new Audio(_0x5f(14));var _ms=new Audio(_0x5f(15));var _es=new Audio(_0x5f(16));_es.volume=.5;var _ws={cannon:{fireRate:1e3,damage:.25,bulletSize:5,sound:_cs},machinegun:{fireRate:200,damage:.05,bulletSize:2,sound:_ms}};var _pl={x:_c[_0x5f(1)]/2,y:_c[_0x5f(2)]/2,speed:5,angle:0,width:100,height:45,health:1e3,maxHealth:1e3};function _sc(){_ic=!0;_ct=3;_cd.style.display='block';_cd.textContent=_ct;var _ci=setInterval(function(){_ct--;if(_ct<=0){clearInterval(_ci);_cd.style.display='none';_ic=!1}_cd.textContent=_ct>0?_ct:'GO!'},1e3)}class _En{constructor(){this.x=Math.random()*_c[_0x5f(1)];this.y=Math.random()*_c[_0x5f(2)];this.health=1e3;this.maxHealth=1e3;this.speed=2;this.lastShot=0;this.shootInterval=1e3;this.angle=0;this.width=100;this.height=45;this.moveTimer=0;this.moveInterval=Math.random()*2e3+1e3;this.moveAngle=Math.random()*Math.PI*2}update(){if(_ic)return;var _n=Date.now();if(_n-this.moveTimer>this.moveInterval){this.moveAngle=Math.random()*Math.PI*2;this.moveTimer=_n}this.x+=Math.cos(this.moveAngle)*this.speed;this.y+=Math.sin(this.moveAngle)*this.speed;this.x=Math.max(this.width/2,Math.min(_c[_0x5f(1)]-this.width/2,this.x));this.y=Math.max(this.height/2,Math.min(_c[_0x5f(2)]-this.height/2,this.y));this.angle=Math.atan2(_pl.y-this.y,_pl.x-this.x);if(_n-this.lastShot>this.shootInterval&&!_ic){this.shoot();this.lastShot=_n}}shoot(){_es.cloneNode().play();_b.push({x:this.x+Math.cos(this.angle)*30,y:this.y+Math.sin(this.angle)*30,angle:this.angle,speed:5,isEnemy:!0,size:3})}}function _ir(){_e=[];for(var i=0;i<1*_cr;i++){_e.push(new _En())}_pl.health=_pl.maxHealth;_b=[];_i=[];_sc()}_c.addEventListener('mousemove',function(e){_pl.angle=Math.atan2(e.clientY-_pl.y,e.clientX-_pl.x)});var _k={};document.addEventListener('keydown',function(e){_k[e.key]=!0;if(e.key.toLowerCase()==='c'){_cw=_cw==='cannon'?'machinegun':'cannon';_w.textContent='Current Weapon: '+_cw.charAt(0).toUpperCase()+_cw.slice(1)}else if(e.key.toLowerCase()==='r'){_af=!_af}});document.addEventListener('keyup',function(e){_k[e.key]=!1});function _fb(){if(_ic)return;var _w=_ws[_cw];var _n=Date.now();if((_k[' ']||_af)&&_n-_ls>_w.fireRate){_w.sound.cloneNode().play();_b.push({x:_pl.x+Math.cos(_pl.angle)*30,y:_pl.y+Math.sin(_pl.angle)*30,angle:_pl.angle,speed:10,isEnemy:!1,damage:_w.damage,size:_w.bulletSize});_ls=_n}}function _ug(){if(_go)return;if(!_ic){if(_k['w'])_pl.y-=_pl.speed;if(_k['s'])_pl.y+=_pl.speed;if(_k['a'])_pl.x-=_pl.speed;if(_k['d'])_pl.x+=_pl.speed;_pl.x=Math.max(_pl.width/2,Math.min(_c[_0x5f(1)]-_pl.width/2,_pl.x));_pl.y=Math.max(_pl.height/2,Math.min(_c[_0x5f(2)]-_pl.height/2,_pl.y));_fb()}_e.forEach(function(e){e.update()});if(!_ic){_b=_b.filter(function(b){b.x+=Math.cos(b.angle)*b.speed;b.y+=Math.sin(b.angle)*b.speed;if(!b.isEnemy){_e=_e.filter(function(e){var d=Math.hypot(b.x-e.x,b.y-e.y);if(d<30){e.health-=e.maxHealth*b.damage;if(e.health<=0){_shi(e.x,e.y);return!1}return!0}return!0})}else{var d=Math.hypot(b.x-_pl.x,b.y-_pl.y);if(d<30){_pl.health-=100;if(_pl.health<=0){_go=!0;_r.style.display='block'}return!1}}return b.x>=0&&b.x<=_c[_0x5f(1)]&&b.y>=0&&b.y<=_c[_0x5f(2)]});_i=_i.filter(function(i){var d=Math.hypot(i.x-_pl.x,i.y-_pl.y);if(d<30){_pl.health=Math.min(_pl.health+200,_pl.maxHealth);return!1}return!0});if(_e.length===0){if(_cr<10){_n.style.display='block'}else{_go=!0;_r.style.display='block'}}}}function _shi(x,y){_i.push({x:x,y:y})}function _dhb(x,y,h,m,w,h,c){_ctx.fillStyle='#333';_ctx.fillRect(x-w/2,y-h/2,w,h);_ctx.fillStyle=c;_ctx.fillRect(x-w/2,y-h/2,w*(h/m),h)}function _dg(){_ctx.clearRect(0,0,_c[_0x5f(1)],_c[_0x5f(2)]);var p=_ctx.createPattern(_bg,'repeat');_ctx.fillStyle=p;_ctx.fillRect(0,0,_c[_0x5f(1)],_c[_0x5f(2)]);_ctx.save();_ctx.translate(_pl.x,_pl.y);_ctx.rotate(_pl.angle);_ctx.drawImage(_p,-_pl.width/2,-_pl.height/2,_pl.width,_pl.height);_ctx.restore();_dhb(_c[_0x5f(1)]/2,30,_pl.health,_pl.maxHealth,200,20,'green');_e.forEach(function(e){_ctx.save();_ctx.translate(e.x,e.y);_ctx.rotate(e.angle);_ctx.drawImage(_ei,-e.width/2,-e.height/2,e.width,e.height);_ctx.restore();_dhb(e.x,e.y-40,e.health,e.maxHealth,60,5,'red')});_b.forEach(function(b){_ctx.beginPath();_ctx.fillStyle=b.isEnemy?'red':'yellow';_ctx.arc(b.x,b.y,b.size,0,Math.PI*2);_ctx.fill()});_i.forEach(function(i){_ctx.beginPath();_ctx.fillStyle='green';_ctx.arc(i.x,i.y,10,0,Math.PI*2);_ctx.fill()});_ctx.fillStyle='white';_ctx.font='24px Arial';_ctx.fillText('Round '+_cr+'/10',10,30);if(_ic){_ctx.fillStyle='rgba(0, 0, 0, 0.5)';_ctx.fillRect(0,0,_c[_0x5f(1)],_c[_0x5f(2)])}}function _gl(){_ug();_dg();requestAnimationFrame(_gl)}_n.addEventListener('click',function(){_cr++;_n.style.display='none';_ir()});_r.addEventListener('click',function(){_cr=1;_go=!1;_r.style.display='none';_ir()});Promise.all([new Promise(function(r){_bg.onload=r}),new Promise(function(r){_p.onload=r}),new Promise(function(r){_ei.onload=r})]).then(function(){_ir();_gl()});window.addEventListener('resize',function(){_c[_0x5f(1)]=window[_0x5f(3)];_c[_0x5f(2)]=window[_0x5f(4)]})})();</script></body></html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ font-family: Arial;
11
+ }
12
+ #gameCanvas {
13
+ background-repeat: repeat;
14
+ }
15
+ #instructions {
16
+ position: fixed;
17
+ top: 10px;
18
+ right: 10px;
19
+ color: white;
20
+ background: rgba(0,0,0,0.7);
21
+ padding: 10px;
22
+ border-radius: 5px;
23
+ z-index: 1000;
24
+ }
25
+ #weaponInfo {
26
+ position: fixed;
27
+ top: 150px;
28
+ right: 10px;
29
+ color: white;
30
+ background: rgba(0,0,0,0.7);
31
+ padding: 10px;
32
+ border-radius: 5px;
33
+ z-index: 1000;
34
+ font-size: 18px;
35
+ }
36
+ .button {
37
+ position: fixed;
38
+ top: 50%;
39
+ left: 50%;
40
+ transform: translate(-50%, -50%);
41
+ padding: 20px 40px;
42
+ font-size: 24px;
43
+ background: #4CAF50;
44
+ color: white;
45
+ border: none;
46
+ border-radius: 5px;
47
+ cursor: pointer;
48
+ display: none;
49
+ z-index: 1000;
50
+ }
51
+ #countdown {
52
+ position: fixed;
53
+ top: 50%;
54
+ left: 50%;
55
+ transform: translate(-50%, -50%);
56
+ font-size: 72px;
57
+ color: white;
58
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
59
+ z-index: 1000;
60
+ display: none;
61
+ }
62
+ </style>
63
+ </head>
64
+ <body>
65
+ <div id="instructions">
66
+ Controls:<br>
67
+ WASD - Move tank<br>
68
+ Mouse - Aim<br>
69
+ Space - Fire<br>
70
+ C - Switch Weapon
71
+ R - Toggle Auto-fire
72
+ </div>
73
+ <div id="weaponInfo">Current Weapon: Cannon</div>
74
+ <div id="countdown">3</div>
75
+ <button id="nextRound" class="button">Next Round</button>
76
+ <button id="restart" class="button">Restart Game</button>
77
+ <canvas id="gameCanvas"></canvas>
78
+
79
+ <script>
80
+ const canvas = document.getElementById('gameCanvas');
81
+ const ctx = canvas.getContext('2d');
82
+ const nextRoundBtn = document.getElementById('nextRound');
83
+ const restartBtn = document.getElementById('restart');
84
+ const weaponInfo = document.getElementById('weaponInfo');
85
+ const countdownEl = document.getElementById('countdown');
86
+ canvas.width = window.innerWidth;
87
+ canvas.height = window.innerHeight;
88
+ // Game state
89
+ let currentRound = 1;
90
+ let gameOver = false;
91
+ let currentWeapon = 'cannon';
92
+ let enemies = [];
93
+ let bullets = [];
94
+ let items = [];
95
+ let lastShot = 0;
96
+ let isCountingDown = true;
97
+ let countdownTime = 3;
98
+ let autoFire = false;
99
+
100
+ // Load assets
101
+ const backgroundImg = new Image();
102
+ backgroundImg.src = 'city.png';
103
+ const playerImg = new Image();
104
+ playerImg.src = 'player.png';
105
+
106
+ const enemyImg = new Image();
107
+ enemyImg.src = 'enemy.png';
108
+ // Audio setup
109
+ const cannonSound = new Audio('firemn.ogg');
110
+ const machinegunSound = new Audio('firemg.ogg');
111
+ const enemyFireSound = new Audio('fireenemy.ogg');
112
+ enemyFireSound.volume = 0.5;
113
+ const weapons = {
114
+ cannon: {
115
+ fireRate: 1000,
116
+ damage: 0.25,
117
+ bulletSize: 5,
118
+ sound: cannonSound
119
+ },
120
+ machinegun: {
121
+ fireRate: 200,
122
+ damage: 0.05,
123
+ bulletSize: 2,
124
+ sound: machinegunSound
125
+ }
126
+ };
127
+ // Player setup
128
+ const player = {
129
+ x: canvas.width/2,
130
+ y: canvas.height/2,
131
+ speed: 5,
132
+ angle: 0,
133
+ width: 100,
134
+ height: 45,
135
+ health: 1000,
136
+ maxHealth: 1000
137
+ };
138
+ function startCountdown() {
139
+ isCountingDown = true;
140
+ countdownTime = 3;
141
+ countdownEl.style.display = 'block';
142
+ countdownEl.textContent = countdownTime;
143
+ const countInterval = setInterval(() => {
144
+ countdownTime--;
145
+ if(countdownTime <= 0) {
146
+ clearInterval(countInterval);
147
+ countdownEl.style.display = 'none';
148
+ isCountingDown = false;
149
+ }
150
+ countdownEl.textContent = countdownTime > 0 ? countdownTime : 'GO!';
151
+ }, 1000);
152
+ }
153
+ class Enemy {
154
+ constructor() {
155
+ this.x = Math.random() * canvas.width;
156
+ this.y = Math.random() * canvas.height;
157
+ this.health = 1000;
158
+ this.maxHealth = 1000;
159
+ this.speed = 2;
160
+ this.lastShot = 0;
161
+ this.shootInterval = 1000;
162
+ this.angle = 0;
163
+ this.width = 100;
164
+ this.height = 45;
165
+ this.moveTimer = 0;
166
+ this.moveInterval = Math.random() * 2000 + 1000;
167
+ this.moveAngle = Math.random() * Math.PI * 2;
168
+ }
169
+ update() {
170
+ if(isCountingDown) return;
171
+ const now = Date.now();
172
+
173
+ // Movement
174
+ if (now - this.moveTimer > this.moveInterval) {
175
+ this.moveAngle = Math.random() * Math.PI * 2;
176
+ this.moveTimer = now;
177
+ }
178
+ this.x += Math.cos(this.moveAngle) * this.speed;
179
+ this.y += Math.sin(this.moveAngle) * this.speed;
180
+ // Bounds check
181
+ this.x = Math.max(this.width/2, Math.min(canvas.width - this.width/2, this.x));
182
+ this.y = Math.max(this.height/2, Math.min(canvas.height - this.height/2, this.y));
183
+ // Aim at player
184
+ this.angle = Math.atan2(player.y - this.y, player.x - this.x);
185
+ // Shooting
186
+ if (now - this.lastShot > this.shootInterval && !isCountingDown) {
187
+ this.shoot();
188
+ this.lastShot = now;
189
+ }
190
+ }
191
+ shoot() {
192
+ enemyFireSound.cloneNode().play();
193
+ bullets.push({
194
+ x: this.x + Math.cos(this.angle) * 30,
195
+ y: this.y + Math.sin(this.angle) * 30,
196
+ angle: this.angle,
197
+ speed: 5,
198
+ isEnemy: true,
199
+ size: 3
200
+ });
201
+ }
202
+ }
203
+ function initRound() {
204
+ enemies = [];
205
+ for(let i = 0; i < 1 * currentRound; i++) {
206
+ enemies.push(new Enemy());
207
+ }
208
+ player.health = player.maxHealth;
209
+ bullets = [];
210
+ items = [];
211
+ startCountdown();
212
+ }
213
+ canvas.addEventListener('mousemove', (e) => {
214
+ player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
215
+ });
216
+ const keys = {};
217
+ document.addEventListener('keydown', e => {
218
+ keys[e.key] = true;
219
+ if(e.key.toLowerCase() === 'c') {
220
+ currentWeapon = currentWeapon === 'cannon' ? 'machinegun' : 'cannon';
221
+ weaponInfo.textContent = `Current Weapon: ${currentWeapon.charAt(0).toUpperCase() + currentWeapon.slice(1)}`;
222
+ } else if(e.key.toLowerCase() === 'r') {
223
+ autoFire = !autoFire;
224
+ }
225
+ });
226
+ document.addEventListener('keyup', e => keys[e.key] = false);
227
+ function fireBullet() {
228
+ if(isCountingDown) return;
229
+ const weapon = weapons[currentWeapon];
230
+ const now = Date.now();
231
+ if ((keys[' '] || autoFire) && now - lastShot > weapon.fireRate) {
232
+ weapon.sound.cloneNode().play();
233
+ bullets.push({
234
+ x: player.x + Math.cos(player.angle) * 30,
235
+ y: player.y + Math.sin(player.angle) * 30,
236
+ angle: player.angle,
237
+ speed: 10,
238
+ isEnemy: false,
239
+ damage: weapon.damage,
240
+ size: weapon.bulletSize
241
+ });
242
+ lastShot = now;
243
+ }
244
+ }
245
+ function updateGame() {
246
+ if(gameOver) return;
247
+ if(!isCountingDown) {
248
+ if(keys['w']) player.y -= player.speed;
249
+ if(keys['s']) player.y += player.speed;
250
+ if(keys['a']) player.x -= player.speed;
251
+ if(keys['d']) player.x += player.speed;
252
+ player.x = Math.max(player.width/2, Math.min(canvas.width - player.width/2, player.x));
253
+ player.y = Math.max(player.height/2, Math.min(canvas.height - player.height/2, player.y));
254
+ fireBullet();
255
+ }
256
+ enemies.forEach(enemy => enemy.update());
257
+ if(!isCountingDown) {
258
+ // Update bullets and collisions
259
+ bullets = bullets.filter(bullet => {
260
+ bullet.x += Math.cos(bullet.angle) * bullet.speed;
261
+ bullet.y += Math.sin(bullet.angle) * bullet.speed;
262
+ if(!bullet.isEnemy) {
263
+ enemies = enemies.filter(enemy => {
264
+ const dist = Math.hypot(bullet.x - enemy.x, bullet.y - enemy.y);
265
+ if(dist < 30) {
266
+ enemy.health -= enemy.maxHealth * bullet.damage;
267
+ if(enemy.health <= 0) {
268
+ spawnHealthItem(enemy.x, enemy.y);
269
+ return false;
270
+ }
271
+ return true;
272
+ }
273
+ return true;
274
+ });
275
+ } else {
276
+ const dist = Math.hypot(bullet.x - player.x, bullet.y - player.y);
277
+ if(dist < 30) {
278
+ player.health -= 100;
279
+ if(player.health <= 0) {
280
+ gameOver = true;
281
+ restartBtn.style.display = 'block';
282
+ }
283
+ return false;
284
+ }
285
+ }
286
+ return bullet.x >= 0 && bullet.x <= canvas.width &&
287
+ bullet.y >= 0 && bullet.y <= canvas.height;
288
+ });
289
+ items = items.filter(item => {
290
+ const dist = Math.hypot(item.x - player.x, item.y - player.y);
291
+ if(dist < 30) {
292
+ player.health = Math.min(player.health + 200, player.maxHealth);
293
+ return false;
294
+ }
295
+ return true;
296
+ });
297
+ if(enemies.length === 0) {
298
+ if(currentRound < 10) {
299
+ nextRoundBtn.style.display = 'block';
300
+ } else {
301
+ gameOver = true;
302
+ restartBtn.style.display = 'block';
303
+ }
304
+ }
305
+ }
306
+ }
307
+ function spawnHealthItem(x, y) {
308
+ items.push({x, y});
309
+ }
310
+ function drawHealthBar(x, y, health, maxHealth, width, height, color) {
311
+ ctx.fillStyle = '#333';
312
+ ctx.fillRect(x - width/2, y - height/2, width, height);
313
+ ctx.fillStyle = color;
314
+ ctx.fillRect(x - width/2, y - height/2, width * (health/maxHealth), height);
315
+ }
316
+ function drawGame() {
317
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
318
+ const pattern = ctx.createPattern(backgroundImg, 'repeat');
319
+ ctx.fillStyle = pattern;
320
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
321
+ // Draw all game objects
322
+ ctx.save();
323
+ ctx.translate(player.x, player.y);
324
+ ctx.rotate(player.angle);
325
+ ctx.drawImage(playerImg, -player.width/2, -player.height/2, player.width, player.height);
326
+ ctx.restore();
327
+ drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
328
+ enemies.forEach(enemy => {
329
+ ctx.save();
330
+ ctx.translate(enemy.x, enemy.y);
331
+ ctx.rotate(enemy.angle);
332
+ ctx.drawImage(enemyImg, -enemy.width/2, -enemy.height/2, enemy.width, enemy.height);
333
+ ctx.restore();
334
+ drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
335
+ });
336
+ bullets.forEach(bullet => {
337
+ ctx.beginPath();
338
+ ctx.fillStyle = bullet.isEnemy ? 'red' : 'yellow';
339
+ ctx.arc(bullet.x, bullet.y, bullet.size, 0, Math.PI * 2);
340
+ ctx.fill();
341
+ });
342
+ items.forEach(item => {
343
+ ctx.beginPath();
344
+ ctx.fillStyle = 'green';
345
+ ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
346
+ ctx.fill();
347
+ });
348
+ ctx.fillStyle = 'white';
349
+ ctx.font = '24px Arial';
350
+ ctx.fillText(`Round ${currentRound}/10`, 10, 30);
351
+ if(isCountingDown) {
352
+ ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
353
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
354
+ }
355
+ }
356
+ function gameLoop() {
357
+ updateGame();
358
+ drawGame();
359
+ requestAnimationFrame(gameLoop);
360
+ }
361
+ nextRoundBtn.addEventListener('click', () => {
362
+ currentRound++;
363
+ nextRoundBtn.style.display = 'none';
364
+ initRound();
365
+ });
366
+ restartBtn.addEventListener('click', () => {
367
+ currentRound = 1;
368
+ gameOver = false;
369
+ restartBtn.style.display = 'none';
370
+ initRound();
371
+ });
372
+ Promise.all([
373
+ new Promise(resolve => backgroundImg.onload = resolve),
374
+ new Promise(resolve => playerImg.onload = resolve),
375
+ new Promise(resolve => enemyImg.onload = resolve)
376
+ ]).then(() => {
377
+ initRound();
378
+ gameLoop();
379
+ });
380
+ window.addEventListener('resize', () => {
381
+ canvas.width = window.innerWidth;
382
+ canvas.height = window.innerHeight;
383
+ });
384
+ </script>
385
+ </body>
386
+ </html>