cutechicken commited on
Commit
0837df4
·
verified ·
1 Parent(s): f4d0847

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +74 -62
index.html CHANGED
@@ -102,8 +102,7 @@
102
  }
103
  </style>
104
  </head>
105
- <body>
106
- <div id="instructions">
107
  Controls:<br>
108
  WASD - Move tank<br>
109
  Mouse - Aim<br>
@@ -116,7 +115,11 @@
116
  <button id="nextRound" class="button">Next Round</button>
117
  <button id="restart" class="button">Restart Game</button>
118
  <canvas id="gameCanvas"></canvas>
119
-
 
 
 
 
120
  <div id="shop" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); background:rgba(0,0,0,0.9); padding:20px; border-radius:10px; color:white; z-index:1000;">
121
  <h2>Tank Shop</h2>
122
  <div style="display:flex; gap:20px;">
@@ -201,11 +204,11 @@
201
  enemyImg.src = 'enemy.png';
202
  const bulletImg = new Image(); // APCR 총알 이미지
203
  bulletImg.src = 'apcr2.png';
204
- // Audio setup
205
  const cannonSound = new Audio('firemn.ogg');
206
  const machinegunSound = new Audio('firemg.ogg');
207
  const enemyFireSound = new Audio('fireenemy.ogg');
208
- const bgm = new Audio('BGM2.ogg');
209
  const countSound = new Audio('count.ogg');
210
  const deathSound = new Audio('death.ogg');
211
  bgm.loop = true;
@@ -847,81 +850,90 @@ function buyTank(tankImg, cost, tankId) {
847
 
848
  // UI 그리기
849
  ctx.fillStyle = 'white';
850
- ctx.font = '24px Arial';
851
- ctx.fillText(`Round ${currentRound}/10`, 10, 30);
852
- ctx.fillText(`Gold: ${gold}`, 10, 60);
853
-
854
- // 이펙트 그리기
855
  effects = effects.filter(effect => !effect.isExpired());
856
  effects.forEach(effect => {
857
  effect.update(); // 이펙트 위치 업데이트
858
  ctx.save();
859
  ctx.translate(effect.x, effect.y);
860
- if(effect.type === 'fire') ctx.rotate(effect.angle);
861
  // bang.png는 1.5배 크게
862
  const size = effect.type === 'death' ? 75 : 42; // death는 75px (1.5배), fire는 42px
863
- ctx.drawImage(effect.img, -size/2, -size/2, size, size);
864
  ctx.restore();
865
  });
866
 
867
- if(isCountingDown) {
868
- ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
869
- ctx.fillRect(0, 0, canvas.width, canvas.height);
870
- }
871
  }
872
 
873
- // drawGame 함수 밖으로 이동
874
  function gameLoop() {
875
- updateGame();
876
- drawGame();
877
- requestAnimationFrame(gameLoop);
 
 
878
  }
879
 
880
- nextRoundBtn.addEventListener('click', () => {
881
- currentRound++;
882
- nextRoundBtn.style.display = 'none';
883
- document.getElementById('shop').style.display = 'none';
884
- initRound();
885
- });
886
-
887
- bossButton.addEventListener('click', startBossStage);
888
-
889
- restartBtn.addEventListener('click', () => {
890
- currentRound = 1;
891
- gameOver = false;
892
- isBossStage = false;
893
- gold = 0;
894
- hasAPCR = false; // APCR 초기화
895
- hasBF109 = false; // BF109 초기화
896
- hasJU87 = false;
897
- supportUnits = []; // 지원 유닛 배열 초기화
898
-
899
- restartBtn.style.display = 'none';
900
- document.getElementById('winMessage').style.display = 'none';
901
- document.getElementById('tank1').style.display = 'block';
902
- document.getElementById('tank2').style.display = 'block';
903
- document.getElementById('apcr').style.display = 'block';
904
- document.getElementById('bf109').style.display = 'block'; // BF109 상점 아이템 다시 표시
905
 
906
- playerImg.src = 'player.png';
907
- bgm.src = 'BGM2.ogg';
908
- bgm.play();
909
- initRound();
910
- });
 
 
 
 
 
911
 
912
- Promise.all([
913
- new Promise(resolve => backgroundImg.onload = resolve),
914
- new Promise(resolve => playerImg.onload = resolve),
915
- new Promise(resolve => enemyImg.onload = resolve)
916
- ]).then(() => {
917
- initRound();
918
- gameLoop();
919
- bgm.play();
920
- });
921
 
922
- window.addEventListener('resize', () => {
923
- canvas.width = window.innerWidth;
924
- canvas.height = window.innerHeight;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
925
  });
926
  </script>
927
  </body>
 
102
  }
103
  </style>
104
  </head>
105
+ <div id="instructions">
 
106
  Controls:<br>
107
  WASD - Move tank<br>
108
  Mouse - Aim<br>
 
115
  <button id="nextRound" class="button">Next Round</button>
116
  <button id="restart" class="button">Restart Game</button>
117
  <canvas id="gameCanvas"></canvas>
118
+ <div id="titleScreen">
119
+ <h1>TANK WAR</h1>
120
+ <button id="startButton">START GAME</button>
121
+ </div>
122
+
123
  <div id="shop" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); background:rgba(0,0,0,0.9); padding:20px; border-radius:10px; color:white; z-index:1000;">
124
  <h2>Tank Shop</h2>
125
  <div style="display:flex; gap:20px;">
 
204
  enemyImg.src = 'enemy.png';
205
  const bulletImg = new Image(); // APCR 총알 이미지
206
  bulletImg.src = 'apcr2.png';
207
+ // Audio setup
208
  const cannonSound = new Audio('firemn.ogg');
209
  const machinegunSound = new Audio('firemg.ogg');
210
  const enemyFireSound = new Audio('fireenemy.ogg');
211
+ let bgm = new Audio('title.ogg'); // 'title.ogg'로 초기화하고 let으로 선언
212
  const countSound = new Audio('count.ogg');
213
  const deathSound = new Audio('death.ogg');
214
  bgm.loop = true;
 
850
 
851
  // UI 그리기
852
  ctx.fillStyle = 'white';
853
+ ctx.font = '24px Arial';
854
+ ctx.fillText(`Round ${currentRound}/10`, 10, 30);
855
+ ctx.fillText(`Gold: ${gold}`, 10, 60);
856
+ // 이펙트 그리기
 
857
  effects = effects.filter(effect => !effect.isExpired());
858
  effects.forEach(effect => {
859
  effect.update(); // 이펙트 위치 업데이트
860
  ctx.save();
861
  ctx.translate(effect.x, effect.y);
862
+ if (effect.type === 'fire') ctx.rotate(effect.angle);
863
  // bang.png는 1.5배 크게
864
  const size = effect.type === 'death' ? 75 : 42; // death는 75px (1.5배), fire는 42px
865
+ ctx.drawImage(effect.img, -size / 2, -size / 2, size, size);
866
  ctx.restore();
867
  });
868
 
869
+ if (isCountingDown) {
870
+ ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
871
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
872
+ }
873
  }
874
 
 
875
  function gameLoop() {
876
+ if (!gameOver) {
877
+ updateGame();
878
+ drawGame();
879
+ requestAnimationFrame(gameLoop);
880
+ }
881
  }
882
 
883
+ document.addEventListener('DOMContentLoaded', () => {
884
+ // DOM 요소 참조
885
+ const titleScreen = document.getElementById('titleScreen');
886
+ const startButton = document.getElementById('startButton');
887
+ const instructions = document.getElementById('instructions');
888
+ const weaponInfo = document.getElementById('weaponInfo');
889
+ const gameCanvas = document.getElementById('gameCanvas');
890
+
891
+ // 초기 상태
892
+ instructions.style.display = 'none';
893
+ weaponInfo.style.display = 'none';
894
+ gameCanvas.style.display = 'none';
895
+
896
+ // 디버깅용 확인 로그
897
+ console.log("DOM Loaded");
 
 
 
 
 
 
 
 
 
 
898
 
899
+ // 타이틀 음악 재생
900
+ bgm.play().catch(err => console.error("Error playing title music:", err));
901
+
902
+ // Start Button 클릭 이벤트
903
+ startButton.addEventListener('click', () => {
904
+ console.log("Start Button Clicked");
905
+ if (!titleScreen || !instructions || !weaponInfo || !gameCanvas) {
906
+ console.error("DOM elements not found");
907
+ return;
908
+ }
909
 
910
+ titleScreen.style.display = 'none';
911
+ instructions.style.display = 'block';
912
+ weaponInfo.style.display = 'block';
913
+ gameCanvas.style.display = 'block';
 
 
 
 
 
914
 
915
+ bgm.pause();
916
+ bgm.src = 'BGM2.ogg';
917
+ bgm.play().catch(err => console.error("Error playing game music:", err));
918
+
919
+ initRound();
920
+ gameLoop();
921
+ });
922
+
923
+ // 이미지 로드 확인
924
+ Promise.all([
925
+ new Promise(resolve => backgroundImg.onload = resolve),
926
+ new Promise(resolve => playerImg.onload = resolve),
927
+ new Promise(resolve => enemyImg.onload = resolve)
928
+ ]).then(() => {
929
+ console.log("Assets loaded successfully");
930
+ }).catch(err => console.error("Error loading assets:", err));
931
+
932
+ // 창 크기 변경 시 캔버스 크기 업데이트
933
+ window.addEventListener('resize', () => {
934
+ canvas.width = window.innerWidth;
935
+ canvas.height = window.innerHeight;
936
+ });
937
  });
938
  </script>
939
  </body>