cutechicken commited on
Commit
47576da
ยท
verified ยท
1 Parent(s): 6c39306

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +5 -130
game.js CHANGED
@@ -815,10 +815,6 @@ class EnemyFighter {
815
  this.temporaryEvadeMode = false;
816
  this.evadeTimer = 0;
817
 
818
- // ํ›„ํ‡ด ์‹œ์Šคํ…œ
819
- this.isRetreating = false;
820
- this.retreatTargetDistance = 250; // ๋ชฉํ‘œ ํ›„ํ‡ด ๊ฑฐ๋ฆฌ
821
-
822
  // ์ถฉ๋Œ ์˜ˆ์ธก
823
  this.predictedPosition = new THREE.Vector3();
824
 
@@ -899,25 +895,6 @@ class EnemyFighter {
899
 
900
  const distanceToPlayer = this.position.distanceTo(playerPosition);
901
 
902
- // 100m ์ด๋‚ด๋ฉด ์ฆ‰์‹œ ํ›„ํ‡ด ๋ชจ๋“œ ํ™œ์„ฑํ™”
903
- if (distanceToPlayer < 100) {
904
- this.isRetreating = true;
905
- this.aiState = 'retreat';
906
- // ํ›„ํ‡ด ์‹œ์ž‘ ์‹œ ๋กœ๊ทธ
907
- console.log(`Enemy retreating! Distance: ${distanceToPlayer.toFixed(1)}m`);
908
- }
909
-
910
- // 250m ์ด์ƒ ๋–จ์–ด์ง€๋ฉด ํ›„ํ‡ด ๋ชจ๋“œ ํ•ด์ œ
911
- if (this.isRetreating && distanceToPlayer >= this.retreatTargetDistance) {
912
- this.isRetreating = false;
913
- console.log(`Enemy retreat complete. Distance: ${distanceToPlayer.toFixed(1)}m`);
914
- }
915
-
916
- // ์ƒํƒœ ๊ฒฐ์ • - ํ›„ํ‡ด๊ฐ€ ์ตœ์šฐ์„ 
917
- if (this.isRetreating) {
918
- this.aiState = 'retreat';
919
- // ํ›„ํ‡ด ์ค‘์—๋Š” ๋‹ค๋ฅธ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€
920
- } else if (this.temporaryEvadeMode) {
921
  this.aiState = 'evade';
922
  } else if (distanceToPlayer <= 3000) {
923
  this.aiState = 'combat';
@@ -925,11 +902,9 @@ class EnemyFighter {
925
  this.aiState = 'patrol';
926
  }
927
 
928
- // ์ถฉ๋Œ ํšŒํ”ผ ๊ณ„์‚ฐ (ํ›„ํ‡ด ์ค‘์ด ์•„๋‹ ๋•Œ๋งŒ)
929
- if (!this.isRetreating) {
930
- this.calculateAvoidance();
931
- this.checkCollisionPrediction(deltaTime);
932
- }
933
 
934
  // AI ํ–‰๋™ ์‹คํ–‰
935
  switch (this.aiState) {
@@ -942,9 +917,6 @@ class EnemyFighter {
942
  case 'evade':
943
  this.executeEmergencyEvade(deltaTime);
944
  break;
945
- case 'retreat':
946
- this.executeRetreat(playerPosition, deltaTime);
947
- break;
948
  }
949
 
950
  // ๋ฌผ๋ฆฌ ์—…๋ฐ์ดํŠธ
@@ -954,56 +926,6 @@ class EnemyFighter {
954
  this.updateBullets(deltaTime);
955
  }
956
 
957
- // ์ƒˆ๋กœ์šด ๋ฉ”์„œ๋“œ: ํ›„ํ‡ด ์‹คํ–‰
958
- executeRetreat(playerPosition, deltaTime) {
959
- // ํ”Œ๋ ˆ์ด์–ด๋กœ๋ถ€ํ„ฐ ๋ฉ€์–ด์ง€๋Š” ๋ฐฉํ–ฅ ๊ณ„์‚ฐ
960
- const retreatDirection = this.position.clone().sub(playerPosition).normalize();
961
-
962
- // ์ˆ˜ํ‰ ๋ฐฉํ–ฅ ๊ฐ•์กฐ (์ˆ˜์ง ์ด๋™ ๊ฐ์†Œ)
963
- retreatDirection.y *= 0.3;
964
- retreatDirection.normalize();
965
-
966
- // ๋ชฉํ‘œ ์œ„์น˜ ์„ค์ • (ํ˜„์žฌ ์œ„์น˜์—์„œ ํ”Œ๋ ˆ์ด์–ด ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ์œผ๋กœ 500m)
967
- const targetPosition = this.position.clone().add(retreatDirection.multiplyScalar(500));
968
-
969
- // ํ›„ํ‡ด ์ค‘์—๋Š” ์ตœ๋Œ€ ์†๋„
970
- this.speed = this.maxSpeed;
971
-
972
- // ๋งค์šฐ ๋น ๋ฅธ ํšŒ์ „์œผ๋กœ ์ฆ‰์‹œ ํ›„ํ‡ด ๋ฐฉํ–ฅ์„ ํ–ฅํ•˜๋„๋ก
973
- const targetYaw = Math.atan2(retreatDirection.x, retreatDirection.z);
974
- const targetPitch = Math.asin(-retreatDirection.y);
975
-
976
- // ๊ธด๊ธ‰ ํšŒ์ „ ์†๋„ (3๋ฐฐ ๋น ๋ฅด๊ฒŒ)
977
- const emergencyTurnSpeed = this.turnSpeed * 3.0;
978
- const maxTurnRate = emergencyTurnSpeed * deltaTime;
979
-
980
- // Yaw ํšŒ์ „ (์ฆ‰์‹œ ํšŒ์ „)
981
- const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
982
- if (Math.abs(yawDiff) > maxTurnRate) {
983
- this.rotation.y += Math.sign(yawDiff) * maxTurnRate;
984
- } else {
985
- this.rotation.y = targetYaw;
986
- }
987
-
988
- // Pitch ํšŒ์ „ (์ œํ•œ์ ์ด์ง€๋งŒ ๋น ๋ฅด๊ฒŒ)
989
- const pitchDiff = targetPitch - this.rotation.x;
990
- if (Math.abs(pitchDiff) > maxTurnRate * 0.7) {
991
- this.rotation.x += Math.sign(pitchDiff) * maxTurnRate * 0.7;
992
- } else {
993
- this.rotation.x = targetPitch;
994
- }
995
-
996
- // ํ›„ํ‡ด ์ค‘ ๊ธ‰์„ ํšŒ๋ฅผ ์œ„ํ•œ ๋กค
997
- this.rotation.z = Math.sign(yawDiff) * Math.min(Math.abs(yawDiff), Math.PI / 4);
998
-
999
- // ํ›„ํ‡ด ์ค‘์—๋Š” ๋ฐœ์‚ฌ ๊ธˆ์ง€
1000
- this.canShoot = false;
1001
- this.burstCounter = 0;
1002
-
1003
- // ์ถฉ๋Œ ํšŒํ”ผ ๋ฒกํ„ฐ ์ดˆ๊ธฐํ™” (ํ›„ํ‡ด๊ฐ€ ์šฐ์„ )
1004
- this.avoidanceVector.set(0, 0, 0);
1005
- }
1006
-
1007
  executePatrol(deltaTime) {
1008
  // ๋ชฉํ‘œ ์ง€์ ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ ํ™•์ธ
1009
  if (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {
@@ -1023,13 +945,6 @@ class EnemyFighter {
1023
  executeCombat(playerPosition, deltaTime) {
1024
  const distance = this.position.distanceTo(playerPosition);
1025
 
1026
- // 100m ๋ฏธ๋งŒ์ด๋ฉด ์ฆ‰์‹œ ํ›„ํ‡ด๋กœ ์ „ํ™˜ (์ด์ค‘ ์ฒดํฌ)
1027
- if (distance < 100) {
1028
- this.isRetreating = true;
1029
- this.aiState = 'retreat';
1030
- console.log(`Combat -> Retreat triggered! Distance: ${distance.toFixed(1)}m`);
1031
- return; // ์ฆ‰์‹œ ๋ฆฌํ„ดํ•˜์—ฌ ์ „ํˆฌ ๋กœ์ง ์‹คํ–‰ ๋ฐฉ์ง€
1032
- }
1033
 
1034
  // ํ”Œ๋ ˆ์ด์–ด๋ฅผ ํ–ฅํ•ด ํšŒ์ „
1035
  this.smoothTurnToTarget(playerPosition, deltaTime);
@@ -1043,8 +958,7 @@ class EnemyFighter {
1043
  const isStraightFlying = isPitchLevel && isRollLevel;
1044
 
1045
  // ์ง์ง„ ๋น„ํ–‰ ์ค‘์ด๊ณ  ์ •ํ™•ํ•œ ์กฐ์ค€ ์‹œ์—๋งŒ ๋ฐœ์‚ฌ ๊ฐ€๋Šฅ
1046
- // 200m ์ด์ƒ์—์„œ๋งŒ ๋ฐœ์‚ฌ (์•ˆ์ „ ๊ฑฐ๋ฆฌ ํ™•๋ณด)
1047
- this.canShoot = isStraightFlying && aimAccuracy < 0.15 && distance > 200;
1048
 
1049
  // ๋ฐœ์‚ฌ ์กฐ๊ฑด ์ถฉ์กฑ ์‹œ ๋ฐœ์‚ฌ
1050
  if (this.canShoot) {
@@ -1148,46 +1062,7 @@ class EnemyFighter {
1148
  }
1149
 
1150
  smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {
1151
- // ํ›„ํ‡ด ์ค‘์ด๋ฉด ํšŒํ”ผ ๋ฒกํ„ฐ ๋ฌด์‹œ
1152
- if (this.isRetreating) {
1153
- // ํƒ€๊ฒŸ ๋ฐฉํ–ฅ ๊ณ„์‚ฐ
1154
- const direction = targetPos.clone().sub(this.position);
1155
- direction.y *= 0.5;
1156
- direction.normalize();
1157
-
1158
- // ๋ชฉํ‘œ ํšŒ์ „ ๊ณ„์‚ฐ
1159
- const targetYaw = Math.atan2(direction.x, direction.z);
1160
- const targetPitch = Math.asin(-direction.y);
1161
-
1162
- // ํ›„ํ‡ด ์ค‘์—๋Š” ๋งค์šฐ ๋น ๋ฅธ ํšŒ์ „
1163
- const turnSpeed = this.turnSpeed * 3.0;
1164
- const maxTurnRate = turnSpeed * deltaTime;
1165
-
1166
- // Yaw ํšŒ์ „
1167
- const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
1168
- if (Math.abs(yawDiff) > maxTurnRate) {
1169
- this.rotation.y += Math.sign(yawDiff) * maxTurnRate;
1170
- } else {
1171
- this.rotation.y = targetYaw;
1172
- }
1173
-
1174
- // Pitch ํšŒ์ „
1175
- const maxPitchRate = maxTurnRate * 0.7;
1176
- if (Math.abs(targetPitch - this.rotation.x) > maxPitchRate) {
1177
- this.rotation.x += Math.sign(targetPitch - this.rotation.x) * maxPitchRate;
1178
- } else {
1179
- this.rotation.x = targetPitch;
1180
- }
1181
-
1182
- // Pitch ์ œํ•œ
1183
- const maxPitchAngle = Math.PI * 40 / 180;
1184
- this.rotation.x = THREE.MathUtils.clamp(this.rotation.x, -maxPitchAngle, maxPitchAngle);
1185
-
1186
- // ํ›„ํ‡ด ์ค‘ ๊ธ‰์„ ํšŒ๋ฅผ ์œ„ํ•œ ๋กค
1187
- this.rotation.z = Math.sign(yawDiff) * Math.min(Math.abs(yawDiff), Math.PI / 3);
1188
-
1189
- return; // ํ›„ํ‡ด ์ค‘์ด๋ฉด ์—ฌ๊ธฐ์„œ ์ข…๋ฃŒ
1190
- }
1191
 
1192
  // ๊ธฐ์กด ๋กœ์ง (ํ›„ํ‡ด๊ฐ€ ์•„๋‹ ๋•Œ)
1193
  const direction = targetPos.clone().sub(this.position);
 
815
  this.temporaryEvadeMode = false;
816
  this.evadeTimer = 0;
817
 
 
 
 
 
818
  // ์ถฉ๋Œ ์˜ˆ์ธก
819
  this.predictedPosition = new THREE.Vector3();
820
 
 
895
 
896
  const distanceToPlayer = this.position.distanceTo(playerPosition);
897
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
898
  this.aiState = 'evade';
899
  } else if (distanceToPlayer <= 3000) {
900
  this.aiState = 'combat';
 
902
  this.aiState = 'patrol';
903
  }
904
 
905
+ // ์ถฉ๋Œ ํšŒํ”ผ ๊ณ„์‚ฐ
906
+ this.calculateAvoidance();
907
+ this.checkCollisionPrediction(deltaTime);
 
 
908
 
909
  // AI ํ–‰๋™ ์‹คํ–‰
910
  switch (this.aiState) {
 
917
  case 'evade':
918
  this.executeEmergencyEvade(deltaTime);
919
  break;
 
 
 
920
  }
921
 
922
  // ๋ฌผ๋ฆฌ ์—…๋ฐ์ดํŠธ
 
926
  this.updateBullets(deltaTime);
927
  }
928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
929
  executePatrol(deltaTime) {
930
  // ๋ชฉํ‘œ ์ง€์ ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ ํ™•์ธ
931
  if (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {
 
945
  executeCombat(playerPosition, deltaTime) {
946
  const distance = this.position.distanceTo(playerPosition);
947
 
 
 
 
 
 
 
 
948
 
949
  // ํ”Œ๋ ˆ์ด์–ด๋ฅผ ํ–ฅํ•ด ํšŒ์ „
950
  this.smoothTurnToTarget(playerPosition, deltaTime);
 
958
  const isStraightFlying = isPitchLevel && isRollLevel;
959
 
960
  // ์ง์ง„ ๋น„ํ–‰ ์ค‘์ด๊ณ  ์ •ํ™•ํ•œ ์กฐ์ค€ ์‹œ์—๋งŒ ๋ฐœ์‚ฌ ๊ฐ€๋Šฅ
961
+ this.canShoot = isStraightFlying && aimAccuracy < 0.15;
 
962
 
963
  // ๋ฐœ์‚ฌ ์กฐ๊ฑด ์ถฉ์กฑ ์‹œ ๋ฐœ์‚ฌ
964
  if (this.canShoot) {
 
1062
  }
1063
 
1064
  smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {
1065
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1066
 
1067
  // ๊ธฐ์กด ๋กœ์ง (ํ›„ํ‡ด๊ฐ€ ์•„๋‹ ๋•Œ)
1068
  const direction = targetPos.clone().sub(this.position);