Spaces:
Running
Running
cutechicken
commited on
Update game.js
Browse files
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() {
|