Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -1179,62 +1179,77 @@ checkPathClear(start, end) {
|
|
| 1179 |
}, 500);
|
| 1180 |
}
|
| 1181 |
|
| 1182 |
-
|
| 1183 |
-
|
| 1184 |
-
|
| 1185 |
-
|
| 1186 |
-
|
| 1187 |
|
| 1188 |
-
|
| 1189 |
|
| 1190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1191 |
|
| 1192 |
-
|
| 1193 |
-
|
| 1194 |
-
enemyFireSound.play();
|
| 1195 |
|
| 1196 |
-
|
| 1197 |
-
|
| 1198 |
-
|
| 1199 |
-
emissive: 0xff0000,
|
| 1200 |
-
emissiveIntensity: 0.5
|
| 1201 |
-
});
|
| 1202 |
-
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 1203 |
|
| 1204 |
-
|
| 1205 |
-
|
| 1206 |
-
|
| 1207 |
-
|
| 1208 |
-
|
| 1209 |
-
|
| 1210 |
-
|
| 1211 |
-
|
| 1212 |
-
|
| 1213 |
-
|
| 1214 |
-
|
| 1215 |
-
|
| 1216 |
-
|
| 1217 |
-
|
| 1218 |
-
|
| 1219 |
-
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
|
| 1223 |
-
|
| 1224 |
-
|
| 1225 |
-
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
-
|
| 1229 |
-
|
| 1230 |
-
|
| 1231 |
-
|
| 1232 |
-
|
| 1233 |
-
|
| 1234 |
-
|
| 1235 |
-
|
| 1236 |
-
|
| 1237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1238 |
|
| 1239 |
takeDamage(damage) {
|
| 1240 |
this.health -= damage;
|
|
|
|
| 1179 |
}, 500);
|
| 1180 |
}
|
| 1181 |
|
| 1182 |
+
shoot(playerPosition) {
|
| 1183 |
+
const currentTime = Date.now();
|
| 1184 |
+
const attackInterval = this.type === 'tank' ?
|
| 1185 |
+
ENEMY_CONFIG.ATTACK_INTERVAL :
|
| 1186 |
+
ENEMY_CONFIG.ATTACK_INTERVAL * 1.5;
|
| 1187 |
|
| 1188 |
+
if (currentTime - this.lastAttackTime < attackInterval) return;
|
| 1189 |
|
| 1190 |
+
// 플레이어와의 방향 차이 계산
|
| 1191 |
+
const directionToPlayer = new THREE.Vector3()
|
| 1192 |
+
.subVectors(playerPosition, this.mesh.position)
|
| 1193 |
+
.normalize();
|
| 1194 |
+
const forwardDirection = new THREE.Vector3(0, 0, 1)
|
| 1195 |
+
.applyQuaternion(this.mesh.quaternion)
|
| 1196 |
+
.normalize();
|
| 1197 |
|
| 1198 |
+
const dotProduct = forwardDirection.dot(directionToPlayer);
|
| 1199 |
+
const angleToPlayer = Math.acos(dotProduct);
|
|
|
|
| 1200 |
|
| 1201 |
+
// 일정 각도 이하일 경우에만 공격
|
| 1202 |
+
const attackAngleThreshold = Math.PI / 8; // 약 22.5도
|
| 1203 |
+
if (angleToPlayer > attackAngleThreshold) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1204 |
|
| 1205 |
+
this.createMuzzleFlash();
|
| 1206 |
+
|
| 1207 |
+
const enemyFireSound = new Audio('sounds/mbtfire5.ogg');
|
| 1208 |
+
enemyFireSound.volume = 0.3;
|
| 1209 |
+
enemyFireSound.play();
|
| 1210 |
+
|
| 1211 |
+
const bulletGeometry = new THREE.CylinderGeometry(0.2, 0.2, 2, 8);
|
| 1212 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
| 1213 |
+
color: 0xff0000,
|
| 1214 |
+
emissive: 0xff0000,
|
| 1215 |
+
emissiveIntensity: 0.5
|
| 1216 |
+
});
|
| 1217 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 1218 |
+
|
| 1219 |
+
const muzzleOffset = new THREE.Vector3(0, 0.5, 4);
|
| 1220 |
+
const muzzlePosition = new THREE.Vector3();
|
| 1221 |
+
this.mesh.getWorldPosition(muzzlePosition);
|
| 1222 |
+
muzzleOffset.applyQuaternion(this.mesh.quaternion);
|
| 1223 |
+
muzzlePosition.add(muzzleOffset);
|
| 1224 |
+
|
| 1225 |
+
bullet.position.copy(muzzlePosition);
|
| 1226 |
+
bullet.quaternion.copy(this.mesh.quaternion);
|
| 1227 |
+
|
| 1228 |
+
const direction = new THREE.Vector3()
|
| 1229 |
+
.subVectors(playerPosition, muzzlePosition)
|
| 1230 |
+
.normalize();
|
| 1231 |
+
|
| 1232 |
+
const bulletSpeed = this.type === 'tank' ?
|
| 1233 |
+
ENEMY_CONFIG.BULLET_SPEED :
|
| 1234 |
+
ENEMY_CONFIG.BULLET_SPEED * 0.8;
|
| 1235 |
+
|
| 1236 |
+
bullet.velocity = direction.multiplyScalar(bulletSpeed);
|
| 1237 |
+
|
| 1238 |
+
const trailGeometry = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
|
| 1239 |
+
const trailMaterial = new THREE.MeshBasicMaterial({
|
| 1240 |
+
color: 0xff4444,
|
| 1241 |
+
transparent: true,
|
| 1242 |
+
opacity: 0.5
|
| 1243 |
+
});
|
| 1244 |
+
|
| 1245 |
+
const trail = new THREE.Mesh(trailGeometry, trailMaterial);
|
| 1246 |
+
trail.position.z = -1;
|
| 1247 |
+
bullet.add(trail);
|
| 1248 |
+
|
| 1249 |
+
this.scene.add(bullet);
|
| 1250 |
+
this.bullets.push(bullet);
|
| 1251 |
+
this.lastAttackTime = currentTime;
|
| 1252 |
+
}
|
| 1253 |
|
| 1254 |
takeDamage(damage) {
|
| 1255 |
this.health -= damage;
|