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() {