cutechicken commited on
Commit
450973d
ยท
verified ยท
1 Parent(s): aba7aeb

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +86 -47
game.js CHANGED
@@ -1097,78 +1097,117 @@ class Game {
1097
  const rollDegrees = this.fighter.rotation.z * (180 / Math.PI);
1098
  hudElement.style.transform = `translate(-50%, -50%) rotate(${-rollDegrees}deg)`;
1099
 
1100
- // ํ”ผ์น˜ ํ‘œ์‹œ๊ธฐ ์—…๋ฐ์ดํŠธ
1101
- const pitchIndicator = document.getElementById('pitchIndicator');
1102
- if (pitchIndicator) {
1103
  const pitchDegrees = this.fighter.rotation.x * (180 / Math.PI);
1104
- const pitchOffset = pitchDegrees * 2; // ํ”ผ์น˜์— ๋”ฐ๋ฅธ ์ˆ˜์ง ์˜คํ”„์…‹
1105
- pitchIndicator.style.transform = `translateY(${pitchOffset}px)`;
1106
  }
1107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1108
  // ์  ํƒ€๊ฒŸ ๋งˆ์ปค ์—…๋ฐ์ดํŠธ
1109
  const targetMarkers = document.getElementById('targetMarkers');
1110
  if (targetMarkers) {
1111
- // ๊ธฐ์กด ๋งˆ์ปค ์ œ๊ฑฐ
1112
  targetMarkers.innerHTML = '';
1113
 
1114
- // ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์  ์ฐพ๊ธฐ
1115
- let closestEnemy = null;
1116
- let closestDistance = Infinity;
1117
-
1118
  this.enemies.forEach(enemy => {
1119
  if (!enemy.mesh || !enemy.isLoaded) return;
1120
 
1121
  const distance = this.fighter.position.distanceTo(enemy.position);
1122
- if (distance < closestDistance) {
1123
- closestDistance = distance;
1124
- closestEnemy = enemy;
1125
- }
1126
- });
1127
-
1128
- // ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์ ์— ๋Œ€ํ•œ ํƒ€๊ฒŸ ๋งˆ์ปค ํ‘œ์‹œ
1129
- if (closestEnemy && closestDistance < 5000) {
1130
- // ์ ์˜ ์ƒ๋Œ€ ์œ„์น˜ ๊ณ„์‚ฐ
1131
- const relativePos = closestEnemy.position.clone().sub(this.fighter.position);
1132
 
1133
- // ์ „ํˆฌ๊ธฐ์˜ ํšŒ์ „์„ ๊ณ ๋ คํ•œ ์ƒ๋Œ€ ์œ„์น˜
1134
- const inverseRotation = new THREE.Euler(
1135
- -this.fighter.rotation.x,
1136
- -this.fighter.rotation.y,
1137
- -this.fighter.rotation.z
 
 
 
 
 
1138
  );
1139
- relativePos.applyEuler(inverseRotation);
1140
 
1141
- // ํ™”๋ฉด ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
1142
- const screenX = (relativePos.x / closestDistance) * 200;
1143
- const screenY = -(relativePos.y / closestDistance) * 200;
1144
 
1145
  // ํƒ€๊ฒŸ ๋งˆ์ปค ์ƒ์„ฑ
1146
  const marker = document.createElement('div');
1147
  marker.className = 'target-marker';
1148
- marker.style.left = `${50 + screenX}%`;
1149
- marker.style.top = `${50 + screenY}%`;
1150
-
1151
- // ๊ฑฐ๋ฆฌ๊ฐ€ ๊ฐ€๊นŒ์šธ์ˆ˜๋ก ๋นจ๊ฐ„์ƒ‰
1152
- const colorIntensity = Math.max(0, 1 - closestDistance / 5000);
1153
- marker.style.borderColor = `rgba(255, ${255 * (1 - colorIntensity)}, 0, ${0.5 + colorIntensity * 0.5})`;
1154
 
1155
- // ๋ฝ์˜จ ์ƒํƒœ
1156
- if (closestDistance < 2000) {
1157
- marker.classList.add('locked');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1158
  }
1159
 
1160
- targetMarkers.appendChild(marker);
 
1161
 
1162
- // ๊ฑฐ๋ฆฌ ํ‘œ์‹œ
1163
- const distanceLabel = document.createElement('div');
1164
- distanceLabel.className = 'target-distance';
1165
- distanceLabel.textContent = `${Math.round(closestDistance)}m`;
1166
- distanceLabel.style.left = `${50 + screenX}%`;
1167
- distanceLabel.style.top = `${50 + screenY + 5}%`;
1168
- targetMarkers.appendChild(distanceLabel);
1169
- }
1170
  }
1171
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1172
 
1173
  updateWarnings() {
1174
  // ๊ธฐ์กด ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€ ์ œ๊ฑฐ
 
1097
  const rollDegrees = this.fighter.rotation.z * (180 / Math.PI);
1098
  hudElement.style.transform = `translate(-50%, -50%) rotate(${-rollDegrees}deg)`;
1099
 
1100
+ // ํ”ผ์น˜ ๋ž˜๋” ์—…๋ฐ์ดํŠธ
1101
+ const pitchLadder = document.getElementById('pitchLadder');
1102
+ if (pitchLadder) {
1103
  const pitchDegrees = this.fighter.rotation.x * (180 / Math.PI);
1104
+ const pitchOffset = pitchDegrees * 3; // ํ”ผ์น˜์— ๋”ฐ๋ฅธ ์ˆ˜์ง ์˜คํ”„์…‹
1105
+ pitchLadder.style.transform = `translateY(${pitchOffset}px)`;
1106
  }
1107
 
1108
+ // ๋น„ํ–‰ ์ •๋ณด ์—…๋ฐ์ดํŠธ
1109
+ const speedKnots = Math.round(this.fighter.speed * 1.94384);
1110
+ const altitudeMeters = Math.round(this.fighter.altitude);
1111
+ const pitchDegrees = Math.round(this.fighter.rotation.x * (180 / Math.PI));
1112
+ const rollDegreesRounded = Math.round(rollDegrees);
1113
+ const headingDegrees = Math.round(((this.fighter.rotation.y * (180 / Math.PI)) + 360) % 360);
1114
+
1115
+ // ์„ ํšŒ์œจ ๊ณ„์‚ฐ (๋„/์ดˆ)
1116
+ if (!this.lastHeading) this.lastHeading = headingDegrees;
1117
+ let turnRate = (headingDegrees - this.lastHeading);
1118
+ if (turnRate > 180) turnRate -= 360;
1119
+ if (turnRate < -180) turnRate += 360;
1120
+ this.lastHeading = headingDegrees;
1121
+ const turnRateDegPerSec = Math.round(turnRate / (1/60)); // 60 FPS ๊ธฐ์ค€
1122
+
1123
+ // HUD ์ •๋ณด ์—…๋ฐ์ดํŠธ
1124
+ const hudSpeed = document.getElementById('hudSpeed');
1125
+ const hudAltitude = document.getElementById('hudAltitude');
1126
+ const hudHeading = document.getElementById('hudHeading');
1127
+ const hudPitch = document.getElementById('hudPitch');
1128
+ const hudRoll = document.getElementById('hudRoll');
1129
+ const hudTurnRate = document.getElementById('hudTurnRate');
1130
+
1131
+ if (hudSpeed) hudSpeed.textContent = `SPD: ${speedKnots} KT`;
1132
+ if (hudAltitude) hudAltitude.textContent = `ALT: ${altitudeMeters} M`;
1133
+ if (hudHeading) hudHeading.textContent = `HDG: ${String(headingDegrees).padStart(3, '0')}ยฐ`;
1134
+ if (hudPitch) hudPitch.textContent = `PITCH: ${pitchDegrees}ยฐ`;
1135
+ if (hudRoll) hudRoll.textContent = `ROLL: ${rollDegreesRounded}ยฐ`;
1136
+ if (hudTurnRate) hudTurnRate.textContent = `TURN: ${Math.abs(turnRateDegPerSec) > 1 ? turnRateDegPerSec : 0}ยฐ/s`;
1137
+
1138
  // ์  ํƒ€๊ฒŸ ๋งˆ์ปค ์—…๋ฐ์ดํŠธ
1139
  const targetMarkers = document.getElementById('targetMarkers');
1140
  if (targetMarkers) {
 
1141
  targetMarkers.innerHTML = '';
1142
 
1143
+ // ๋ชจ๋“  ์ ์— ๋Œ€ํ•ด ์ฒ˜๋ฆฌ
 
 
 
1144
  this.enemies.forEach(enemy => {
1145
  if (!enemy.mesh || !enemy.isLoaded) return;
1146
 
1147
  const distance = this.fighter.position.distanceTo(enemy.position);
1148
+ if (distance > 10000) return; // 10km ์ด์ƒ์€ ํ‘œ์‹œํ•˜์ง€ ์•Š์Œ
 
 
 
 
 
 
 
 
 
1149
 
1150
+ // ์ ์˜ ํ™”๋ฉด ์ขŒํ‘œ ๊ณ„์‚ฐ
1151
+ const enemyScreenPos = this.getScreenPosition(enemy.position);
1152
+ if (!enemyScreenPos) return;
1153
+
1154
+ // ํ™”๋ฉด ์ค‘์•™์œผ๋กœ๋ถ€ํ„ฐ์˜ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
1155
+ const centerX = window.innerWidth / 2;
1156
+ const centerY = window.innerHeight / 2;
1157
+ const distFromCenter = Math.sqrt(
1158
+ Math.pow(enemyScreenPos.x - centerX, 2) +
1159
+ Math.pow(enemyScreenPos.y - centerY, 2)
1160
  );
 
1161
 
1162
+ // ํฌ๋กœ์Šคํ—ค์–ด ๋ฐ˜๊ฒฝ (75px)
1163
+ const crosshairRadius = 75;
1164
+ const isInCrosshair = distFromCenter < crosshairRadius;
1165
 
1166
  // ํƒ€๊ฒŸ ๋งˆ์ปค ์ƒ์„ฑ
1167
  const marker = document.createElement('div');
1168
  marker.className = 'target-marker';
 
 
 
 
 
 
1169
 
1170
+ if (isInCrosshair) {
1171
+ marker.classList.add('in-crosshair');
1172
+
1173
+ // 2000m ์ด๋‚ด๋ฉด ๋ฝ์˜จ
1174
+ if (distance < 2000) {
1175
+ marker.classList.add('locked');
1176
+ }
1177
+
1178
+ // ํƒ€๊ฒŸ ๋ฐ•์Šค ์ถ”๊ฐ€
1179
+ const targetBox = document.createElement('div');
1180
+ targetBox.className = 'target-box';
1181
+ marker.appendChild(targetBox);
1182
+
1183
+ // ๊ฑฐ๋ฆฌ ์ •๋ณด ์ถ”๊ฐ€
1184
+ const targetInfo = document.createElement('div');
1185
+ targetInfo.className = 'target-info';
1186
+ targetInfo.textContent = `${Math.round(distance)}m`;
1187
+ marker.appendChild(targetInfo);
1188
  }
1189
 
1190
+ marker.style.left = `${enemyScreenPos.x}px`;
1191
+ marker.style.top = `${enemyScreenPos.y}px`;
1192
 
1193
+ targetMarkers.appendChild(marker);
1194
+ });
 
 
 
 
 
 
1195
  }
1196
  }
1197
+
1198
+ getScreenPosition(worldPosition) {
1199
+ // 3D ์ขŒํ‘œ๋ฅผ ํ™”๋ฉด ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
1200
+ const vector = worldPosition.clone();
1201
+ vector.project(this.camera);
1202
+
1203
+ // ์นด๋ฉ”๋ผ ๋’ค์— ์žˆ๋Š” ๊ฐ์ฒด๋Š” ํ‘œ์‹œํ•˜์ง€ ์•Š์Œ
1204
+ if (vector.z > 1) return null;
1205
+
1206
+ const x = (vector.x * 0.5 + 0.5) * window.innerWidth;
1207
+ const y = (-vector.y * 0.5 + 0.5) * window.innerHeight;
1208
+
1209
+ return { x, y };
1210
+ }
1211
 
1212
  updateWarnings() {
1213
  // ๊ธฐ์กด ๊ฒฝ๊ณ  ๋ฉ”์‹œ์ง€ ์ œ๊ฑฐ