cutechicken commited on
Commit
6307156
Β·
verified Β·
1 Parent(s): 6088e31

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +0 -161
game.js CHANGED
@@ -795,167 +795,6 @@ class EnemyFighter {
795
  }
796
 
797
  update(playerPosition, deltaTime) {
798
- if (!this.mesh || !this.isLoaded) return;
799
-
800
- const currentTime = Date.now();
801
- const distanceToPlayer = this.position.distanceTo(playerPosition);
802
-
803
- // ν”Œλ ˆμ΄μ–΄ 감지 및 μ „νˆ¬ μƒνƒœ μ „ν™˜
804
- if (distanceToPlayer < 3000) {
805
- this.isEngaged = true;
806
- this.aiState = 'combat';
807
-
808
- // ν”Œλ ˆμ΄μ–΄κ°€ μ‹œμ•Όκ° 내에 μžˆλŠ”μ§€ 확인
809
- const toPlayer = playerPosition.clone().sub(this.position).normalize();
810
- const forward = new THREE.Vector3(0, 0, 1);
811
- forward.applyEuler(this.rotation);
812
- const angle = forward.dot(toPlayer);
813
-
814
- // 예츑 사격을 μœ„ν•œ ν”Œλ ˆμ΄μ–΄ 속도 계산
815
- if (this.playerFighter) {
816
- const bulletSpeed = 1200; // νƒ„ν™˜ 속도
817
- const timeToHit = distanceToPlayer / bulletSpeed;
818
-
819
- // ν”Œλ ˆμ΄μ–΄μ˜ μ˜ˆμƒ μœ„μΉ˜ 계산
820
- this.predictedTargetPos = playerPosition.clone().add(
821
- this.playerFighter.velocity.clone().multiplyScalar(timeToHit)
822
- );
823
- }
824
-
825
- // 사격 쑰건: μ‹œμ•Όκ° 내에 있고 거리가 2000m 이내
826
- if (angle > 0.7 && distanceToPlayer < 2000) { // μ‹œμ•Όκ°μ„ μ’ν˜€μ„œ 정확도 ν–₯상
827
- // μ—°λ°œ 사격 μ‹œμŠ€ν…œ
828
- const timeSinceLastBurst = currentTime - this.lastBurstTime;
829
-
830
- // 2μ΄ˆλ§ˆλ‹€ μƒˆλ‘œμš΄ μ—°λ°œ μ‹œμž‘
831
- if (timeSinceLastBurst >= 2000) {
832
- this.burstCount = 0;
833
- this.lastBurstTime = currentTime;
834
- }
835
-
836
- // 10발 μ—°λ°œ (0.1초 간격)
837
- if (this.burstCount < 10 && currentTime - this.lastShootTime >= 100) {
838
- this.shoot();
839
- this.burstCount++;
840
- }
841
- }
842
- } else {
843
- this.isEngaged = false;
844
- this.aiState = 'patrol';
845
- }
846
-
847
- // μ „νˆ¬ 쀑일 λ•Œ ν”Œλ ˆμ΄μ–΄ 좔적
848
- if (this.isEngaged && this.playerFighter) {
849
- // ν”Œλ ˆμ΄μ–΄μ˜ 기동 νŒ¨ν„΄ λͺ¨λ°©
850
- const playerVelocity = this.playerFighter.velocity.clone().normalize();
851
- const playerRoll = this.playerFighter.rotation.z;
852
- const playerPitch = this.playerFighter.rotation.x;
853
-
854
- // 예츑된 μœ„μΉ˜λ‘œ ν–₯ν•˜λ„λ‘ μ„€μ •
855
- this.targetPosition = this.predictedTargetPos.clone();
856
-
857
- // ν”Œλ ˆμ΄μ–΄μ™€ λΉ„μŠ·ν•œ λ‘€ 적용 (μ•½κ°„μ˜ μ§€μ—°μœΌλ‘œ)
858
- this.targetRotation.z = playerRoll * 0.7;
859
-
860
- // 고도 차이에 λ”°λ₯Έ ν”ΌμΉ˜ 쑰절 (더 λΆ€λ“œλŸ½κ³  길게)
861
- const altitudeDiff = this.targetPosition.y - this.position.y;
862
-
863
- // ν”ΌμΉ˜ λ³€ν™”λ₯Ό 더 λΆ€λ“œλŸ½κ²Œ (κΈ°μ‘΄ 0.0003 β†’ 0.00015둜 50% κ°μ†Œ)
864
- this.targetRotation.x = Math.max(-0.3, Math.min(0.3, altitudeDiff * 0.00015));
865
- } else {
866
- // 순찰 λͺ¨λ“œ
867
- if (this.position.distanceTo(this.targetPosition) < 500 ||
868
- currentTime - this.lastDirectionChange > 15000) {
869
- this.targetPosition = this.generateRandomTarget();
870
- this.lastDirectionChange = currentTime;
871
- this.isTurning = false;
872
- }
873
- }
874
-
875
- // λͺ©ν‘œ λ°©ν–₯ 계산
876
- const toTarget = this.targetPosition.clone().sub(this.position);
877
- const targetAngle = Math.atan2(toTarget.x, toTarget.z);
878
- let angleDiff = targetAngle - this.rotation.y;
879
-
880
- // 각도 차이λ₯Ό -PI ~ PI λ²”μœ„λ‘œ μ •κ·œν™”
881
- while (angleDiff > Math.PI) angleDiff -= Math.PI * 2;
882
- while (angleDiff < -Math.PI) angleDiff += Math.PI * 2;
883
-
884
- // μ „νˆ¬ μ€‘μ—λŠ” 더 λΉ λ₯Έ μ„ νšŒ
885
- const turnRateMultiplier = this.isEngaged ? 2.0 : 1.0;
886
-
887
- // 큰 각도 차이가 있으면 μ›ν˜• μ„ νšŒ
888
- if (Math.abs(angleDiff) > Math.PI / 6) {
889
- this.isTurning = true;
890
- this.turnDirection = angleDiff > 0 ? 1 : -1;
891
- }
892
-
893
- // μ„ νšŒ 쀑일 λ•Œ
894
- if (this.isTurning) {
895
- // μ›ν˜• μ„ νšŒ κ΅¬ν˜„ (μ „νˆ¬ μ€‘μ—λŠ” 더 λΉ λ₯΄κ²Œ)
896
- const turnRate = (this.speed / this.turnRadius) * this.turnDirection * turnRateMultiplier;
897
- this.targetRotation.y += turnRate * deltaTime;
898
- this.targetRotation.z = this.turnDirection * 0.5 * (this.isEngaged ? 1.5 : 1); // μ „νˆ¬ 쀑 더 큰 λ‘€
899
-
900
- // λͺ©ν‘œ 각도에 κ·Όμ ‘ν•˜λ©΄ μ„ νšŒ μ’…λ£Œ
901
- const newAngleDiff = targetAngle - this.targetRotation.y;
902
- if (Math.abs(newAngleDiff) < Math.PI / 12) {
903
- this.isTurning = false;
904
- }
905
- } else {
906
- // 직진 λΉ„οΏ½οΏ½οΏ½ (μ „νˆ¬ μ€‘μ—λŠ” 더 λΉ λ₯Έ λ°˜μ‘)
907
- const lerpSpeed = this.isEngaged ? 1.0 : 0.5;
908
- this.targetRotation.y = THREE.MathUtils.lerp(this.targetRotation.y, targetAngle, deltaTime * lerpSpeed);
909
- this.targetRotation.z = THREE.MathUtils.lerp(this.targetRotation.z, 0, deltaTime * 2);
910
- }
911
-
912
- // λ‹€λ₯Έ μ κΈ°μ™€μ˜ 좩돌 νšŒν”Ό
913
- this.avoidOtherEnemies(deltaTime);
914
-
915
- // λΆ€λ“œλŸ¬μš΄ νšŒμ „ 적용 (μ „νˆ¬ μ€‘μ—λŠ” 더 λΉ λ₯΄κ²Œ)
916
- const rotationSpeed = this.isEngaged ? 3.0 : 2.0;
917
- this.rotation.x = THREE.MathUtils.lerp(this.rotation.x, this.targetRotation.x, deltaTime * rotationSpeed * 0.5); // xμΆ•(ν”ΌμΉ˜) νšŒμ „λ§Œ 50% 느리게
918
- this.rotation.y = THREE.MathUtils.lerp(this.rotation.y, this.targetRotation.y, deltaTime * rotationSpeed);
919
- this.rotation.z = THREE.MathUtils.lerp(this.rotation.z, this.targetRotation.z, deltaTime * rotationSpeed * 1.25);
920
-
921
- // 속도 벑터 계산
922
- const forward = new THREE.Vector3(0, 0, 1);
923
- forward.applyEuler(this.rotation);
924
- this.velocity = forward.multiplyScalar(this.speed);
925
-
926
- // μœ„μΉ˜ μ—…λ°μ΄νŠΈ
927
- this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
928
-
929
- // 고도 μ œν•œ
930
- if (this.position.y < 500) {
931
- this.position.y = 500;
932
- this.targetRotation.x = -0.2; // μƒμŠΉ
933
- }
934
- if (this.position.y > GAME_CONSTANTS.MAX_ALTITUDE - 500) {
935
- this.position.y = GAME_CONSTANTS.MAX_ALTITUDE - 500;
936
- this.targetRotation.x = 0.2; // ν•˜κ°•
937
- }
938
-
939
- // λ§΅ 경계 처리
940
- const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
941
- if (Math.abs(this.position.x) > mapLimit * 0.9 || Math.abs(this.position.z) > mapLimit * 0.9) {
942
- // λ§΅ 경계에 κ°€κΉŒμ›Œμ§€λ©΄ μ€‘μ•™μœΌλ‘œ ν–₯ν•˜λŠ” μƒˆ λͺ©ν‘œ μ„€μ •
943
- this.targetPosition = new THREE.Vector3(
944
- (Math.random() - 0.5) * mapLimit * 0.5,
945
- 1000 + Math.random() * 3000,
946
- (Math.random() - 0.5) * mapLimit * 0.5
947
- );
948
- this.lastDirectionChange = currentTime;
949
- }
950
-
951
- // λ©”μ‹œ μ—…λ°μ΄νŠΈ
952
- this.mesh.position.copy(this.position);
953
- this.mesh.rotation.x = this.rotation.x;
954
- this.mesh.rotation.y = this.rotation.y + 3 * Math.PI / 2;
955
- this.mesh.rotation.z = this.rotation.z;
956
-
957
- this.updateBullets(deltaTime);
958
- }
959
 
960
  avoidOtherEnemies(deltaTime) {
961
  if (!this.nearbyEnemies) return;
 
795
  }
796
 
797
  update(playerPosition, deltaTime) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
 
799
  avoidOtherEnemies(deltaTime) {
800
  if (!this.nearbyEnemies) return;