cutechicken commited on
Commit
ba01407
ยท
verified ยท
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) {