cutechicken commited on
Commit
4755951
·
verified ·
1 Parent(s): b5b0c77

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +75 -0
game.js CHANGED
@@ -1166,6 +1166,81 @@ class Game {
1166
  this.handleLoadingError();
1167
  }
1168
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1169
 
1170
  // 레이더 업데이트 메서드 추가
1171
  updateRadar() {
 
1166
  this.handleLoadingError();
1167
  }
1168
  }
1169
+ checkTargetAlignment() {
1170
+ if (!this.tank || !this.tank.isLoaded) return;
1171
+
1172
+ const crosshair = document.getElementById('crosshair');
1173
+ const tankPosition = this.tank.getPosition();
1174
+ const turretRotation = this.tank.turretRotation;
1175
+
1176
+ // 조준 방향 벡터 계산
1177
+ const aimVector = new THREE.Vector3(
1178
+ Math.sin(turretRotation),
1179
+ 0,
1180
+ Math.cos(turretRotation)
1181
+ ).normalize();
1182
+
1183
+ let targetInSight = false;
1184
+ let closestDistance = Infinity;
1185
+
1186
+ // 모든 적에 대해 검사
1187
+ this.enemies.forEach(enemy => {
1188
+ if (!enemy.mesh || !enemy.isLoaded) return;
1189
+
1190
+ // 적과의 방향 벡터 계산
1191
+ const enemyVector = new THREE.Vector3()
1192
+ .subVectors(enemy.mesh.position, tankPosition)
1193
+ .normalize();
1194
+
1195
+ // 두 벡터 사이의 각도 계산
1196
+ const angle = aimVector.angleTo(enemyVector);
1197
+
1198
+ // 거리 계산
1199
+ const distance = tankPosition.distanceTo(enemy.mesh.position);
1200
+
1201
+ // 각도가 매우 작고(거의 일직선), 적정 거리 내에 있을 때
1202
+ if (angle < 0.1 && distance < 100) {
1203
+ // 레이캐스트로 장애물 체크
1204
+ const raycaster = new THREE.Raycaster(tankPosition, enemyVector);
1205
+ const intersects = raycaster.intersectObjects(this.obstacles);
1206
+
1207
+ // 장애물이 없으면 조준 가능 상태
1208
+ if (intersects.length === 0) {
1209
+ targetInSight = true;
1210
+ closestDistance = Math.min(closestDistance, distance);
1211
+ }
1212
+ }
1213
+ });
1214
+
1215
+ // 크로스헤어 상태 업데이트
1216
+ if (targetInSight) {
1217
+ if (!crosshair.classList.contains('target-locked')) {
1218
+ // 목표물 조준 시 사운드 효과
1219
+ const targetLockSound = new Audio('sounds/targetlock.ogg');
1220
+ targetLockSound.volume = 0.3;
1221
+ targetLockSound.play();
1222
+
1223
+ // 크로스헤어 애니메이션 효과
1224
+ crosshair.style.transform = 'scale(1.2)';
1225
+ setTimeout(() => {
1226
+ crosshair.style.transform = 'scale(1)';
1227
+ }, 200);
1228
+ }
1229
+
1230
+ crosshair.classList.add('target-locked');
1231
+
1232
+ // 거리에 따른 크로스헤어 크기 조절
1233
+ const baseSize = 32; // 기본 크기
1234
+ const size = baseSize * (1 + (100 - closestDistance) / 200);
1235
+ crosshair.style.width = `${size}px`;
1236
+ crosshair.style.height = `${size}px`;
1237
+
1238
+ } else {
1239
+ crosshair.classList.remove('target-locked');
1240
+ // 기본 크기로 복귀
1241
+ crosshair.style.width = '32px';
1242
+ crosshair.style.height = '32px';
1243
+ }
1244
 
1245
  // 레이더 업데이트 메서드 추가
1246
  updateRadar() {