Spaces:
Running
Running
cutechicken
commited on
Update index.html
Browse files- index.html +121 -92
index.html
CHANGED
@@ -592,27 +592,48 @@ nextRoundBtn.addEventListener('click', () => {
|
|
592 |
initRound();
|
593 |
});
|
594 |
|
|
|
595 |
restartBtn.addEventListener('click', () => {
|
|
|
596 |
currentRound = 1;
|
597 |
gameOver = false;
|
|
|
598 |
player.health = player.maxHealth;
|
599 |
gold = 0;
|
600 |
hasAPCR = false;
|
601 |
hasBF109 = false;
|
602 |
hasJU87 = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
603 |
document.getElementById('apcr').style.display = 'block';
|
604 |
document.getElementById('bf109').style.display = 'block';
|
605 |
document.getElementById('ju87').style.display = 'block';
|
606 |
document.getElementById('tank1').style.display = 'block';
|
607 |
document.getElementById('tank2').style.display = 'block';
|
608 |
document.getElementById('winMessage').style.display = 'none';
|
|
|
609 |
restartBtn.style.display = 'none';
|
|
|
|
|
610 |
playerImg.src = 'player.png';
|
611 |
player.maxHealth = defaultPlayerStats.maxHealth;
|
612 |
player.speed = defaultPlayerStats.speed;
|
613 |
player.width = defaultPlayerStats.width;
|
614 |
player.height = defaultPlayerStats.height;
|
|
|
|
|
|
|
|
|
615 |
bgm.src = 'BGM2.ogg';
|
|
|
|
|
|
|
|
|
616 |
initRound();
|
617 |
});
|
618 |
|
@@ -682,26 +703,31 @@ function buyJU87() {
|
|
682 |
lastJU87Spawn = Date.now();
|
683 |
}
|
684 |
}
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
|
|
|
|
|
|
|
|
|
|
695 |
|
696 |
-
|
697 |
|
698 |
-
setTimeout(() => {
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
}, 3000);
|
704 |
-
|
705 |
function startBossStage() {
|
706 |
isBossStage = true;
|
707 |
enemies = [];
|
@@ -713,93 +739,96 @@ document.getElementById('bossButton').style.display = 'none';
|
|
713 |
bgm.src = 'BGM.ogg';
|
714 |
startCountdown();
|
715 |
}
|
716 |
-
function updateGame() {
|
717 |
-
if(gameOver) return;
|
718 |
-
if(!isCountingDown) {
|
719 |
-
if(keys['w']) player.y -= player.speed;
|
720 |
-
if(keys['s']) player.y += player.speed;
|
721 |
-
if(keys['a']) player.x -= player.speed;
|
722 |
-
if(keys['d']) player.x += player.speed;
|
723 |
-
player.x = Math.max(player.width/2, Math.min(canvas.width - player.width/2, player.x));
|
724 |
-
player.y = Math.max(player.height/2, Math.min(canvas.height - player.height/2, player.y));
|
725 |
-
fireBullet();
|
726 |
-
}
|
727 |
-
if (hasBF109 && !isCountingDown) {
|
728 |
-
const now = Date.now();
|
729 |
-
if (now - lastSupportSpawn > 10000) {
|
730 |
-
supportUnits.push(
|
731 |
-
new SupportUnit(canvas.height * 0.2),
|
732 |
-
new SupportUnit(canvas.height * 0.5),
|
733 |
-
new SupportUnit(canvas.height * 0.8)
|
734 |
-
);
|
735 |
-
lastSupportSpawn = now;
|
736 |
}
|
737 |
-
|
738 |
-
|
739 |
-
if (
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
|
|
|
|
|
|
744 |
}
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
758 |
if(dist < 30) {
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
effects.push(new Effect(enemy.x, enemy.y, 1000, 'death'));
|
765 |
deathSound.cloneNode().play();
|
766 |
-
return false;
|
767 |
}
|
768 |
-
return
|
769 |
}
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
|
|
|
|
|
|
774 |
if(dist < 30) {
|
775 |
-
player.health
|
776 |
-
if(player.health <= 0) {
|
777 |
-
gameOver = true;
|
778 |
-
restartBtn.style.display = 'block';
|
779 |
-
effects.push(new Effect(player.x, player.y, 1000, 'death'));
|
780 |
-
deathSound.cloneNode().play();
|
781 |
-
}
|
782 |
return false;
|
783 |
}
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
items = items.filter(item => {
|
790 |
-
const dist = Math.hypot(item.x - player.x, item.y - player.y);
|
791 |
-
if(dist < 30) {
|
792 |
-
player.health = Math.min(player.health + 200, player.maxHealth);
|
793 |
-
return false;
|
794 |
-
}
|
795 |
-
return true;
|
796 |
-
});
|
797 |
-
|
798 |
if(enemies.length === 0) {
|
799 |
if (!isBossStage) {
|
800 |
if(currentRound < 10) {
|
801 |
nextRoundBtn.style.display = 'block';
|
802 |
showShop();
|
|
|
|
|
803 |
} else {
|
804 |
bossButton.style.display = 'block';
|
805 |
}
|
@@ -812,7 +841,7 @@ if(!isCountingDown) {
|
|
812 |
victorySound.play();
|
813 |
}
|
814 |
}
|
815 |
-
}
|
816 |
}
|
817 |
function spawnHealthItem(x, y) {
|
818 |
items.push({x, y});
|
|
|
592 |
initRound();
|
593 |
});
|
594 |
|
595 |
+
r// restartBtn ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์์
|
596 |
restartBtn.addEventListener('click', () => {
|
597 |
+
// ๊ฒ์ ์ํ ์์ ์ด๊ธฐํ
|
598 |
currentRound = 1;
|
599 |
gameOver = false;
|
600 |
+
isBossStage = false;
|
601 |
player.health = player.maxHealth;
|
602 |
gold = 0;
|
603 |
hasAPCR = false;
|
604 |
hasBF109 = false;
|
605 |
hasJU87 = false;
|
606 |
+
enemies = [];
|
607 |
+
bullets = [];
|
608 |
+
items = [];
|
609 |
+
supportUnits = [];
|
610 |
+
effects = [];
|
611 |
+
|
612 |
+
// UI ์์ ์ด๊ธฐํ
|
613 |
document.getElementById('apcr').style.display = 'block';
|
614 |
document.getElementById('bf109').style.display = 'block';
|
615 |
document.getElementById('ju87').style.display = 'block';
|
616 |
document.getElementById('tank1').style.display = 'block';
|
617 |
document.getElementById('tank2').style.display = 'block';
|
618 |
document.getElementById('winMessage').style.display = 'none';
|
619 |
+
document.getElementById('bossButton').style.display = 'none';
|
620 |
restartBtn.style.display = 'none';
|
621 |
+
|
622 |
+
// ํ๋ ์ด์ด ์ด๊ธฐํ
|
623 |
playerImg.src = 'player.png';
|
624 |
player.maxHealth = defaultPlayerStats.maxHealth;
|
625 |
player.speed = defaultPlayerStats.speed;
|
626 |
player.width = defaultPlayerStats.width;
|
627 |
player.height = defaultPlayerStats.height;
|
628 |
+
player.health = player.maxHealth;
|
629 |
+
|
630 |
+
// BGM ์ด๊ธฐํ
|
631 |
+
bgm.pause();
|
632 |
bgm.src = 'BGM2.ogg';
|
633 |
+
bgm.currentTime = 0;
|
634 |
+
bgm.play().catch(err => console.error("Error playing game music:", err));
|
635 |
+
|
636 |
+
// ๊ฒ์ ์ฌ์์
|
637 |
initRound();
|
638 |
});
|
639 |
|
|
|
703 |
lastJU87Spawn = Date.now();
|
704 |
}
|
705 |
}
|
706 |
+
// initRound ํจ์ ์์
|
707 |
+
function initRound() {
|
708 |
+
enemies = [];
|
709 |
+
for(let i = 0; i < 1 * currentRound; i++) {
|
710 |
+
enemies.push(new Enemy());
|
711 |
+
}
|
712 |
+
player.health = player.maxHealth;
|
713 |
+
bullets = [];
|
714 |
+
items = [];
|
715 |
+
supportUnits = [];
|
716 |
+
lastSupportSpawn = 0;
|
717 |
+
|
718 |
+
// ๋ชจ๋ UI ์์ ์จ๊ธฐ๊ธฐ
|
719 |
+
nextRoundBtn.style.display = 'none';
|
720 |
+
document.getElementById('shop').style.display = 'none';
|
721 |
|
722 |
+
startCountdown();
|
723 |
|
724 |
+
setTimeout(() => {
|
725 |
+
if (hasJU87) {
|
726 |
+
supportUnits.push(new JU87());
|
727 |
+
lastJU87Spawn = Date.now();
|
728 |
+
}
|
729 |
+
}, 3000);
|
730 |
+
}
|
731 |
function startBossStage() {
|
732 |
isBossStage = true;
|
733 |
enemies = [];
|
|
|
739 |
bgm.src = 'BGM.ogg';
|
740 |
startCountdown();
|
741 |
}
|
742 |
+
function updateGame() {
|
743 |
+
if(gameOver) return;
|
744 |
+
if(!isCountingDown) {
|
745 |
+
if(keys['w']) player.y -= player.speed;
|
746 |
+
if(keys['s']) player.y += player.speed;
|
747 |
+
if(keys['a']) player.x -= player.speed;
|
748 |
+
if(keys['d']) player.x += player.speed;
|
749 |
+
player.x = Math.max(player.width/2, Math.min(canvas.width - player.width/2, player.x));
|
750 |
+
player.y = Math.max(player.height/2, Math.min(canvas.height - player.height/2, player.y));
|
751 |
+
fireBullet();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
752 |
}
|
753 |
+
if (hasBF109 && !isCountingDown) {
|
754 |
+
const now = Date.now();
|
755 |
+
if (now - lastSupportSpawn > 10000) {
|
756 |
+
supportUnits.push(
|
757 |
+
new SupportUnit(canvas.height * 0.2),
|
758 |
+
new SupportUnit(canvas.height * 0.5),
|
759 |
+
new SupportUnit(canvas.height * 0.8)
|
760 |
+
);
|
761 |
+
lastSupportSpawn = now;
|
762 |
+
}
|
763 |
}
|
764 |
+
|
765 |
+
if (hasJU87 && !isCountingDown) {
|
766 |
+
const now = Date.now();
|
767 |
+
if (now - lastJU87Spawn > 15000) {
|
768 |
+
supportUnits.push(new JU87());
|
769 |
+
lastJU87Spawn = now;
|
770 |
+
}
|
771 |
+
}
|
772 |
+
|
773 |
+
supportUnits = supportUnits.filter(unit => unit.update());
|
774 |
+
|
775 |
+
enemies.forEach(enemy => enemy.update());
|
776 |
+
|
777 |
+
if(!isCountingDown) {
|
778 |
+
bullets = bullets.filter(bullet => {
|
779 |
+
bullet.x += Math.cos(bullet.angle) * bullet.speed;
|
780 |
+
bullet.y += Math.sin(bullet.angle) * bullet.speed;
|
781 |
+
if(!bullet.isEnemy) {
|
782 |
+
enemies = enemies.filter(enemy => {
|
783 |
+
const dist = Math.hypot(bullet.x - enemy.x, bullet.y - enemy.y);
|
784 |
+
if(dist < 30) {
|
785 |
+
let damage = currentWeapon === 'cannon' ? 250 : 50;
|
786 |
+
enemy.health -= damage;
|
787 |
+
if(enemy.health <= 0) {
|
788 |
+
spawnHealthItem(enemy.x, enemy.y);
|
789 |
+
gold += 100;
|
790 |
+
effects.push(new Effect(enemy.x, enemy.y, 1000, 'death'));
|
791 |
+
deathSound.cloneNode().play();
|
792 |
+
return false;
|
793 |
+
}
|
794 |
+
return true;
|
795 |
+
}
|
796 |
+
return true;
|
797 |
+
});
|
798 |
+
} else {
|
799 |
+
const dist = Math.hypot(bullet.x - player.x, bullet.y - player.y);
|
800 |
if(dist < 30) {
|
801 |
+
player.health -= bullet.damage || 100;
|
802 |
+
if(player.health <= 0) {
|
803 |
+
gameOver = true;
|
804 |
+
restartBtn.style.display = 'block';
|
805 |
+
effects.push(new Effect(player.x, player.y, 1000, 'death'));
|
|
|
806 |
deathSound.cloneNode().play();
|
|
|
807 |
}
|
808 |
+
return false;
|
809 |
}
|
810 |
+
}
|
811 |
+
return bullet.x >= 0 && bullet.x <= canvas.width &&
|
812 |
+
bullet.y >= 0 && bullet.y <= canvas.height;
|
813 |
+
});
|
814 |
+
|
815 |
+
items = items.filter(item => {
|
816 |
+
const dist = Math.hypot(item.x - player.x, item.y - player.y);
|
817 |
if(dist < 30) {
|
818 |
+
player.health = Math.min(player.health + 200, player.maxHealth);
|
|
|
|
|
|
|
|
|
|
|
|
|
819 |
return false;
|
820 |
}
|
821 |
+
return true;
|
822 |
+
});
|
823 |
+
|
824 |
+
// updateGame ํจ์ ๋ด์ enemies.length === 0 ์ฒ๋ฆฌ ๋ถ๋ถ ์์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
if(enemies.length === 0) {
|
826 |
if (!isBossStage) {
|
827 |
if(currentRound < 10) {
|
828 |
nextRoundBtn.style.display = 'block';
|
829 |
showShop();
|
830 |
+
// ์ฌ๋ฌ ๋ฒ ์คํ๋๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด ๋น ๋ฐฐ์ด ์ถ๊ฐ
|
831 |
+
enemies.push({health: -1}); // ์์ enemy ์ถ๊ฐ๋ก ์ค๋ณต ์คํ ๋ฐฉ์ง
|
832 |
} else {
|
833 |
bossButton.style.display = 'block';
|
834 |
}
|
|
|
841 |
victorySound.play();
|
842 |
}
|
843 |
}
|
844 |
+
}
|
845 |
}
|
846 |
function spawnHealthItem(x, y) {
|
847 |
items.push({x, y});
|