cutechicken commited on
Commit
9bac41b
Β·
verified Β·
1 Parent(s): 373a5b5

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +30 -8
game.js CHANGED
@@ -792,7 +792,7 @@ class Fighter {
792
  }
793
  }
794
 
795
- // 적 μ „νˆ¬κΈ° 클래슀 - μ™„μ „νžˆ μž¬μ„€κ³„
796
  class EnemyFighter {
797
  constructor(scene, position) {
798
  this.mesh = null;
@@ -838,6 +838,9 @@ class EnemyFighter {
838
  this.nearbyEnemies = [];
839
  this.avoidanceVector = new THREE.Vector3();
840
 
 
 
 
841
  // 초기 λͺ©ν‘œ μ„€μ •
842
  this.selectNewPatrolTarget();
843
  }
@@ -889,7 +892,7 @@ class EnemyFighter {
889
  }
890
 
891
  update(playerPosition, deltaTime) {
892
- if (!this.mesh || !this.isLoaded) return;
893
 
894
  // νšŒν”Ό 타이머 μ—…λ°μ΄νŠΈ
895
  if (this.temporaryEvadeMode && this.evadeTimer > 0) {
@@ -905,7 +908,6 @@ class EnemyFighter {
905
  if (distanceToPlayer < 100) {
906
  this.isRetreating = true;
907
  this.aiState = 'retreat';
908
- // 후퇴 μ‹œμž‘ μ‹œ 둜그
909
  console.log(`Enemy retreating! Distance: ${distanceToPlayer.toFixed(1)}m`);
910
  }
911
 
@@ -918,7 +920,6 @@ class EnemyFighter {
918
  // μƒνƒœ κ²°μ • - 후퇴가 μ΅œμš°μ„ 
919
  if (this.isRetreating) {
920
  this.aiState = 'retreat';
921
- // 후퇴 μ€‘μ—λŠ” λ‹€λ₯Έ μƒνƒœλ‘œ λ³€κ²½ λΆˆκ°€
922
  } else if (this.temporaryEvadeMode) {
923
  this.aiState = 'evade';
924
  } else if (distanceToPlayer <= 3000) {
@@ -956,7 +957,6 @@ class EnemyFighter {
956
  this.updateBullets(deltaTime);
957
  }
958
 
959
- // μƒˆλ‘œμš΄ λ©”μ„œλ“œ: 후퇴 μ‹€ν–‰
960
  executeRetreat(playerPosition, deltaTime) {
961
  // ν”Œλ ˆμ΄μ–΄λ‘œλΆ€ν„° λ©€μ–΄μ§€λŠ” λ°©ν–₯ 계산
962
  const retreatDirection = this.position.clone().sub(playerPosition).normalize();
@@ -1294,7 +1294,7 @@ class EnemyFighter {
1294
  }
1295
 
1296
  updatePhysics(deltaTime) {
1297
- if (!this.mesh) return;
1298
 
1299
  // 속도 벑터 계산 (항상 μ „μ§„)
1300
  const forward = new THREE.Vector3(0, 0, 1);
@@ -1482,14 +1482,36 @@ class EnemyFighter {
1482
 
1483
  takeDamage(damage) {
1484
  this.health -= damage;
1485
- return this.health <= 0;
 
 
 
 
 
 
1486
  }
1487
 
1488
  destroy() {
1489
- if (this.mesh) {
 
 
 
 
 
 
 
 
 
 
 
 
1490
  this.scene.remove(this.mesh);
 
 
 
1491
  this.bullets.forEach(bullet => this.scene.remove(bullet));
1492
  this.bullets = [];
 
1493
  this.isLoaded = false;
1494
  }
1495
  }
 
792
  }
793
  }
794
 
795
+ // 적 μ „νˆ¬κΈ° 클래슀 - 폭발 처리 μˆ˜μ •
796
  class EnemyFighter {
797
  constructor(scene, position) {
798
  this.mesh = null;
 
838
  this.nearbyEnemies = [];
839
  this.avoidanceVector = new THREE.Vector3();
840
 
841
+ // 파괴 μƒνƒœ μΆ”κ°€
842
+ this.isDestroyed = false;
843
+
844
  // 초기 λͺ©ν‘œ μ„€μ •
845
  this.selectNewPatrolTarget();
846
  }
 
892
  }
893
 
894
  update(playerPosition, deltaTime) {
895
+ if (!this.mesh || !this.isLoaded || this.isDestroyed) return;
896
 
897
  // νšŒν”Ό 타이머 μ—…λ°μ΄νŠΈ
898
  if (this.temporaryEvadeMode && this.evadeTimer > 0) {
 
908
  if (distanceToPlayer < 100) {
909
  this.isRetreating = true;
910
  this.aiState = 'retreat';
 
911
  console.log(`Enemy retreating! Distance: ${distanceToPlayer.toFixed(1)}m`);
912
  }
913
 
 
920
  // μƒνƒœ κ²°μ • - 후퇴가 μ΅œμš°μ„ 
921
  if (this.isRetreating) {
922
  this.aiState = 'retreat';
 
923
  } else if (this.temporaryEvadeMode) {
924
  this.aiState = 'evade';
925
  } else if (distanceToPlayer <= 3000) {
 
957
  this.updateBullets(deltaTime);
958
  }
959
 
 
960
  executeRetreat(playerPosition, deltaTime) {
961
  // ν”Œλ ˆμ΄μ–΄λ‘œλΆ€ν„° λ©€μ–΄μ§€λŠ” λ°©ν–₯ 계산
962
  const retreatDirection = this.position.clone().sub(playerPosition).normalize();
 
1294
  }
1295
 
1296
  updatePhysics(deltaTime) {
1297
+ if (!this.mesh || this.isDestroyed) return;
1298
 
1299
  // 속도 벑터 계산 (항상 μ „μ§„)
1300
  const forward = new THREE.Vector3(0, 0, 1);
 
1482
 
1483
  takeDamage(damage) {
1484
  this.health -= damage;
1485
+
1486
+ // 체λ ₯이 0 μ΄ν•˜κ°€ 되면 true λ°˜ν™˜ (파괴됨)
1487
+ if (this.health <= 0) {
1488
+ this.isDestroyed = true;
1489
+ return true;
1490
+ }
1491
+ return false;
1492
  }
1493
 
1494
  destroy() {
1495
+ if (this.mesh && !this.isDestroyed) {
1496
+ // 파괴 μƒνƒœ μ„€μ •
1497
+ this.isDestroyed = true;
1498
+
1499
+ // 폭발 효과 생성 - window.gameInstance 확인
1500
+ if (window.gameInstance && window.gameInstance.createExplosionEffect) {
1501
+ console.log('Enemy destroyed at position:', this.position);
1502
+ window.gameInstance.createExplosionEffect(this.position.clone());
1503
+ } else {
1504
+ console.error('Game instance or createExplosionEffect not available');
1505
+ }
1506
+
1507
+ // λ©”μ‹œ 제거
1508
  this.scene.remove(this.mesh);
1509
+ this.mesh = null;
1510
+
1511
+ // 남은 νƒ„ν™˜λ“€ 제거
1512
  this.bullets.forEach(bullet => this.scene.remove(bullet));
1513
  this.bullets = [];
1514
+
1515
  this.isLoaded = false;
1516
  }
1517
  }