cutechicken commited on
Commit
cd4590b
Β·
verified Β·
1 Parent(s): 1aa52d5

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +167 -45
game.js CHANGED
@@ -865,58 +865,180 @@ class EnemyFighter {
865
  }
866
  }
867
  }
868
- shoot() {
869
- this.lastShootTime = Date.now();
870
-
871
- // 직선 λͺ¨μ–‘μ˜ νƒ„ν™˜ (100% 더 크게)
872
- const bulletGeometry = new THREE.CylinderGeometry(0.8, 0.8, 12, 8);
873
- const bulletMaterial = new THREE.MeshBasicMaterial({
874
- color: 0xff0000,
875
- emissive: 0xff0000,
876
- emissiveIntensity: 1.0
877
- });
878
- const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
879
 
880
- // 기수 λμ—μ„œ λ°œμ‚¬ (8 β†’ 12둜 증가)
881
- const muzzleOffset = new THREE.Vector3(0, 0, 12); // κΈ°μ‘΄ 8μ—μ„œ 12둜 λ³€κ²½
882
- muzzleOffset.applyEuler(this.rotation);
883
- bullet.position.copy(this.position).add(muzzleOffset);
884
-
885
- // νƒ„ν™˜μ„ λ°œμ‚¬ λ°©ν–₯으둜 νšŒμ „
886
- bullet.rotation.copy(this.rotation);
887
- bullet.rotateX(Math.PI / 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
888
 
889
- const direction = new THREE.Vector3(0, 0, 1);
890
- direction.applyEuler(this.rotation);
891
- bullet.velocity = direction.multiplyScalar(1200);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
892
 
893
- this.scene.add(bullet);
894
- this.bullets.push(bullet);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895
 
896
- // MGLAUNCH.ogg μ†Œλ¦¬ μž¬μƒ - ν”Œλ ˆμ΄μ–΄κ°€ 3000m 이내에 μžˆμ„ λ•Œλ§Œ
897
- if (this.playerFighter) {
898
- const distanceToPlayer = this.position.distanceTo(this.playerFighter.position);
899
- if (distanceToPlayer < 3000) {
900
- try {
901
- const audio = new Audio('sounds/MGLAUNCH.ogg');
902
- audio.volume = 0.5;
903
-
904
- // 거리에 λ”°λ₯Έ μŒλŸ‰ 쑰절 (거리가 λ©€μˆ˜λ‘ μž‘κ²Œ)
905
- const volumeMultiplier = 1 - (distanceToPlayer / 3000);
906
- audio.volume = 0.5 * volumeMultiplier;
907
-
908
- audio.play().catch(e => console.log('Enemy gunfire sound failed to play'));
909
-
910
- // μž¬μƒ μ™„λ£Œ μ‹œ λ©”λͺ¨λ¦¬ 정리
911
- audio.addEventListener('ended', () => {
912
- audio.remove();
913
- });
914
- } catch (e) {
915
- console.log('Audio error:', e);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
916
  }
917
  }
918
  }
919
- }
920
 
921
  updateBullets(deltaTime) {
922
  for (let i = this.bullets.length - 1; i >= 0; i--) {
 
865
  }
866
  }
867
  }
 
 
 
 
 
 
 
 
 
 
 
868
 
869
+ patrol(deltaTime) {
870
+ // λͺ©ν‘œ 지점에 λ„λ‹¬ν–ˆλŠ”μ§€ 확인
871
+ const distanceToTarget = this.position.distanceTo(this.targetPosition);
872
+ if (distanceToTarget < 500) {
873
+ // μƒˆλ‘œμš΄ λͺ©ν‘œ 생성
874
+ this.targetPosition = this.generateRandomTarget();
875
+ }
876
+
877
+ // λͺ©ν‘œλ₯Ό ν–₯ν•΄ μ„ νšŒ
878
+ const direction = this.targetPosition.clone().sub(this.position).normalize();
879
+ const targetYaw = Math.atan2(direction.x, direction.z);
880
+
881
+ // λΆ€λ“œλŸ¬μš΄ μ„ νšŒ
882
+ const yawDiff = targetYaw - this.rotation.y;
883
+ const normalizedYawDiff = ((yawDiff + Math.PI) % (2 * Math.PI)) - Math.PI;
884
+
885
+ this.targetRotation.y += normalizedYawDiff * deltaTime * 0.5;
886
+
887
+ // 고도 μ‘°μ •
888
+ const altitudeDiff = this.targetPosition.y - this.position.y;
889
+ if (Math.abs(altitudeDiff) > 50) {
890
+ this.targetRotation.x = Math.max(-0.3, Math.min(0.3, altitudeDiff * 0.0001));
891
+ } else {
892
+ this.targetRotation.x = 0;
893
+ }
894
+ }
895
 
896
+ combat(playerPosition, deltaTime) {
897
+ // ν”Œλ ˆμ΄μ–΄ μœ„μΉ˜ 예츑
898
+ if (this.playerFighter && this.playerFighter.velocity) {
899
+ const bulletTravelTime = this.position.distanceTo(playerPosition) / 1200; // νƒ„ν™˜ 속도
900
+ this.predictedTargetPos = playerPosition.clone().add(
901
+ this.playerFighter.velocity.clone().multiplyScalar(bulletTravelTime)
902
+ );
903
+ } else {
904
+ this.predictedTargetPos = playerPosition.clone();
905
+ }
906
+
907
+ // 예츑 μœ„μΉ˜λ₯Ό ν–₯ν•΄ μ‘°μ€€
908
+ const aimDirection = this.predictedTargetPos.clone().sub(this.position).normalize();
909
+ const targetYaw = Math.atan2(aimDirection.x, aimDirection.z);
910
+ const targetPitch = Math.asin(-aimDirection.y);
911
+
912
+ // λΆ€λ“œλŸ¬μš΄ μ‘°μ€€
913
+ const yawDiff = targetYaw - this.rotation.y;
914
+ const normalizedYawDiff = ((yawDiff + Math.PI) % (2 * Math.PI)) - Math.PI;
915
+
916
+ this.targetRotation.y += normalizedYawDiff * deltaTime * 1.0;
917
+ this.targetRotation.x = THREE.MathUtils.lerp(this.targetRotation.x, targetPitch, deltaTime * 2.0);
918
+
919
+ // 사격 νŒλ‹¨
920
+ const distanceToPlayer = this.position.distanceTo(playerPosition);
921
+ const aimAccuracy = Math.abs(normalizedYawDiff) + Math.abs(targetPitch - this.rotation.x);
922
+
923
+ if (distanceToPlayer < 1500 && aimAccuracy < 0.1) {
924
+ // μ—°λ°œ 사격 μ‹œμŠ€ν…œ
925
+ const now = Date.now();
926
+ if (now - this.lastBurstTime > 2000) { // 2μ΄ˆλ§ˆλ‹€ μ—°λ°œ
927
+ this.burstCount = 0;
928
+ this.lastBurstTime = now;
929
+ }
930
+
931
+ if (this.burstCount < 5 && now - this.lastShootTime > 200) { // 0.2초 κ°„κ²©μœΌλ‘œ 5발
932
+ this.shoot();
933
+ this.burstCount++;
934
+ }
935
+ }
936
+
937
+ // νšŒν”Ό 기동
938
+ if (distanceToPlayer < 500) {
939
+ // λ„ˆλ¬΄ κ°€κΉŒμš°λ©΄ κΈ‰μ„ νšŒ
940
+ this.targetRotation.z = Math.sin(Date.now() * 0.001) * 0.5;
941
+ this.targetRotation.y += deltaTime * 2.0 * (Math.random() > 0.5 ? 1 : -1);
942
+ }
943
+ }
944
 
945
+ updatePhysics(deltaTime) {
946
+ if (!this.mesh) return;
947
+
948
+ // λΆ€λ“œλŸ¬μš΄ νšŒμ „ 적용
949
+ this.rotation.x = THREE.MathUtils.lerp(this.rotation.x, this.targetRotation.x, deltaTime * 2.0);
950
+ this.rotation.y = THREE.MathUtils.lerp(this.rotation.y, this.targetRotation.y, deltaTime * 1.5);
951
+ this.rotation.z = THREE.MathUtils.lerp(this.rotation.z, this.targetRotation.z, deltaTime * 3.0);
952
+
953
+ // 속도 벑터 계산
954
+ const forward = new THREE.Vector3(0, 0, 1);
955
+ forward.applyEuler(this.rotation);
956
+ this.velocity = forward.multiplyScalar(this.speed);
957
+
958
+ // μœ„μΉ˜ μ—…λ°μ΄νŠΈ
959
+ this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
960
+
961
+ // 고도 μ œν•œ
962
+ if (this.position.y < 500) {
963
+ this.position.y = 500;
964
+ this.targetRotation.x = -0.2; // μƒμŠΉ
965
+ } else if (this.position.y > 8000) {
966
+ this.position.y = 8000;
967
+ this.targetRotation.x = 0.2; // ν•˜κ°•
968
+ }
969
+
970
+ // λ§΅ 경계 처리
971
+ const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
972
+ if (Math.abs(this.position.x) > mapLimit * 0.9 || Math.abs(this.position.z) > mapLimit * 0.9) {
973
+ // λ§΅ 쀑앙을 ν–₯ν•΄ νšŒμ „
974
+ const centerDirection = new THREE.Vector3(0, this.position.y, 0).sub(this.position).normalize();
975
+ this.targetRotation.y = Math.atan2(centerDirection.x, centerDirection.z);
976
+ }
977
+
978
+ // λ©”μ‹œ μ—…λ°μ΄νŠΈ
979
+ this.mesh.position.copy(this.position);
980
+ this.mesh.rotation.x = this.rotation.x;
981
+ this.mesh.rotation.y = this.rotation.y + Math.PI;
982
+ this.mesh.rotation.z = this.rotation.z;
983
+
984
+ // μžλ™ λ‘€ 볡귀
985
+ if (Math.abs(this.targetRotation.z) > 0.01) {
986
+ this.targetRotation.z *= 0.95;
987
+ }
988
+ }
989
 
990
+ shoot() {
991
+ this.lastShootTime = Date.now();
992
+
993
+ // 직선 λͺ¨μ–‘μ˜ νƒ„ν™˜ (100% 더 크게)
994
+ const bulletGeometry = new THREE.CylinderGeometry(0.8, 0.8, 12, 8);
995
+ const bulletMaterial = new THREE.MeshBasicMaterial({
996
+ color: 0xff0000,
997
+ emissive: 0xff0000,
998
+ emissiveIntensity: 1.0
999
+ });
1000
+ const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
1001
+
1002
+ // 기수 λμ—μ„œ λ°œμ‚¬ (8 β†’ 12둜 증가)
1003
+ const muzzleOffset = new THREE.Vector3(0, 0, 12); // κΈ°μ‘΄ 8μ—μ„œ 12둜 λ³€κ²½
1004
+ muzzleOffset.applyEuler(this.rotation);
1005
+ bullet.position.copy(this.position).add(muzzleOffset);
1006
+
1007
+ // νƒ„ν™˜μ„ λ°œμ‚¬ λ°©ν–₯으둜 νšŒμ „
1008
+ bullet.rotation.copy(this.rotation);
1009
+ bullet.rotateX(Math.PI / 2);
1010
+
1011
+ const direction = new THREE.Vector3(0, 0, 1);
1012
+ direction.applyEuler(this.rotation);
1013
+ bullet.velocity = direction.multiplyScalar(1200);
1014
+
1015
+ this.scene.add(bullet);
1016
+ this.bullets.push(bullet);
1017
+
1018
+ // MGLAUNCH.ogg μ†Œλ¦¬ μž¬μƒ - ν”Œλ ˆμ΄μ–΄κ°€ 3000m 이내에 μžˆμ„ λ•Œλ§Œ
1019
+ if (this.playerFighter) {
1020
+ const distanceToPlayer = this.position.distanceTo(this.playerFighter.position);
1021
+ if (distanceToPlayer < 3000) {
1022
+ try {
1023
+ const audio = new Audio('sounds/MGLAUNCH.ogg');
1024
+ audio.volume = 0.5;
1025
+
1026
+ // 거리에 λ”°λ₯Έ μŒλŸ‰ 쑰절 (거리가 λ©€μˆ˜λ‘ μž‘κ²Œ)
1027
+ const volumeMultiplier = 1 - (distanceToPlayer / 3000);
1028
+ audio.volume = 0.5 * volumeMultiplier;
1029
+
1030
+ audio.play().catch(e => console.log('Enemy gunfire sound failed to play'));
1031
+
1032
+ // μž¬μƒ μ™„λ£Œ μ‹œ λ©”λͺ¨λ¦¬ 정리
1033
+ audio.addEventListener('ended', () => {
1034
+ audio.remove();
1035
+ });
1036
+ } catch (e) {
1037
+ console.log('Audio error:', e);
1038
+ }
1039
  }
1040
  }
1041
  }
 
1042
 
1043
  updateBullets(deltaTime) {
1044
  for (let i = this.bullets.length - 1; i >= 0; i--) {