cutechicken commited on
Commit
ebd5b49
·
verified ·
1 Parent(s): 6a4beff

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +67 -53
index.html CHANGED
@@ -471,55 +471,61 @@ function buyTank(tankImg, cost, tankId) {
471
  ctx.fillRect(x - width/2, y - height/2, width * (health/maxHealth), height);
472
  }
473
  function drawGame() {
474
- ctx.clearRect(0, 0, canvas.width, canvas.height);
475
- const pattern = ctx.createPattern(backgroundImg, 'repeat');
476
- ctx.fillStyle = pattern;
477
- ctx.fillRect(0, 0, canvas.width, canvas.height);
478
- // 플레이어 그리기
479
- ctx.save();
480
- ctx.translate(player.x, player.y);
481
- ctx.rotate(player.angle);
482
- ctx.drawImage(playerImg, -player.width/2, -player.height/2, player.width, player.height);
483
- ctx.restore();
484
- // 체력바
485
- drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
486
- // 적 그리기
487
- enemies.forEach(enemy => {
488
- ctx.save();
489
- ctx.translate(enemy.x, enemy.y);
490
- ctx.rotate(enemy.angle);
491
- const img = enemy.isBoss ? enemy.enemyImg : (enemy.enemyImg || enemyImg);
492
- ctx.drawImage(img, -enemy.width/2, -enemy.height/2, enemy.width, enemy.height);
493
- ctx.restore();
494
- drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
495
- });
496
- // 총알 그리기
497
- bullets.forEach(bullet => {
498
- ctx.beginPath();
499
- ctx.fillStyle = bullet.isEnemy ? 'red' : 'blue';
500
- ctx.arc(bullet.x, bullet.y, bullet.size, 0, Math.PI * 2);
501
- ctx.fill();
502
- });
503
- // 아이템 그리기
504
- items.forEach(item => {
505
- ctx.beginPath();
506
- ctx.fillStyle = 'green';
507
- ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
508
- ctx.fill();
509
- });
510
- // UI 그리기
 
 
 
 
 
 
511
  ctx.fillStyle = 'white';
512
  ctx.font = '24px Arial';
513
  ctx.fillText(`Round ${currentRound}/10`, 10, 30);
514
  ctx.fillText(`Gold: ${gold}`, 10, 60);
515
 
516
- // 이펙트 그리기 (여기에 추가)
517
  effects = effects.filter(effect => !effect.isExpired());
518
  effects.forEach(effect => {
519
  ctx.save();
520
  ctx.translate(effect.x, effect.y);
521
  if(effect.type === 'fire') ctx.rotate(effect.angle);
522
- ctx.drawImage(effect.img, -25, -25, 50, 50); // 이펙트 크기 조정
523
  ctx.restore();
524
  });
525
 
@@ -527,18 +533,24 @@ function buyTank(tankImg, cost, tankId) {
527
  ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
528
  ctx.fillRect(0, 0, canvas.width, canvas.height);
529
  }
 
 
 
530
  function gameLoop() {
531
  updateGame();
532
  drawGame();
533
  requestAnimationFrame(gameLoop);
534
  }
 
535
  nextRoundBtn.addEventListener('click', () => {
536
  currentRound++;
537
  nextRoundBtn.style.display = 'none';
538
- document.getElementById('shop').style.display = 'none'; // 상점 창 닫기
539
  initRound();
540
  });
 
541
  bossButton.addEventListener('click', startBossStage);
 
542
  restartBtn.addEventListener('click', () => {
543
  currentRound = 1;
544
  gameOver = false;
@@ -552,19 +564,21 @@ restartBtn.addEventListener('click', () => {
552
  bgm.play();
553
  initRound();
554
  });
555
- Promise.all([
556
- new Promise(resolve => backgroundImg.onload = resolve),
557
- new Promise(resolve => playerImg.onload = resolve),
558
- new Promise(resolve => enemyImg.onload = resolve)
559
- ]).then(() => {
560
- initRound();
561
- gameLoop();
562
- bgm.play(); // 게임 시작시 BGM 재생
563
- });
564
- window.addEventListener('resize', () => {
565
- canvas.width = window.innerWidth;
566
- canvas.height = window.innerHeight;
567
- });
 
 
568
  </script>
569
  </body>
570
  </html>
 
471
  ctx.fillRect(x - width/2, y - height/2, width * (health/maxHealth), height);
472
  }
473
  function drawGame() {
474
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
475
+ const pattern = ctx.createPattern(backgroundImg, 'repeat');
476
+ ctx.fillStyle = pattern;
477
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
478
+
479
+ // 플레이어 그리기
480
+ ctx.save();
481
+ ctx.translate(player.x, player.y);
482
+ ctx.rotate(player.angle);
483
+ ctx.drawImage(playerImg, -player.width/2, -player.height/2, player.width, player.height);
484
+ ctx.restore();
485
+
486
+ // 체력바
487
+ drawHealthBar(canvas.width/2, 30, player.health, player.maxHealth, 200, 20, 'green');
488
+
489
+ // 적 그리기
490
+ enemies.forEach(enemy => {
491
+ ctx.save();
492
+ ctx.translate(enemy.x, enemy.y);
493
+ ctx.rotate(enemy.angle);
494
+ const img = enemy.isBoss ? enemy.enemyImg : (enemy.enemyImg || enemyImg);
495
+ ctx.drawImage(img, -enemy.width/2, -enemy.height/2, enemy.width, enemy.height);
496
+ ctx.restore();
497
+ drawHealthBar(enemy.x, enemy.y - 40, enemy.health, enemy.maxHealth, 60, 5, 'red');
498
+ });
499
+
500
+ // 총알 그리기
501
+ bullets.forEach(bullet => {
502
+ ctx.beginPath();
503
+ ctx.fillStyle = bullet.isEnemy ? 'red' : 'blue';
504
+ ctx.arc(bullet.x, bullet.y, bullet.size, 0, Math.PI * 2);
505
+ ctx.fill();
506
+ });
507
+
508
+ // 아이템 그리기
509
+ items.forEach(item => {
510
+ ctx.beginPath();
511
+ ctx.fillStyle = 'green';
512
+ ctx.arc(item.x, item.y, 10, 0, Math.PI * 2);
513
+ ctx.fill();
514
+ });
515
+
516
+ // UI 그리기
517
  ctx.fillStyle = 'white';
518
  ctx.font = '24px Arial';
519
  ctx.fillText(`Round ${currentRound}/10`, 10, 30);
520
  ctx.fillText(`Gold: ${gold}`, 10, 60);
521
 
522
+ // 이펙트 그리기
523
  effects = effects.filter(effect => !effect.isExpired());
524
  effects.forEach(effect => {
525
  ctx.save();
526
  ctx.translate(effect.x, effect.y);
527
  if(effect.type === 'fire') ctx.rotate(effect.angle);
528
+ ctx.drawImage(effect.img, -25, -25, 50, 50);
529
  ctx.restore();
530
  });
531
 
 
533
  ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
534
  ctx.fillRect(0, 0, canvas.width, canvas.height);
535
  }
536
+ }
537
+
538
+ // drawGame 함수 밖으로 이동
539
  function gameLoop() {
540
  updateGame();
541
  drawGame();
542
  requestAnimationFrame(gameLoop);
543
  }
544
+
545
  nextRoundBtn.addEventListener('click', () => {
546
  currentRound++;
547
  nextRoundBtn.style.display = 'none';
548
+ document.getElementById('shop').style.display = 'none';
549
  initRound();
550
  });
551
+
552
  bossButton.addEventListener('click', startBossStage);
553
+
554
  restartBtn.addEventListener('click', () => {
555
  currentRound = 1;
556
  gameOver = false;
 
564
  bgm.play();
565
  initRound();
566
  });
567
+
568
+ Promise.all([
569
+ new Promise(resolve => backgroundImg.onload = resolve),
570
+ new Promise(resolve => playerImg.onload = resolve),
571
+ new Promise(resolve => enemyImg.onload = resolve)
572
+ ]).then(() => {
573
+ initRound();
574
+ gameLoop();
575
+ bgm.play();
576
+ });
577
+
578
+ window.addEventListener('resize', () => {
579
+ canvas.width = window.innerWidth;
580
+ canvas.height = window.innerHeight;
581
+ });
582
  </script>
583
  </body>
584
  </html>