cutechicken commited on
Commit
70004e8
β€’
1 Parent(s): 1413f15

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +80 -78
game.js CHANGED
@@ -1120,56 +1120,56 @@ class Game {
1120
 
1121
  // λ ˆμ΄λ” μ—…λ°μ΄νŠΈ λ©”μ„œλ“œ μΆ”κ°€
1122
  updateRadar() {
1123
- const currentTime = Date.now();
1124
- if (currentTime - this.lastRadarUpdate < this.radarUpdateInterval) return;
1125
-
1126
- const radar = document.getElementById('radar');
1127
- const radarRect = radar.getBoundingClientRect();
1128
- const radarCenter = {
1129
- x: radarRect.width / 2,
1130
- y: radarRect.height / 2
1131
- };
1132
 
1133
- // κΈ°μ‘΄ 적 λ„νŠΈ 제거
1134
- const oldDots = radar.getElementsByClassName('enemy-dot');
1135
- while (oldDots[0]) {
1136
- oldDots[0].remove();
1137
- }
1138
 
1139
- // 탱크 μœ„μΉ˜ κ°€μ Έμ˜€κΈ°
1140
- const tankPos = this.tank.getPosition();
1141
 
1142
- // λͺ¨λ“  적에 λŒ€ν•΄ λ ˆμ΄λ”μ— ν‘œμ‹œ
1143
- this.enemies.forEach(enemy => {
1144
- if (!enemy.mesh || !enemy.isLoaded) return;
1145
 
1146
- const enemyPos = enemy.mesh.position;
1147
- const distance = tankPos.distanceTo(enemyPos);
1148
 
1149
- // λ ˆμ΄λ” λ²”μœ„ 내에 μžˆλŠ” 경우만 ν‘œμ‹œ
1150
- if (distance <= this.radarRange) {
1151
- // 탱크 κΈ°μ€€ μƒλŒ€ 각도 계산
1152
- const angle = Math.atan2(
1153
- enemyPos.x - tankPos.x,
1154
- enemyPos.z - tankPos.z
1155
- );
1156
 
1157
- // μƒλŒ€ 거리λ₯Ό λ ˆμ΄λ” 크기에 맞게 μŠ€μΌ€μΌλ§
1158
- const relativeDistance = distance / this.radarRange;
1159
- const dotX = radarCenter.x + Math.sin(angle) * (radarCenter.x * relativeDistance);
1160
- const dotY = radarCenter.y + Math.cos(angle) * (radarCenter.y * relativeDistance);
1161
-
1162
- // 적 λ„νŠΈ 생성 및 μΆ”κ°€
1163
- const dot = document.createElement('div');
1164
- dot.className = 'enemy-dot';
1165
- dot.style.left = `${dotX}px`;
1166
- dot.style.top = `${dotY}px`;
1167
- radar.appendChild(dot);
1168
- }
1169
- });
1170
 
1171
- this.lastRadarUpdate = currentTime;
1172
- }
1173
 
1174
  async addDesertDecorations() {
1175
  if (!this.obstacles) {
@@ -1881,45 +1881,47 @@ this.enemies.forEach(enemy => {
1881
  }
1882
 
1883
  animate() {
1884
- if (this.isGameOver) {
1885
- if (this.animationFrameId) {
1886
- cancelAnimationFrame(this.animationFrameId);
1887
- }
1888
- return;
1889
- }
1890
-
1891
- this.animationFrameId = requestAnimationFrame(() => this.animate());
1892
- // κ²Œμž„μ΄ μ‹œμž‘λ˜μ§€ μ•Šμ•˜μœΌλ©΄ λ Œλ”λ§λ§Œ μˆ˜ν–‰
1893
- if (!this.isStarted) {
1894
- this.renderer.render(this.scene, this.camera);
1895
- return;
1896
  }
 
 
1897
 
1898
- const currentTime = performance.now();
1899
- const deltaTime = (currentTime - this.lastTime) / 1000;
1900
- this.lastTime = currentTime;
 
 
 
1901
 
1902
- if (!this.isLoading) {
1903
- this.handleMovement();
1904
- this.tank.update(this.mouse.x, this.mouse.y, this.scene);
1905
-
1906
- const tankPosition = this.tank.getPosition();
1907
- this.enemies.forEach(enemy => {
1908
- enemy.update(tankPosition);
1909
-
1910
- if (enemy.isLoaded && enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
1911
- enemy.shoot(tankPosition);
1912
- }
1913
- });
1914
 
1915
- this.updateParticles();
1916
- this.checkCollisions();
1917
- this.updateUI();
1918
- this.updateRadar(); // λ ˆμ΄λ” μ—…λ°μ΄νŠΈ μΆ”κ°€
1919
- }
1920
-
1921
- this.renderer.render(this.scene, this.camera);
1922
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1923
  }
1924
 
1925
  // Start game
 
1120
 
1121
  // λ ˆμ΄λ” μ—…λ°μ΄νŠΈ λ©”μ„œλ“œ μΆ”κ°€
1122
  updateRadar() {
1123
+ const currentTime = Date.now();
1124
+ if (currentTime - this.lastRadarUpdate < this.radarUpdateInterval) return;
1125
+
1126
+ const radar = document.getElementById('radar');
1127
+ const radarRect = radar.getBoundingClientRect();
1128
+ const radarCenter = {
1129
+ x: radarRect.width / 2,
1130
+ y: radarRect.height / 2
1131
+ };
1132
 
1133
+ // κΈ°μ‘΄ 적 λ„νŠΈ 제거
1134
+ const oldDots = radar.getElementsByClassName('enemy-dot');
1135
+ while (oldDots[0]) {
1136
+ oldDots[0].remove();
1137
+ }
1138
 
1139
+ // 탱크 μœ„μΉ˜ κ°€μ Έμ˜€κΈ°
1140
+ const tankPos = this.tank.getPosition();
1141
 
1142
+ // λͺ¨λ“  적에 λŒ€ν•΄ λ ˆμ΄λ”μ— ν‘œμ‹œ
1143
+ this.enemies.forEach(enemy => {
1144
+ if (!enemy.isLoaded || !enemy.body) return;
1145
 
1146
+ const enemyPos = enemy.body.position;
1147
+ const distance = tankPos.distanceTo(enemyPos);
1148
 
1149
+ // λ ˆμ΄λ” λ²”μœ„ 내에 μžˆλŠ” 경우만 ν‘œμ‹œ
1150
+ if (distance <= this.radarRange) {
1151
+ // 탱크 κΈ°μ€€ μƒλŒ€ 각도 계산
1152
+ const angle = Math.atan2(
1153
+ enemyPos.x - tankPos.x,
1154
+ enemyPos.z - tankPos.z
1155
+ );
1156
 
1157
+ // μƒλŒ€ 거리λ₯Ό λ ˆμ΄λ” 크기에 맞게 μŠ€μΌ€μΌλ§
1158
+ const relativeDistance = distance / this.radarRange;
1159
+ const dotX = radarCenter.x + Math.sin(angle) * (radarCenter.x * relativeDistance);
1160
+ const dotY = radarCenter.y + Math.cos(angle) * (radarCenter.y * relativeDistance);
1161
+
1162
+ // 적 λ„νŠΈ 생성 및 μΆ”κ°€
1163
+ const dot = document.createElement('div');
1164
+ dot.className = 'enemy-dot';
1165
+ dot.style.left = `${dotX}px`;
1166
+ dot.style.top = `${dotY}px`;
1167
+ radar.appendChild(dot);
1168
+ }
1169
+ });
1170
 
1171
+ this.lastRadarUpdate = currentTime;
1172
+ }
1173
 
1174
  async addDesertDecorations() {
1175
  if (!this.obstacles) {
 
1881
  }
1882
 
1883
  animate() {
1884
+ if (this.isGameOver) {
1885
+ if (this.animationFrameId) {
1886
+ cancelAnimationFrame(this.animationFrameId);
 
 
 
 
 
 
 
 
 
1887
  }
1888
+ return;
1889
+ }
1890
 
1891
+ this.animationFrameId = requestAnimationFrame(() => this.animate());
1892
+ // κ²Œμž„μ΄ μ‹œμž‘λ˜μ§€ μ•Šμ•˜μœΌλ©΄ λ Œλ”λ§λ§Œ μˆ˜ν–‰
1893
+ if (!this.isStarted) {
1894
+ this.renderer.render(this.scene, this.camera);
1895
+ return;
1896
+ }
1897
 
1898
+ const currentTime = performance.now();
1899
+ const deltaTime = (currentTime - this.lastTime) / 1000;
1900
+ this.lastTime = currentTime;
 
 
 
 
 
 
 
 
 
1901
 
1902
+ if (!this.isLoading) {
1903
+ this.handleMovement();
1904
+ this.tank.update(this.mouse.x, this.mouse.y, this.scene);
1905
+
1906
+ const tankPosition = this.tank.getPosition();
1907
+ this.enemies.forEach(enemy => {
1908
+ if (enemy && enemy.isLoaded && enemy.body) { // body 쑴재 μ—¬λΆ€ 확인
1909
+ enemy.update(tankPosition);
1910
+
1911
+ const distanceToPlayer = enemy.body.position.distanceTo(tankPosition);
1912
+ if (distanceToPlayer < ENEMY_CONFIG.ATTACK_RANGE) {
1913
+ enemy.shoot(tankPosition);
1914
+ }
1915
+ }
1916
+ });
1917
+
1918
+ this.updateParticles();
1919
+ this.checkCollisions();
1920
+ this.updateUI();
1921
+ this.updateRadar();
1922
+ }
1923
+
1924
+ this.renderer.render(this.scene, this.camera);
1925
  }
1926
 
1927
  // Start game