cutechicken commited on
Commit
69185fd
ยท
verified ยท
1 Parent(s): 99b30f8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +114 -31
index.html CHANGED
@@ -75,6 +75,25 @@
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');
@@ -96,6 +115,8 @@
96
  let isCountingDown = true;
97
  let countdownTime = 3;
98
  let autoFire = false;
 
 
99
 
100
  // Load assets
101
  const backgroundImg = new Image();
@@ -157,21 +178,34 @@
157
  }, 1000);
158
  }
159
  class Enemy {
160
- constructor() {
161
- this.x = Math.random() * canvas.width;
162
- this.y = Math.random() * canvas.height;
163
- this.health = 1000;
164
- this.maxHealth = 1000;
165
- this.speed = 2;
166
- this.lastShot = 0;
167
- this.shootInterval = 1000;
168
- this.angle = 0;
169
- this.width = 100;
170
- this.height = 45;
171
- this.moveTimer = 0;
172
- this.moveInterval = Math.random() * 2000 + 1000;
173
- this.moveAngle = Math.random() * Math.PI * 2;
174
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  update() {
176
  if(isCountingDown) return;
177
  const now = Date.now();
@@ -194,18 +228,34 @@
194
  this.lastShot = now;
195
  }
196
  }
197
- shoot() {
198
- enemyFireSound.cloneNode().play();
199
- bullets.push({
200
- x: this.x + Math.cos(this.angle) * 30,
201
- y: this.y + Math.sin(this.angle) * 30,
202
- angle: this.angle,
203
- speed: 5,
204
- isEnemy: true,
205
- size: 3
206
- });
207
- }
208
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  function initRound() {
210
  enemies = [];
211
  for(let i = 0; i < 1 * currentRound; i++) {
@@ -248,6 +298,17 @@
248
  lastShot = now;
249
  }
250
  }
 
 
 
 
 
 
 
 
 
 
 
251
  function updateGame() {
252
  if(gameOver) return;
253
  if(!isCountingDown) {
@@ -272,6 +333,7 @@
272
  enemy.health -= enemy.maxHealth * bullet.damage;
273
  if(enemy.health <= 0) {
274
  spawnHealthItem(enemy.x, enemy.y);
 
275
  return false;
276
  }
277
  return true;
@@ -300,12 +362,20 @@
300
  }
301
  return true;
302
  });
303
- if(enemies.length === 0) {
304
- if(currentRound < 10) {
305
- nextRoundBtn.style.display = 'block';
 
 
 
 
 
 
306
  } else {
307
  gameOver = true;
 
308
  restartBtn.style.display = 'block';
 
309
  }
310
  }
311
  }
@@ -357,6 +427,11 @@
357
  if(isCountingDown) {
358
  ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
359
  ctx.fillRect(0, 0, canvas.width, canvas.height);
 
 
 
 
 
360
  }
361
  }
362
  function gameLoop() {
@@ -369,10 +444,18 @@
369
  nextRoundBtn.style.display = 'none';
370
  initRound();
371
  });
372
- restartBtn.addEventListener('click', () => {
 
373
  currentRound = 1;
374
  gameOver = false;
 
 
375
  restartBtn.style.display = 'none';
 
 
 
 
 
376
  initRound();
377
  });
378
  Promise.all([
 
75
  <button id="nextRound" class="button">Next Round</button>
76
  <button id="restart" class="button">Restart Game</button>
77
  <canvas id="gameCanvas"></canvas>
78
+ <div id="shop" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); background:rgba(0,0,0,0.9); padding:20px; border-radius:10px; color:white; z-index:1000;">
79
+ <h2>Tank Shop</h2>
80
+ <div style="display:flex; gap:20px;">
81
+ <div id="tank1" style="text-align:center;">
82
+ <h3>PZ.IV</h3>
83
+ <img src="player2.png" width="100" height="45">
84
+ <p>300 Gold</p>
85
+ <button onclick="buyTank('player2.png', 300, 'tank1')">Buy</button>
86
+ </div>
87
+ <div id="tank2" style="text-align:center;">
88
+ <h3>TIGER</h3>
89
+ <img src="player3.png" width="100" height="45">
90
+ <p>500 Gold</p>
91
+ <button onclick="buyTank('player3.png', 500, 'tank2')">Buy</button>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ <button id="bossButton" class="button">Fight Boss!</button>
96
+ <div id="winMessage" class="button" style="font-size: 72px; background: none;">You Win!</div>
97
 
98
  <script>
99
  const canvas = document.getElementById('gameCanvas');
 
115
  let isCountingDown = true;
116
  let countdownTime = 3;
117
  let autoFire = false;
118
+ let gold = 0;
119
+ let isBossStage = false;
120
 
121
  // Load assets
122
  const backgroundImg = new Image();
 
178
  }, 1000);
179
  }
180
  class Enemy {
181
+ constructor(isBoss = false) {
182
+ this.x = Math.random() * canvas.width;
183
+ this.y = Math.random() * canvas.height;
184
+ this.health = isBoss ? 5000 : 1000;
185
+ this.maxHealth = this.health;
186
+ this.speed = isBoss ? 1 : 2;
187
+ this.lastShot = 0;
188
+ this.shootInterval = isBoss ? 1000 : 1000;
189
+ this.angle = 0;
190
+ this.width = 100;
191
+ this.height = 45;
192
+ this.moveTimer = 0;
193
+ this.moveInterval = Math.random() * 2000 + 1000;
194
+ this.moveAngle = Math.random() * Math.PI * 2;
195
+ this.isBoss = isBoss;
196
+
197
+ if (isBoss) {
198
+ this.enemyImg = new Image();
199
+ this.enemyImg.src = 'boss.png';
200
+ } else if (currentRound >= 7) {
201
+ this.enemyImg = new Image();
202
+ this.enemyImg.src = 'enemy3.png';
203
+ } else if (currentRound >= 4) {
204
+ this.enemyImg = new Image();
205
+ this.enemyImg.src = 'enemy2.png';
206
+ }
207
+ }
208
+
209
  update() {
210
  if(isCountingDown) return;
211
  const now = Date.now();
 
228
  this.lastShot = now;
229
  }
230
  }
231
+ shoot() {
232
+ enemyFireSound.cloneNode().play();
233
+ bullets.push({
234
+ x: this.x + Math.cos(this.angle) * 30,
235
+ y: this.y + Math.sin(this.angle) * 30,
236
+ angle: this.angle,
237
+ speed: 5,
238
+ isEnemy: true,
239
+ size: this.isBoss ? 5 : 3,
240
+ damage: this.isBoss ? 200 : 100
241
+ });
242
+ }
243
+ }
244
+
245
+ function showShop() {
246
+ document.getElementById('shop').style.display = 'block';
247
+ }
248
+
249
+ function buyTank(tankImg, cost, tankId) {
250
+ if (gold >= cost) {
251
+ gold -= cost;
252
+ playerImg.src = tankImg;
253
+ document.getElementById(tankId).style.display = 'none';
254
+ document.getElementById('shop').style.display = 'none';
255
+ initRound();
256
+ }
257
+ }
258
+
259
  function initRound() {
260
  enemies = [];
261
  for(let i = 0; i < 1 * currentRound; i++) {
 
298
  lastShot = now;
299
  }
300
  }
301
+
302
+ function startBossStage() {
303
+ isBossStage = true;
304
+ enemies = [];
305
+ enemies.push(new Enemy(true));
306
+ player.health = player.maxHealth;
307
+ bullets = [];
308
+ items = [];
309
+ document.getElementById('bossButton').style.display = 'none';
310
+ startCountdown();
311
+ }
312
  function updateGame() {
313
  if(gameOver) return;
314
  if(!isCountingDown) {
 
333
  enemy.health -= enemy.maxHealth * bullet.damage;
334
  if(enemy.health <= 0) {
335
  spawnHealthItem(enemy.x, enemy.y);
336
+ gold += 100;
337
  return false;
338
  }
339
  return true;
 
362
  }
363
  return true;
364
  });
365
+ if(enemies.length === 0) {
366
+ //์ถ”๊ฐ€๋œ ๋ถ€๋ถ„
367
+ if (!isBossStage) {
368
+ if(currentRound < 10) {
369
+ nextRoundBtn.style.display = 'block';
370
+ showShop();
371
+ } else {
372
+ document.getElementById('bossButton').style.display = 'block';
373
+ }
374
  } else {
375
  gameOver = true;
376
+ document.getElementById('winMessage').style.display = 'block';
377
  restartBtn.style.display = 'block';
378
+ bgm.pause();
379
  }
380
  }
381
  }
 
427
  if(isCountingDown) {
428
  ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
429
  ctx.fillRect(0, 0, canvas.width, canvas.height);
430
+ ctx.fillStyle = 'white';
431
+ //์ถ”๊ฐ€๋œ ๋ถ€๋ถ„
432
+ ctx.font = '24px Arial';
433
+ ctx.fillText(`Round ${currentRound}/10`, 10, 30);
434
+ ctx.fillText(`Gold: ${gold}`, 10, 60);
435
  }
436
  }
437
  function gameLoop() {
 
444
  nextRoundBtn.style.display = 'none';
445
  initRound();
446
  });
447
+ //์ถ”๊ฐ€๋œ ๋ถ€๋ถ„
448
+ restartBtn.addEventListener('click', () => {
449
  currentRound = 1;
450
  gameOver = false;
451
+ isBossStage = false;
452
+ gold = 0;
453
  restartBtn.style.display = 'none';
454
+ document.getElementById('winMessage').style.display = 'none';
455
+ document.getElementById('tank1').style.display = 'block';
456
+ document.getElementById('tank2').style.display = 'block';
457
+ playerImg.src = 'player.png';
458
+ bgm.play();
459
  initRound();
460
  });
461
  Promise.all([