cutechicken commited on
Commit
ba01407
β€’
1 Parent(s): 8cc3811

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +43 -43
game.js CHANGED
@@ -1097,56 +1097,56 @@ class Game {
1097
 
1098
  // λ ˆμ΄λ” μ—…λ°μ΄νŠΈ λ©”μ„œλ“œ μΆ”κ°€
1099
  updateRadar() {
1100
- const currentTime = Date.now();
1101
- if (currentTime - this.lastRadarUpdate < this.radarUpdateInterval) return;
1102
-
1103
- const radar = document.getElementById('radar');
1104
- const radarRect = radar.getBoundingClientRect();
1105
- const radarCenter = {
1106
- x: radarRect.width / 2,
1107
- y: radarRect.height / 2
1108
- };
1109
 
1110
- // κΈ°μ‘΄ 적 λ„νŠΈ 제거
1111
- const oldDots = radar.getElementsByClassName('enemy-dot');
1112
- while (oldDots[0]) {
1113
- oldDots[0].remove();
1114
- }
1115
 
1116
- // 탱크 μœ„μΉ˜ κ°€μ Έμ˜€κΈ°
1117
- const tankPos = this.tank.getPosition();
1118
 
1119
- // λͺ¨λ“  적에 λŒ€ν•΄ λ ˆμ΄λ”μ— ν‘œμ‹œ
1120
- this.enemies.forEach(enemy => {
1121
- if (!enemy.mesh || !enemy.isLoaded) return;
1122
 
1123
- const enemyPos = enemy.mesh.position;
1124
- const distance = tankPos.distanceTo(enemyPos);
1125
 
1126
- // λ ˆμ΄λ” λ²”μœ„ 내에 μžˆλŠ” 경우만 ν‘œμ‹œ
1127
- if (distance <= this.radarRange) {
1128
- // 탱크 κΈ°μ€€ μƒλŒ€ 각도 계산
1129
- const angle = Math.atan2(
1130
- enemyPos.x - tankPos.x,
1131
- enemyPos.z - tankPos.z
1132
- );
1133
 
1134
- // μƒλŒ€ 거리λ₯Ό λ ˆμ΄λ” 크기에 맞게 μŠ€μΌ€μΌλ§
1135
- const relativeDistance = distance / this.radarRange;
1136
- const dotX = radarCenter.x + Math.sin(angle) * (radarCenter.x * relativeDistance);
1137
- const dotY = radarCenter.y + Math.cos(angle) * (radarCenter.y * relativeDistance);
1138
-
1139
- // 적 λ„νŠΈ 생성 및 μΆ”κ°€
1140
- const dot = document.createElement('div');
1141
- dot.className = 'enemy-dot';
1142
- dot.style.left = `${dotX}px`;
1143
- dot.style.top = `${dotY}px`;
1144
- radar.appendChild(dot);
1145
- }
1146
- });
1147
 
1148
- this.lastRadarUpdate = currentTime;
1149
- }
1150
 
1151
  async addDesertDecorations() {
1152
  if (!this.obstacles) {
 
1097
 
1098
  // λ ˆμ΄λ” μ—…λ°μ΄νŠΈ λ©”μ„œλ“œ μΆ”κ°€
1099
  updateRadar() {
1100
+ const currentTime = Date.now();
1101
+ if (currentTime - this.lastRadarUpdate < this.radarUpdateInterval) return;
1102
+
1103
+ const radar = document.getElementById('radar');
1104
+ const radarRect = radar.getBoundingClientRect();
1105
+ const radarCenter = {
1106
+ x: radarRect.width / 2,
1107
+ y: radarRect.height / 2
1108
+ };
1109
 
1110
+ // κΈ°μ‘΄ 적 λ„νŠΈ 제거
1111
+ const oldDots = radar.getElementsByClassName('enemy-dot');
1112
+ while (oldDots[0]) {
1113
+ oldDots[0].remove();
1114
+ }
1115
 
1116
+ // 탱크 μœ„μΉ˜ κ°€μ Έμ˜€κΈ°
1117
+ const tankPos = this.tank.getPosition();
1118
 
1119
+ // λͺ¨λ“  적에 λŒ€ν•΄ λ ˆμ΄λ”μ— ν‘œμ‹œ
1120
+ this.enemies.forEach(enemy => {
1121
+ if (!enemy.isLoaded || !enemy.body) return; // body 체크둜 λ³€κ²½
1122
 
1123
+ const enemyPos = enemy.body.position; // mesh λŒ€μ‹  body μ‚¬μš©
1124
+ const distance = tankPos.distanceTo(enemyPos);
1125
 
1126
+ // λ ˆμ΄λ” λ²”μœ„ 내에 μžˆλŠ” 경우만 ν‘œμ‹œ
1127
+ if (distance <= this.radarRange) {
1128
+ // 탱크 κΈ°μ€€ μƒλŒ€ 각도 계산
1129
+ const angle = Math.atan2(
1130
+ enemyPos.x - tankPos.x,
1131
+ enemyPos.z - tankPos.z
1132
+ );
1133
 
1134
+ // μƒλŒ€ 거리λ₯Ό λ ˆμ΄λ” 크기에 맞게 μŠ€μΌ€μΌλ§
1135
+ const relativeDistance = distance / this.radarRange;
1136
+ const dotX = radarCenter.x + Math.sin(angle) * (radarCenter.x * relativeDistance);
1137
+ const dotY = radarCenter.y + Math.cos(angle) * (radarCenter.y * relativeDistance);
1138
+
1139
+ // 적 λ„νŠΈ 생성 및 μΆ”κ°€
1140
+ const dot = document.createElement('div');
1141
+ dot.className = 'enemy-dot';
1142
+ dot.style.left = `${dotX}px`;
1143
+ dot.style.top = `${dotY}px`;
1144
+ radar.appendChild(dot);
1145
+ }
1146
+ });
1147
 
1148
+ this.lastRadarUpdate = currentTime;
1149
+ }
1150
 
1151
  async addDesertDecorations() {
1152
  if (!this.obstacles) {