cutechicken commited on
Commit
a2229ab
ยท
verified ยท
1 Parent(s): 37f1800

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- function initRound() {
686
- enemies = [];
687
- for(let i = 0; i < 1 * currentRound; i++) {
688
- enemies.push(new Enemy());
689
- }
690
- player.health = player.maxHealth;
691
- bullets = [];
692
- items = [];
693
- supportUnits = [];
694
- lastSupportSpawn = 0;
 
 
 
 
 
695
 
696
- startCountdown();
697
 
698
- setTimeout(() => {
699
- if (hasJU87) {
700
- supportUnits.push(new JU87());
701
- lastJU87Spawn = Date.now();
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 (hasJU87 && !isCountingDown) {
740
- const now = Date.now();
741
- if (now - lastJU87Spawn > 15000) {
742
- supportUnits.push(new JU87());
743
- lastJU87Spawn = now;
 
 
 
744
  }
745
- }
746
-
747
- supportUnits = supportUnits.filter(unit => unit.update());
748
-
749
- enemies.forEach(enemy => enemy.update());
750
-
751
- if(!isCountingDown) {
752
- bullets = bullets.filter(bullet => {
753
- bullet.x += Math.cos(bullet.angle) * bullet.speed;
754
- bullet.y += Math.sin(bullet.angle) * bullet.speed;
755
- if(!bullet.isEnemy) {
756
- enemies = enemies.filter(enemy => {
757
- const dist = Math.hypot(bullet.x - enemy.x, bullet.y - enemy.y);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
758
  if(dist < 30) {
759
- let damage = currentWeapon === 'cannon' ? 250 : 50;
760
- enemy.health -= damage;
761
- if(enemy.health <= 0) {
762
- spawnHealthItem(enemy.x, enemy.y);
763
- gold += 100;
764
- effects.push(new Effect(enemy.x, enemy.y, 1000, 'death'));
765
  deathSound.cloneNode().play();
766
- return false;
767
  }
768
- return true;
769
  }
770
- return true;
771
- });
772
- } else {
773
- const dist = Math.hypot(bullet.x - player.x, bullet.y - player.y);
 
 
 
774
  if(dist < 30) {
775
- player.health -= bullet.damage || 100;
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
- return bullet.x >= 0 && bullet.x <= canvas.width &&
786
- bullet.y >= 0 && bullet.y <= canvas.height;
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});