Update index.html
Browse files- index.html +98 -54
index.html
CHANGED
@@ -135,6 +135,8 @@
|
|
135 |
</div>
|
136 |
<button id="bossButton" class="button">Fight Boss!</button>
|
137 |
<div id="winMessage" class="button" style="font-size: 72px; background: none;">You Win!</div>
|
|
|
|
|
138 |
|
139 |
|
140 |
<script>
|
@@ -436,35 +438,57 @@
|
|
436 |
return true;
|
437 |
}
|
438 |
}
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
this.enemyImg.src = 'enemy3.png';
|
463 |
} else if (currentRound >= 4) {
|
464 |
-
this.enemyImg = new Image();
|
465 |
this.enemyImg.src = 'enemy2.png';
|
|
|
|
|
466 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
}
|
|
|
|
|
468 |
update() {
|
469 |
if(isCountingDown) return;
|
470 |
const now = Date.now();
|
@@ -567,9 +591,10 @@ function buyTank(tankImg, cost, tankId) {
|
|
567 |
lastJU87Spawn = Date.now(); // ๊ตฌ๋งค ์ฆ์ ์คํฐ ํ์ด๋จธ ์ด๊ธฐํ
|
568 |
}
|
569 |
}
|
570 |
-
|
571 |
enemies = [];
|
572 |
-
|
|
|
573 |
enemies.push(new Enemy());
|
574 |
}
|
575 |
player.health = player.maxHealth;
|
@@ -578,6 +603,11 @@ function buyTank(tankImg, cost, tankId) {
|
|
578 |
supportUnits = [];
|
579 |
lastSupportSpawn = 0;
|
580 |
|
|
|
|
|
|
|
|
|
|
|
581 |
// ์นด์ดํธ๋ค์ด ์์
|
582 |
startCountdown();
|
583 |
|
@@ -589,17 +619,19 @@ function buyTank(tankImg, cost, tankId) {
|
|
589 |
}
|
590 |
}, 3000); // 3์ด ํ์ ์คํฐ
|
591 |
}
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
|
|
|
|
603 |
canvas.addEventListener('mousemove', (e) => {
|
604 |
player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
|
605 |
});
|
@@ -732,24 +764,27 @@ function buyTank(tankImg, cost, tankId) {
|
|
732 |
}
|
733 |
return true;
|
734 |
});
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
|
|
|
|
|
|
753 |
enemies.forEach(enemy => enemy.update());
|
754 |
}
|
755 |
function spawnHealthItem(x, y) {
|
@@ -861,6 +896,15 @@ nextRoundBtn.addEventListener('click', () => {
|
|
861 |
|
862 |
bossButton.addEventListener('click', startBossStage);
|
863 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
864 |
restartBtn.addEventListener('click', () => {
|
865 |
currentRound = 1;
|
866 |
gameOver = false;
|
|
|
135 |
</div>
|
136 |
<button id="bossButton" class="button">Fight Boss!</button>
|
137 |
<div id="winMessage" class="button" style="font-size: 72px; background: none;">You Win!</div>
|
138 |
+
<button id="nextStage" class="button">Next Stage</button>
|
139 |
+
|
140 |
|
141 |
|
142 |
<script>
|
|
|
438 |
return true;
|
439 |
}
|
440 |
}
|
441 |
+
|
442 |
+
class Enemy {
|
443 |
+
constructor(isBoss = false) {
|
444 |
+
this.x = Math.random() * canvas.width;
|
445 |
+
this.y = Math.random() * canvas.height;
|
446 |
+
this.health = this.getHealth(isBoss);
|
447 |
+
this.maxHealth = this.health;
|
448 |
+
this.speed = isBoss ? 1 : 2;
|
449 |
+
this.lastShot = 0;
|
450 |
+
this.shootInterval = isBoss ? 1000 : 1000;
|
451 |
+
this.angle = 0;
|
452 |
+
this.width = 100;
|
453 |
+
this.height = 45;
|
454 |
+
this.moveTimer = 0;
|
455 |
+
this.moveInterval = Math.random() * 2000 + 1000;
|
456 |
+
this.moveAngle = Math.random() * Math.PI * 2;
|
457 |
+
this.isBoss = isBoss;
|
458 |
|
459 |
+
this.enemyImg = new Image();
|
460 |
+
if (isBoss) {
|
461 |
+
this.enemyImg.src = currentStage === 1 ? 'boss.png' : 'enemyukboss.png';
|
462 |
+
} else if (currentStage === 1) {
|
463 |
+
if (currentRound >= 7) {
|
464 |
this.enemyImg.src = 'enemy3.png';
|
465 |
} else if (currentRound >= 4) {
|
|
|
466 |
this.enemyImg.src = 'enemy2.png';
|
467 |
+
} else {
|
468 |
+
this.enemyImg.src = 'enemy.png';
|
469 |
}
|
470 |
+
} else { // ์คํ
์ด์ง 2
|
471 |
+
if (currentRound >= 7) {
|
472 |
+
this.enemyImg.src = 'enemyuk3.png';
|
473 |
+
} else if (currentRound >= 4) {
|
474 |
+
this.enemyImg.src = 'enemyuk2.png';
|
475 |
+
} else {
|
476 |
+
this.enemyImg.src = 'enemyuk1.png';
|
477 |
+
}
|
478 |
+
}
|
479 |
+
}
|
480 |
+
|
481 |
+
getHealth(isBoss) {
|
482 |
+
if (isBoss) return 15000;
|
483 |
+
if (currentStage === 1) {
|
484 |
+
return 1000; // ์คํ
์ด์ง 1์ ๊ธฐ์กด๊ณผ ๋์ผ
|
485 |
+
} else { // ์คํ
์ด์ง 2
|
486 |
+
if (currentRound >= 7) return 2000;
|
487 |
+
if (currentRound >= 4) return 1500;
|
488 |
+
return 1000;
|
489 |
}
|
490 |
+
}
|
491 |
+
|
492 |
update() {
|
493 |
if(isCountingDown) return;
|
494 |
const now = Date.now();
|
|
|
591 |
lastJU87Spawn = Date.now(); // ๊ตฌ๋งค ์ฆ์ ์คํฐ ํ์ด๋จธ ์ด๊ธฐํ
|
592 |
}
|
593 |
}
|
594 |
+
function initRound() {
|
595 |
enemies = [];
|
596 |
+
let enemyCount = currentStage === 1 ? currentRound : (2 + currentRound); // 2์คํ
์ด์ง๋ 3๊ฐ๋ถํฐ ์์
|
597 |
+
for(let i = 0; i < enemyCount; i++) {
|
598 |
enemies.push(new Enemy());
|
599 |
}
|
600 |
player.health = player.maxHealth;
|
|
|
603 |
supportUnits = [];
|
604 |
lastSupportSpawn = 0;
|
605 |
|
606 |
+
if (currentStage === 2) {
|
607 |
+
backgroundImg.src = 'city2.png';
|
608 |
+
bgm.src = 'BGM3.ogg';
|
609 |
+
}
|
610 |
+
|
611 |
// ์นด์ดํธ๋ค์ด ์์
|
612 |
startCountdown();
|
613 |
|
|
|
619 |
}
|
620 |
}, 3000); // 3์ด ํ์ ์คํฐ
|
621 |
}
|
622 |
+
function startBossStage() {
|
623 |
+
isBossStage = true;
|
624 |
+
enemies = [];
|
625 |
+
enemies.push(new Enemy(true));
|
626 |
+
player.health = player.maxHealth;
|
627 |
+
bullets = [];
|
628 |
+
items = [];
|
629 |
+
document.getElementById('bossButton').style.display = 'none';
|
630 |
+
if (currentStage === 1) {
|
631 |
+
bgm.src = 'BGM.ogg';
|
632 |
+
}
|
633 |
+
startCountdown();
|
634 |
+
}
|
635 |
canvas.addEventListener('mousemove', (e) => {
|
636 |
player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
|
637 |
});
|
|
|
764 |
}
|
765 |
return true;
|
766 |
});
|
767 |
+
if(enemies.length === 0) {
|
768 |
+
if (!isBossStage) {
|
769 |
+
if(currentRound < 10) {
|
770 |
+
nextRoundBtn.style.display = 'block';
|
771 |
+
showShop();
|
772 |
+
} else {
|
773 |
+
document.getElementById('bossButton').style.display = 'block';
|
774 |
+
}
|
775 |
+
} else {
|
776 |
+
if (currentStage === 1) { // 1์คํ
์ด์ง ๋ณด์ค ์ฒ์น
|
777 |
+
document.getElementById('nextStage').style.display = 'block';
|
778 |
+
} else { // 2์คํ
์ด์ง ๋ณด์ค ์ฒ์น
|
779 |
+
gameOver = true;
|
780 |
+
document.getElementById('winMessage').style.display = 'block';
|
781 |
+
restartBtn.style.display = 'block';
|
782 |
+
bgm.pause(); // ํ์ฌ BGM ์ ์ง
|
783 |
+
const victorySound = new Audio('victory.ogg');
|
784 |
+
victorySound.play();
|
785 |
+
}
|
786 |
+
}
|
787 |
+
}
|
788 |
enemies.forEach(enemy => enemy.update());
|
789 |
}
|
790 |
function spawnHealthItem(x, y) {
|
|
|
896 |
|
897 |
bossButton.addEventListener('click', startBossStage);
|
898 |
|
899 |
+
// ๋ค์ ์คํ
์ด์ง ๋ฒํผ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
900 |
+
document.getElementById('nextStage').addEventListener('click', () => {
|
901 |
+
currentStage++;
|
902 |
+
currentRound = 1;
|
903 |
+
isBossStage = false;
|
904 |
+
document.getElementById('nextStage').style.display = 'none';
|
905 |
+
initRound();
|
906 |
+
});
|
907 |
+
|
908 |
restartBtn.addEventListener('click', () => {
|
909 |
currentRound = 1;
|
910 |
gameOver = false;
|