cutechicken commited on
Commit
23275ba
โ€ข
1 Parent(s): 5ca5ee0

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +89 -97
game.js CHANGED
@@ -732,119 +732,111 @@ class Enemy {
732
 
733
  // ๋ฉ”์ธ ์—…๋ฐ์ดํŠธ ํ•จ์ˆ˜
734
  update(playerPosition) {
735
- if (!this.mesh || !this.isLoaded) return;
736
 
737
- // AI ์ƒํƒœ ์—…๋ฐ์ดํŠธ
738
- this.updateAIState(playerPosition);
739
 
740
- // ์žฅ์• ๋ฌผ ๊ฐ์ง€
741
- const obstacles = this.detectObstacles();
742
- const currentTime = Date.now();
743
- const hasLineOfSight = this.checkLineOfSight(playerPosition);
744
- const distanceToPlayer = this.mesh.position.distanceTo(playerPosition);
745
- // ๊ฒฝ๋กœ ์—…๋ฐ์ดํŠธ ์ฃผ๊ธฐ ์ฒดํฌ
746
- if (currentTime - this.lastPathUpdateTime > this.pathUpdateInterval) {
747
- if (!hasLineOfSight) {
748
- this.alternativePath = this.findAlternativePath(playerPosition);
749
- }
750
- this.lastPathUpdateTime = currentTime;
751
- }
752
- if (!hasLineOfSight) {
753
- if (this.alternativePath) {
754
- const pathDirection = new THREE.Vector3()
755
- .subVectors(this.alternativePath, this.mesh.position)
756
- .normalize();
757
- this.mesh.position.add(pathDirection.multiplyScalar(this.moveSpeed));
758
-
759
- const targetRotation = Math.atan2(pathDirection.x, pathDirection.z);
760
- this.mesh.rotation.y = this.smoothRotation(this.mesh.rotation.y, targetRotation, 0.1);
761
- }
762
- } else {
763
- this.alternativePath = null;
764
-
765
- // ๊ฑฐ๋ฆฌ์— ๋”ฐ๋ฅธ ํ–‰๋™ ๊ฒฐ์ •
766
- if (distanceToPlayer > ENEMY_CONFIG.ATTACK_RANGE * 0.7) {
767
- const moveDirection = new THREE.Vector3()
768
- .subVectors(playerPosition, this.mesh.position)
769
- .normalize();
770
- this.mesh.position.add(moveDirection.multiplyScalar(this.moveSpeed));
771
- } else if (distanceToPlayer < ENEMY_CONFIG.ATTACK_RANGE * 0.3) {
772
- const retreatDirection = new THREE.Vector3()
773
- .subVectors(this.mesh.position, playerPosition)
774
- .normalize();
775
- this.mesh.position.add(retreatDirection.multiplyScalar(this.moveSpeed));
776
- }
777
-
778
- // ํ”Œ๋ ˆ์ด์–ด ๋ฐฉํ–ฅ์œผ๋กœ ํšŒ์ „
779
- const directionToPlayer = new THREE.Vector3()
780
- .subVectors(playerPosition, this.mesh.position)
781
- .normalize();
782
- const targetRotation = Math.atan2(directionToPlayer.x, directionToPlayer.z);
783
- this.mesh.rotation.y = this.smoothRotation(this.mesh.rotation.y, targetRotation, 0.1);
784
 
785
- // ๊ณต๊ฒฉ ์กฐ๊ฑด ํ™•์ธ
786
- if (hasLineOfSight && distanceToPlayer <= ENEMY_CONFIG.ATTACK_RANGE) {
787
- this.shoot(playerPosition);
788
- }
789
  }
 
790
  }
791
- }
792
 
793
-
794
- // ์ด๋™ ๋ฐ ํšŒํ”ผ ๋กœ์ง
795
- if (obstacles.length > 0 && !this.pathfinding.isAvoidingObstacle) {
796
- this.pathfinding.isAvoidingObstacle = true;
797
- this.pathfinding.avoidanceDirection = this.calculateAvoidanceDirection(obstacles);
798
- this.pathfinding.avoidanceTime = 0;
799
- }
800
 
801
- // ํšŒํ”ผ ๋™์ž‘ ์ˆ˜ํ–‰
802
- if (this.pathfinding.isAvoidingObstacle) {
803
- this.pathfinding.avoidanceTime += 16; // ์•ฝ 16ms per frame
804
- if (this.pathfinding.avoidanceTime >= this.pathfinding.maxAvoidanceTime) {
805
- this.pathfinding.isAvoidingObstacle = false;
806
- } else {
807
- const avoidMove = this.pathfinding.avoidanceDirection.multiplyScalar(this.moveSpeed);
808
- this.mesh.position.add(avoidMove);
809
- }
810
  } else {
811
- // ์ผ๋ฐ˜ ์ด๋™ ๋กœ์ง
812
- switch (this.aiState.mode) {
813
- case 'pursue':
814
- this.findPathToTarget(playerPosition);
815
- this.moveAlongPath();
816
- break;
817
- case 'flank':
818
- const flankPosition = this.calculateFlankPosition(playerPosition);
819
- this.findPathToTarget(flankPosition);
820
- this.moveAlongPath();
821
- break;
822
- case 'retreat':
823
- const retreatPosition = this.calculateRetreatPosition(playerPosition);
824
- this.findPathToTarget(retreatPosition);
825
- this.moveAlongPath();
826
- break;
827
- }
828
  }
 
 
 
 
 
 
 
829
 
830
- // ์ „ํˆฌ ๊ฑฐ๋ฆฌ ์กฐ์ •
831
- const combatMove = this.maintainCombatDistance(playerPosition);
832
- if (combatMove.length() > 0) {
833
- this.mesh.position.add(combatMove.multiplyScalar(this.moveSpeed));
834
  }
 
 
 
835
 
836
- // ๋ฐœ์‚ฌ ์ฒ˜๋ฆฌ
837
- if (this.canShoot(playerPosition)) {
838
- this.shoot(playerPosition);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
839
  }
840
 
841
- // ์ด์•Œ ์—…๋ฐ์ดํŠธ
842
- this.updateBullets();
 
 
 
 
 
843
 
844
- // ํƒฑํฌ ๊ธฐ์šธ๊ธฐ ์กฐ์ •
845
- this.adjustTankTilt();
 
 
846
  }
847
- checkLineOfSight(targetPosition) {
 
 
 
 
 
 
 
 
 
 
 
 
 
848
  if (!this.mesh) return false;
849
 
850
  const startPos = this.mesh.position.clone();
 
732
 
733
  // ๋ฉ”์ธ ์—…๋ฐ์ดํŠธ ํ•จ์ˆ˜
734
  update(playerPosition) {
735
+ if (!this.mesh || !this.isLoaded) return;
736
 
737
+ // AI ์ƒํƒœ ์—…๋ฐ์ดํŠธ
738
+ this.updateAIState(playerPosition);
739
 
740
+ // ์žฅ์• ๋ฌผ ๊ฐ์ง€ ๋ฐ ์‹œ์•ผ ์ฒดํฌ
741
+ const obstacles = this.detectObstacles();
742
+ const currentTime = Date.now();
743
+ const hasLineOfSight = this.checkLineOfSight(playerPosition);
744
+ const distanceToPlayer = this.mesh.position.distanceTo(playerPosition);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
745
 
746
+ // ๊ฒฝ๋กœ ์—…๋ฐ์ดํŠธ ์ฃผ๊ธฐ ์ฒดํฌ
747
+ if (currentTime - this.lastPathUpdateTime > this.pathUpdateInterval) {
748
+ if (!hasLineOfSight) {
749
+ this.alternativePath = this.findAlternativePath(playerPosition);
750
  }
751
+ this.lastPathUpdateTime = currentTime;
752
  }
 
753
 
754
+ // ์žฅ์• ๋ฌผ ํšŒํ”ผ ๋กœ์ง
755
+ if (obstacles.length > 0 && !this.pathfinding.isAvoidingObstacle) {
756
+ this.pathfinding.isAvoidingObstacle = true;
757
+ this.pathfinding.avoidanceDirection = this.calculateAvoidanceDirection(obstacles);
758
+ this.pathfinding.avoidanceTime = 0;
759
+ }
 
760
 
761
+ // ์ด๋™ ๋กœ์ง ์‹คํ–‰
762
+ if (this.pathfinding.isAvoidingObstacle) {
763
+ // ํšŒํ”ผ ๋™์ž‘
764
+ this.pathfinding.avoidanceTime += 16;
765
+ if (this.pathfinding.avoidanceTime >= this.pathfinding.maxAvoidanceTime) {
766
+ this.pathfinding.isAvoidingObstacle = false;
 
 
 
767
  } else {
768
+ const avoidMove = this.pathfinding.avoidanceDirection.multiplyScalar(this.moveSpeed);
769
+ this.mesh.position.add(avoidMove);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
770
  }
771
+ } else if (!hasLineOfSight) {
772
+ // ์‹œ์•ผ๊ฐ€ ์—†์„ ๋•Œ์˜ ์ด๋™
773
+ if (this.alternativePath) {
774
+ const pathDirection = new THREE.Vector3()
775
+ .subVectors(this.alternativePath, this.mesh.position)
776
+ .normalize();
777
+ this.mesh.position.add(pathDirection.multiplyScalar(this.moveSpeed));
778
 
779
+ const targetRotation = Math.atan2(pathDirection.x, pathDirection.z);
780
+ this.mesh.rotation.y = this.smoothRotation(this.mesh.rotation.y, targetRotation, 0.1);
 
 
781
  }
782
+ } else {
783
+ // ์‹œ์•ผ๊ฐ€ ์žˆ์„ ๋•Œ์˜ ์ด๋™
784
+ this.alternativePath = null;
785
 
786
+ // AI ์ƒํƒœ์— ๋”ฐ๋ฅธ ์ด๋™
787
+ switch (this.aiState.mode) {
788
+ case 'pursue':
789
+ if (distanceToPlayer > ENEMY_CONFIG.ATTACK_RANGE * 0.7) {
790
+ const moveDirection = new THREE.Vector3()
791
+ .subVectors(playerPosition, this.mesh.position)
792
+ .normalize();
793
+ this.mesh.position.add(moveDirection.multiplyScalar(this.moveSpeed));
794
+ }
795
+ break;
796
+
797
+ case 'flank':
798
+ const flankPosition = this.calculateFlankPosition(playerPosition);
799
+ this.findPathToTarget(flankPosition);
800
+ this.moveAlongPath();
801
+ break;
802
+
803
+ case 'retreat':
804
+ if (distanceToPlayer < ENEMY_CONFIG.ATTACK_RANGE * 0.3) {
805
+ const retreatDirection = new THREE.Vector3()
806
+ .subVectors(this.mesh.position, playerPosition)
807
+ .normalize();
808
+ this.mesh.position.add(retreatDirection.multiplyScalar(this.moveSpeed));
809
+ }
810
+ break;
811
  }
812
 
813
+ // ํ”Œ๋ ˆ์ด์–ด ๋ฐฉํ–ฅ์œผ๋กœ ํšŒ์ „
814
+ const directionToPlayer = new THREE.Vector3()
815
+ .subVectors(playerPosition, this.mesh.position)
816
+ .normalize();
817
+ const targetRotation = Math.atan2(directionToPlayer.x, directionToPlayer.z);
818
+ this.mesh.rotation.y = this.smoothRotation(this.mesh.rotation.y, targetRotation, 0.1);
819
+ }
820
 
821
+ // ์ „ํˆฌ ๊ฑฐ๋ฆฌ ์กฐ์ •
822
+ const combatMove = this.maintainCombatDistance(playerPosition);
823
+ if (combatMove.length() > 0) {
824
+ this.mesh.position.add(combatMove.multiplyScalar(this.moveSpeed));
825
  }
826
+
827
+ // ๊ณต๊ฒฉ ์ฒ˜๋ฆฌ
828
+ if (hasLineOfSight && distanceToPlayer <= ENEMY_CONFIG.ATTACK_RANGE && this.canShoot(playerPosition)) {
829
+ this.shoot(playerPosition);
830
+ }
831
+
832
+ // ์ด์•Œ ์—…๋ฐ์ดํŠธ
833
+ this.updateBullets();
834
+
835
+ // ํƒฑํฌ ๊ธฐ์šธ๊ธฐ ์กฐ์ •
836
+ this.adjustTankTilt();
837
+ }
838
+
839
+ checkLineOfSight(targetPosition) {
840
  if (!this.mesh) return false;
841
 
842
  const startPos = this.mesh.position.clone();