Update index.html
Browse files- index.html +86 -216
index.html
CHANGED
@@ -71,6 +71,9 @@
|
|
71 |
#nextRound {
|
72 |
top: 80%; /* ํ๋ฉด์ ์๋์ชฝ์ผ๋ก ์ด๋ */
|
73 |
z-index: 1000; /* "You Win"๋ณด๋ค ์๋๋ก ์ค์ */
|
|
|
|
|
|
|
74 |
}
|
75 |
</style>
|
76 |
</head>
|
@@ -132,8 +135,6 @@
|
|
132 |
</div>
|
133 |
<button id="bossButton" class="button">Fight Boss!</button>
|
134 |
<div id="winMessage" class="button" style="font-size: 72px; background: none;">You Win!</div>
|
135 |
-
<button id="nextStage" class="button">Next Stage</button>
|
136 |
-
|
137 |
|
138 |
|
139 |
<script>
|
@@ -147,7 +148,6 @@
|
|
147 |
canvas.width = window.innerWidth;
|
148 |
canvas.height = window.innerHeight;
|
149 |
// Game state
|
150 |
-
let currentStage = 1; // ์คํ
์ด์ง ์ถ๊ฐ
|
151 |
let currentRound = 1;
|
152 |
let gameOver = false;
|
153 |
let currentWeapon = 'cannon';
|
@@ -436,57 +436,35 @@
|
|
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.src = 'enemy2.png';
|
465 |
-
} else {
|
466 |
-
this.enemyImg.src = 'enemy.png';
|
467 |
-
}
|
468 |
-
} else { // ์คํ
์ด์ง 2
|
469 |
-
if (currentRound >= 7) {
|
470 |
-
this.enemyImg.src = 'enemyuk3.png';
|
471 |
-
} else if (currentRound >= 4) {
|
472 |
-
this.enemyImg.src = 'enemyuk2.png';
|
473 |
-
} else {
|
474 |
-
this.enemyImg.src = 'enemyuk1.png';
|
475 |
}
|
476 |
}
|
477 |
-
}
|
478 |
-
|
479 |
-
getHealth(isBoss) {
|
480 |
-
if (isBoss) return 15000;
|
481 |
-
if (currentStage === 1) {
|
482 |
-
return 1000; // ์คํ
์ด์ง 1์ ๊ธฐ์กด๊ณผ ๋์ผ
|
483 |
-
} else { // ์คํ
์ด์ง 2
|
484 |
-
if (currentRound >= 7) return 2000;
|
485 |
-
if (currentRound >= 4) return 1500;
|
486 |
-
return 1000;
|
487 |
-
}
|
488 |
-
}
|
489 |
-
|
490 |
update() {
|
491 |
if(isCountingDown) return;
|
492 |
const now = Date.now();
|
@@ -511,13 +489,13 @@
|
|
511 |
sound.play();
|
512 |
|
513 |
// ๋ฐ์ฌ ์ดํํธ ์ถ๊ฐ
|
514 |
-
|
515 |
this.x + Math.cos(this.angle) * 30,
|
516 |
this.y + Math.sin(this.angle) * 30,
|
517 |
500,
|
518 |
'fire',
|
519 |
this.angle,
|
520 |
-
this
|
521 |
));
|
522 |
|
523 |
bullets.push({
|
@@ -589,10 +567,9 @@ function buyTank(tankImg, cost, tankId) {
|
|
589 |
lastJU87Spawn = Date.now(); // ๊ตฌ๋งค ์ฆ์ ์คํฐ ํ์ด๋จธ ์ด๊ธฐํ
|
590 |
}
|
591 |
}
|
592 |
-
function initRound() {
|
593 |
enemies = [];
|
594 |
-
let
|
595 |
-
for(let i = 0; i < enemyCount; i++) {
|
596 |
enemies.push(new Enemy());
|
597 |
}
|
598 |
player.health = player.maxHealth;
|
@@ -601,24 +578,7 @@ function initRound() {
|
|
601 |
supportUnits = [];
|
602 |
lastSupportSpawn = 0;
|
603 |
|
604 |
-
//
|
605 |
-
if (currentStage === 2) {
|
606 |
-
const stage2Bg = new Image(); // ์๋ก์ด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ๊ฐ์ฒด ์์ฑ
|
607 |
-
stage2Bg.src = 'city2.png'; // 2์คํ
์ด์ง ๋ฐฐ๊ฒฝ ๊ฒฝ๋ก ์ค์
|
608 |
-
stage2Bg.onload = () => { // ์ด๋ฏธ์ง๊ฐ ๋ก๋๋ ๊ฒฝ์ฐ๋ง ๋ฐฐ๊ฒฝ ์ค์
|
609 |
-
backgroundImg.src = 'city2.png';
|
610 |
-
console.log('Stage 2 background loaded successfully');
|
611 |
-
};
|
612 |
-
stage2Bg.onerror = () => { // ์๋ฌ ๋ฐ์ ์ ๋ก๊ทธ ์ถ๋ ฅ
|
613 |
-
console.error('Failed to load Stage 2 background image: city2.png');
|
614 |
-
};
|
615 |
-
|
616 |
-
// ๋ฐฐ๊ฒฝ ์์
์ ํ
|
617 |
-
bgm.pause();
|
618 |
-
bgm.src = 'BGM3.ogg';
|
619 |
-
bgm.play();
|
620 |
-
}
|
621 |
-
|
622 |
startCountdown();
|
623 |
|
624 |
// ์นด์ดํธ๋ค์ด์ด ๋๋๋ฉด JU87 ์คํฐ
|
@@ -627,21 +587,19 @@ function initRound() {
|
|
627 |
supportUnits.push(new JU87());
|
628 |
lastJU87Spawn = Date.now();
|
629 |
}
|
630 |
-
}, 3000);
|
631 |
}
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
startCountdown();
|
644 |
-
}
|
645 |
canvas.addEventListener('mousemove', (e) => {
|
646 |
player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
|
647 |
});
|
@@ -774,27 +732,25 @@ function initRound() {
|
|
774 |
}
|
775 |
return true;
|
776 |
});
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
}
|
797 |
-
}
|
798 |
}
|
799 |
function spawnHealthItem(x, y) {
|
800 |
items.push({x, y});
|
@@ -905,129 +861,43 @@ nextRoundBtn.addEventListener('click', () => {
|
|
905 |
|
906 |
bossButton.addEventListener('click', startBossStage);
|
907 |
|
908 |
-
// ๋ค์ ์คํ
์ด์ง ๋ฒํผ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
909 |
-
document.getElementById('nextStage').addEventListener('click', () => {
|
910 |
-
currentStage++;
|
911 |
-
currentRound = 1;
|
912 |
-
isBossStage = false;
|
913 |
-
document.getElementById('nextStage').style.display = 'none';
|
914 |
-
// ์์ ์์ดํ
์ด๊ธฐํ ์ถ๊ฐ
|
915 |
-
document.getElementById('tank1').style.display = 'block';
|
916 |
-
document.getElementById('tank2').style.display = 'block';
|
917 |
-
document.getElementById('apcr').style.display = 'block';
|
918 |
-
document.getElementById('bf109').style.display = 'block';
|
919 |
-
document.getElementById('ju87').style.display = 'block';
|
920 |
-
// ๊ธฐ์กด ๊ตฌ๋งค ์ํ ์ด๊ธฐํ
|
921 |
-
hasAPCR = false;
|
922 |
-
hasBF109 = false;
|
923 |
-
hasJU87 = false;
|
924 |
-
supportUnits = [];
|
925 |
-
lastSupportSpawn = 0;
|
926 |
-
lastJU87Spawn = 0;
|
927 |
-
// ํ๋ ์ด์ด ์ด๊ธฐํ
|
928 |
-
player.health = player.maxHealth;
|
929 |
-
playerImg.src = 'player.png';
|
930 |
-
gold = 0;
|
931 |
-
initRound();
|
932 |
-
});
|
933 |
-
|
934 |
restartBtn.addEventListener('click', () => {
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
supportUnits = []; // ์ง์ ๏ฟฝ๏ฟฝ๏ฟฝ๋ ๋ฐฐ์ด ์ด๊ธฐํ
|
944 |
-
|
945 |
-
restartBtn.style.display = 'none';
|
946 |
-
document.getElementById('winMessage').style.display = 'none';
|
947 |
-
document.getElementById('tank1').style.display = 'block';
|
948 |
-
document.getElementById('tank2').style.display = 'block';
|
949 |
-
document.getElementById('apcr').style.display = 'block';
|
950 |
-
document.getElementById('bf109').style.display = 'block'; // BF109 ์์ ์์ดํ
๋ค์ ํ์
|
951 |
-
document.getElementById('ju87').style.display = 'block'; // JU87 ์์ ์์ดํ
๋ค์ ํ์
|
952 |
-
|
953 |
-
playerImg.src = 'player.png';
|
954 |
-
bgm.src = 'BGM2.ogg';
|
955 |
-
bgm.play();
|
956 |
-
initRound();
|
957 |
-
});
|
958 |
-
Promise.allSettled([
|
959 |
-
// ๊ธฐ๋ณธ ์ด๋ฏธ์ง ๋ก๋ฉ
|
960 |
-
new Promise((resolve, reject) => {
|
961 |
-
backgroundImg.onload = resolve;
|
962 |
-
backgroundImg.onerror = () => reject('Background image failed');
|
963 |
-
}),
|
964 |
-
new Promise((resolve, reject) => {
|
965 |
-
playerImg.onload = resolve;
|
966 |
-
playerImg.onerror = () => reject('Player image failed');
|
967 |
-
}),
|
968 |
-
new Promise((resolve, reject) => {
|
969 |
-
enemyImg.onload = resolve;
|
970 |
-
enemyImg.onerror = () => reject('Enemy image failed');
|
971 |
-
}),
|
972 |
-
new Promise((resolve, reject) => {
|
973 |
-
bulletImg.onload = resolve;
|
974 |
-
bulletImg.onerror = () => reject('Bullet image failed');
|
975 |
-
}),
|
976 |
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
}),
|
984 |
-
new Promise((resolve, reject) => {
|
985 |
-
const bangImg = new Image();
|
986 |
-
bangImg.src = 'bang.png';
|
987 |
-
bangImg.onload = resolve;
|
988 |
-
bangImg.onerror = () => reject('Effect image (bang.png) failed');
|
989 |
-
}),
|
990 |
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
bf109Img.onerror = () => reject('BF109 image failed');
|
997 |
-
}),
|
998 |
-
new Promise((resolve, reject) => {
|
999 |
-
const ju87Img = new Image();
|
1000 |
-
ju87Img.src = 'ju87.png';
|
1001 |
-
ju87Img.onload = resolve;
|
1002 |
-
ju87Img.onerror = () => reject('JU87 image failed');
|
1003 |
-
}),
|
1004 |
-
|
1005 |
-
// ์คํ
์ด์ง 2 ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ ๋ก๋ฉ
|
1006 |
-
new Promise((resolve, reject) => {
|
1007 |
-
const stage2Bg = new Image();
|
1008 |
-
stage2Bg.src = 'city2.png';
|
1009 |
-
stage2Bg.onload = resolve;
|
1010 |
-
stage2Bg.onerror = () => reject('Stage 2 background image failed');
|
1011 |
-
})
|
1012 |
-
]).then(results => {
|
1013 |
-
const errors = results.filter(result => result.status === 'rejected');
|
1014 |
-
if (errors.length > 0) {
|
1015 |
-
console.error('์ด๋ฏธ์ง ๋ก๋ฉ ์คํจ:', errors.map(err => err.reason));
|
1016 |
-
}
|
1017 |
|
1018 |
-
|
|
|
|
|
|
|
|
|
1019 |
initRound();
|
1020 |
gameLoop();
|
1021 |
bgm.play();
|
1022 |
-
}).catch(error => {
|
1023 |
-
console.error('Unexpected error occurred:', error);
|
1024 |
});
|
1025 |
|
1026 |
window.addEventListener('resize', () => {
|
1027 |
canvas.width = window.innerWidth;
|
1028 |
canvas.height = window.innerHeight;
|
1029 |
});
|
1030 |
-
|
1031 |
</script>
|
1032 |
</body>
|
1033 |
</html>
|
|
|
71 |
#nextRound {
|
72 |
top: 80%; /* ํ๋ฉด์ ์๋์ชฝ์ผ๋ก ์ด๋ */
|
73 |
z-index: 1000; /* "You Win"๋ณด๋ค ์๋๋ก ์ค์ */
|
74 |
+
}
|
75 |
+
#nextRound {
|
76 |
+
top: 80%; /* ์๋์ชฝ์ผ๋ก ์ด๋ */
|
77 |
}
|
78 |
</style>
|
79 |
</head>
|
|
|
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>
|
|
|
148 |
canvas.width = window.innerWidth;
|
149 |
canvas.height = window.innerHeight;
|
150 |
// Game state
|
|
|
151 |
let currentRound = 1;
|
152 |
let gameOver = false;
|
153 |
let currentWeapon = 'cannon';
|
|
|
436 |
return true;
|
437 |
}
|
438 |
}
|
439 |
+
|
440 |
+
class Enemy {
|
441 |
+
constructor(isBoss = false) {
|
442 |
+
this.x = Math.random() * canvas.width;
|
443 |
+
this.y = Math.random() * canvas.height;
|
444 |
+
this.health = isBoss ? 15000 : 1000;
|
445 |
+
this.maxHealth = this.health;
|
446 |
+
this.speed = isBoss ? 1 : 2;
|
447 |
+
this.lastShot = 0;
|
448 |
+
this.shootInterval = isBoss ? 1000 : 1000;
|
449 |
+
this.angle = 0;
|
450 |
+
this.width = 100;
|
451 |
+
this.height = 45;
|
452 |
+
this.moveTimer = 0;
|
453 |
+
this.moveInterval = Math.random() * 2000 + 1000;
|
454 |
+
this.moveAngle = Math.random() * Math.PI * 2;
|
455 |
+
this.isBoss = isBoss;
|
456 |
|
457 |
+
if (isBoss) {
|
458 |
+
this.enemyImg = new Image();
|
459 |
+
this.enemyImg.src = 'boss.png';
|
460 |
+
} else if (currentRound >= 7) {
|
461 |
+
this.enemyImg = new Image();
|
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();
|
|
|
489 |
sound.play();
|
490 |
|
491 |
// ๋ฐ์ฌ ์ดํํธ ์ถ๊ฐ
|
492 |
+
effects.push(new Effect(
|
493 |
this.x + Math.cos(this.angle) * 30,
|
494 |
this.y + Math.sin(this.angle) * 30,
|
495 |
500,
|
496 |
'fire',
|
497 |
this.angle,
|
498 |
+
this // ์์ ์ ๋ถ๋ชจ๋ก ์ ๋ฌ
|
499 |
));
|
500 |
|
501 |
bullets.push({
|
|
|
567 |
lastJU87Spawn = Date.now(); // ๊ตฌ๋งค ์ฆ์ ์คํฐ ํ์ด๋จธ ์ด๊ธฐํ
|
568 |
}
|
569 |
}
|
570 |
+
function initRound() {
|
571 |
enemies = [];
|
572 |
+
for(let i = 0; i < 1 * currentRound; i++) {
|
|
|
573 |
enemies.push(new Enemy());
|
574 |
}
|
575 |
player.health = player.maxHealth;
|
|
|
578 |
supportUnits = [];
|
579 |
lastSupportSpawn = 0;
|
580 |
|
581 |
+
// ์นด์ดํธ๋ค์ด ์์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
startCountdown();
|
583 |
|
584 |
// ์นด์ดํธ๋ค์ด์ด ๋๋๋ฉด JU87 ์คํฐ
|
|
|
587 |
supportUnits.push(new JU87());
|
588 |
lastJU87Spawn = Date.now();
|
589 |
}
|
590 |
+
}, 3000); // 3์ด ํ์ ์คํฐ
|
591 |
}
|
592 |
+
function startBossStage() {
|
593 |
+
isBossStage = true;
|
594 |
+
enemies = [];
|
595 |
+
enemies.push(new Enemy(true));
|
596 |
+
player.health = player.maxHealth;
|
597 |
+
bullets = [];
|
598 |
+
items = [];
|
599 |
+
document.getElementById('bossButton').style.display = 'none';
|
600 |
+
bgm.src = 'BGM.ogg'; // ๋ณด์ค์ BGM์ผ๋ก ๋ณ๊ฒฝ
|
601 |
+
startCountdown();
|
602 |
+
}
|
|
|
|
|
603 |
canvas.addEventListener('mousemove', (e) => {
|
604 |
player.angle = Math.atan2(e.clientY - player.y, e.clientX - player.x);
|
605 |
});
|
|
|
732 |
}
|
733 |
return true;
|
734 |
});
|
735 |
+
if(enemies.length === 0) {
|
736 |
+
if (!isBossStage) {
|
737 |
+
if(currentRound < 10) {
|
738 |
+
nextRoundBtn.style.display = 'block';
|
739 |
+
showShop();
|
740 |
+
} else {
|
741 |
+
document.getElementById('bossButton').style.display = 'block';
|
742 |
+
}
|
743 |
+
} else {
|
744 |
+
gameOver = true;
|
745 |
+
document.getElementById('winMessage').style.display = 'block';
|
746 |
+
restartBtn.style.display = 'block';
|
747 |
+
bgm.pause(); // ํ์ฌ BGM ์ ์ง
|
748 |
+
const victorySound = new Audio('victory.ogg'); // ์น๋ฆฌ ์ฌ์ด๋ ์์ฑ
|
749 |
+
victorySound.play(); // ์น๋ฆฌ ์ฌ์ด๋ ์ฌ์
|
750 |
+
}
|
751 |
+
}
|
752 |
+
}
|
753 |
+
enemies.forEach(enemy => enemy.update());
|
|
|
|
|
754 |
}
|
755 |
function spawnHealthItem(x, y) {
|
756 |
items.push({x, y});
|
|
|
861 |
|
862 |
bossButton.addEventListener('click', startBossStage);
|
863 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
864 |
restartBtn.addEventListener('click', () => {
|
865 |
+
currentRound = 1;
|
866 |
+
gameOver = false;
|
867 |
+
isBossStage = false;
|
868 |
+
gold = 0;
|
869 |
+
hasAPCR = false; // APCR ์ด๊ธฐํ
|
870 |
+
hasBF109 = false; // BF109 ์ด๊ธฐํ
|
871 |
+
hasJU87 = false;
|
872 |
+
supportUnits = []; // ์ง์ ์ ๋ ๋ฐฐ์ด ์ด๊ธฐํ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
873 |
|
874 |
+
restartBtn.style.display = 'none';
|
875 |
+
document.getElementById('winMessage').style.display = 'none';
|
876 |
+
document.getElementById('tank1').style.display = 'block';
|
877 |
+
document.getElementById('tank2').style.display = 'block';
|
878 |
+
document.getElementById('apcr').style.display = 'block';
|
879 |
+
document.getElementById('bf109').style.display = 'block'; // BF109 ์์ ์์ดํ
๋ค์ ํ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
880 |
|
881 |
+
playerImg.src = 'player.png';
|
882 |
+
bgm.src = 'BGM2.ogg';
|
883 |
+
bgm.play();
|
884 |
+
initRound();
|
885 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
886 |
|
887 |
+
Promise.all([
|
888 |
+
new Promise(resolve => backgroundImg.onload = resolve),
|
889 |
+
new Promise(resolve => playerImg.onload = resolve),
|
890 |
+
new Promise(resolve => enemyImg.onload = resolve)
|
891 |
+
]).then(() => {
|
892 |
initRound();
|
893 |
gameLoop();
|
894 |
bgm.play();
|
|
|
|
|
895 |
});
|
896 |
|
897 |
window.addEventListener('resize', () => {
|
898 |
canvas.width = window.innerWidth;
|
899 |
canvas.height = window.innerHeight;
|
900 |
});
|
|
|
901 |
</script>
|
902 |
</body>
|
903 |
</html>
|