cutechicken commited on
Commit
6ed5450
โ€ข
1 Parent(s): 49be16c

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +66 -51
game.js CHANGED
@@ -1179,62 +1179,77 @@ checkPathClear(start, end) {
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
- this.createMuzzleFlash();
 
 
 
 
 
 
1191
 
1192
- const enemyFireSound = new Audio('sounds/mbtfire5.ogg');
1193
- enemyFireSound.volume = 0.3;
1194
- enemyFireSound.play();
1195
 
1196
- const bulletGeometry = new THREE.CylinderGeometry(0.2, 0.2, 2, 8);
1197
- const bulletMaterial = new THREE.MeshBasicMaterial({
1198
- color: 0xff0000,
1199
- emissive: 0xff0000,
1200
- emissiveIntensity: 0.5
1201
- });
1202
- const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
1203
 
1204
- const muzzleOffset = new THREE.Vector3(0, 0.5, 4);
1205
- const muzzlePosition = new THREE.Vector3();
1206
- this.mesh.getWorldPosition(muzzlePosition);
1207
- muzzleOffset.applyQuaternion(this.mesh.quaternion);
1208
- muzzlePosition.add(muzzleOffset);
1209
-
1210
- bullet.position.copy(muzzlePosition);
1211
- bullet.quaternion.copy(this.mesh.quaternion);
1212
-
1213
- const direction = new THREE.Vector3()
1214
- .subVectors(playerPosition, muzzlePosition)
1215
- .normalize();
1216
-
1217
- const bulletSpeed = this.type === 'tank' ?
1218
- ENEMY_CONFIG.BULLET_SPEED :
1219
- ENEMY_CONFIG.BULLET_SPEED * 0.8;
1220
-
1221
- bullet.velocity = direction.multiplyScalar(bulletSpeed);
1222
-
1223
- const trailGeometry = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
1224
- const trailMaterial = new THREE.MeshBasicMaterial({
1225
- color: 0xff4444,
1226
- transparent: true,
1227
- opacity: 0.5
1228
- });
1229
-
1230
- const trail = new THREE.Mesh(trailGeometry, trailMaterial);
1231
- trail.position.z = -1;
1232
- bullet.add(trail);
1233
-
1234
- this.scene.add(bullet);
1235
- this.bullets.push(bullet);
1236
- this.lastAttackTime = currentTime;
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;