Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -718,729 +718,730 @@ class Fighter {
|
|
718 |
|
719 |
// ์ ์ ํฌ๊ธฐ ํด๋์ค
|
720 |
class EnemyFighter {
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
879 |
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
1311 |
-
|
1312 |
-
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
|
1317 |
-
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
|
1325 |
-
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
-
|
1330 |
-
|
1331 |
-
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
1373 |
-
|
1374 |
-
|
1375 |
-
|
1376 |
-
|
1377 |
-
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
-
|
1388 |
-
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
audio.remove();
|
1400 |
-
});
|
1401 |
-
} catch (e) {
|
1402 |
-
console.log('Audio error:', e);
|
1403 |
-
}
|
1404 |
-
}
|
1405 |
-
}
|
1406 |
-
}
|
1407 |
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
}
|
1445 |
|
1446 |
// ๋ฉ์ธ ๊ฒ์ ํด๋์ค
|
|
|
718 |
|
719 |
// ์ ์ ํฌ๊ธฐ ํด๋์ค
|
720 |
class EnemyFighter {
|
721 |
+
constructor(scene, position) {
|
722 |
+
this.mesh = null;
|
723 |
+
this.isLoaded = false;
|
724 |
+
this.scene = scene;
|
725 |
+
this.position = position.clone();
|
726 |
+
this.velocity = new THREE.Vector3(0, 0, 120);
|
727 |
+
this.rotation = new THREE.Euler(0, 0, 0);
|
728 |
+
this.health = GAME_CONSTANTS.MAX_HEALTH; // ์ฒด๋ ฅ 1000
|
729 |
+
this.speed = 386; // 750kt in m/s (750 * 0.514444) - 1000kt์์ 750kt๋ก ๊ฐ์
|
730 |
+
this.bullets = [];
|
731 |
+
this.lastShootTime = 0;
|
732 |
+
|
733 |
+
// ๊ฐ์ ๋ AI ์ํ
|
734 |
+
this.aiState = 'patrol';
|
735 |
+
this.targetPosition = this.generateRandomTarget();
|
736 |
+
this.lastDirectionChange = Date.now();
|
737 |
+
this.playerFighter = null; // ํ๋ ์ด์ด ์ฐธ์กฐ ์ ์ฅ์ฉ
|
738 |
+
|
739 |
+
// ๋ถ๋๋ฌ์ด ์ ํ๋ฅผ ์ํ ๋ณ์
|
740 |
+
this.targetRotation = new THREE.Euler(0, Math.random() * Math.PI * 2, 0);
|
741 |
+
this.turnRadius = 1500; // ์ ํ ๋ฐ๊ฒฝ
|
742 |
+
this.isTurning = false;
|
743 |
+
this.turnDirection = 1; // 1: ์ฐํ์ , -1: ์ขํ์
|
744 |
+
|
745 |
+
// ๋ค๋ฅธ ์ ๊ธฐ๋ค๊ณผ์ ์ถฉ๋ ํํผ
|
746 |
+
this.nearbyEnemies = [];
|
747 |
+
this.separationRadius = 300; // ์ต์ ๊ฑฐ๋ฆฌ 300m
|
748 |
+
|
749 |
+
// ์ ํฌ ๊ด๋ จ ๋ณ์
|
750 |
+
this.isEngaged = false; // ์ ํฌ ์ค ์ํ
|
751 |
+
this.burstCount = 0; // ํ์ฌ ์ฐ๋ฐ ์
|
752 |
+
this.lastBurstTime = 0; // ๋ง์ง๋ง ์ฐ๋ฐ ์์ ์๊ฐ
|
753 |
+
this.predictedTargetPos = new THREE.Vector3(); // ์์ธก ์ฌ๊ฒฉ ์์น
|
754 |
+
|
755 |
+
// ์๋ก์ด ํญ๊ณต์ญํ์ ๊ธฐ๋ ๋ณ์
|
756 |
+
this.maneuverState = 'straight'; // straight, turning, climbing, diving, combat_turn
|
757 |
+
this.maneuverTimer = 0;
|
758 |
+
this.nextManeuverTime = 3 + Math.random() * 4; // 3-7์ด๋ง๋ค ๊ธฐ๋ ๋ณ๊ฒฝ
|
759 |
+
|
760 |
+
// ์ ํฌ ๊ธฐ๋ ํจํด
|
761 |
+
this.combatPattern = 'approach'; // approach, attack, evade, reposition
|
762 |
+
this.combatTargetOffset = new THREE.Vector3();
|
763 |
+
this.lastAttackPosition = new THREE.Vector3();
|
764 |
+
this.evasionDirection = new THREE.Vector3();
|
765 |
+
|
766 |
+
// ๋ฌผ๋ฆฌ์ ์ ํ ์ถ๊ฐ
|
767 |
+
this.maxBankAngle = Math.PI / 3; // ์ต๋ 60๋ ๋ฑ
ํฌ
|
768 |
+
this.maxPitchRate = 1.0; // ์ด๋น ์ต๋ ํผ์น ๋ณํ์จ
|
769 |
+
this.maxRollRate = 2.0; // ์ด๋น ์ต๋ ๋กค ๋ณํ์จ
|
770 |
+
this.currentG = 1.0; // ํ์ฌ G-Force
|
771 |
+
|
772 |
+
// ์๋์ง ๊ด๋ฆฌ
|
773 |
+
this.throttle = 0.7; // ์ค๋กํ ์ ์ด
|
774 |
+
this.optimalSpeed = 386; // ์ต์ ์ ํฌ ์๋
|
775 |
+
}
|
776 |
+
|
777 |
+
generateRandomTarget() {
|
778 |
+
// ๋งต ๋ฒ์ ๋ด ๋๋ค ๋ชฉํ ์ง์ ์์ฑ
|
779 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2 * 0.8;
|
780 |
+
return new THREE.Vector3(
|
781 |
+
(Math.random() - 0.5) * 2 * mapLimit,
|
782 |
+
1000 + Math.random() * 3000, // 1000m ~ 4000m ๊ณ ๋
|
783 |
+
(Math.random() - 0.5) * 2 * mapLimit
|
784 |
+
);
|
785 |
+
}
|
786 |
+
|
787 |
+
// ์๋ก์ด ๋ฉ์๋: ์์ฐ์ค๋ฌ์ด ๊ธฐ๋ ์ ํ
|
788 |
+
selectNewManeuver() {
|
789 |
+
const maneuvers = ['straight', 'turning_left', 'turning_right', 'climbing', 'diving', 'barrel_roll'];
|
790 |
+
const weights = [0.3, 0.2, 0.2, 0.15, 0.1, 0.05]; // ๊ฐ ๊ธฐ๋์ ํ๋ฅ
|
791 |
+
|
792 |
+
let random = Math.random();
|
793 |
+
let accumulator = 0;
|
794 |
+
|
795 |
+
for (let i = 0; i < maneuvers.length; i++) {
|
796 |
+
accumulator += weights[i];
|
797 |
+
if (random <= accumulator) {
|
798 |
+
this.maneuverState = maneuvers[i];
|
799 |
+
break;
|
800 |
+
}
|
801 |
+
}
|
802 |
+
|
803 |
+
// ๊ธฐ๋ ์ง์ ์๊ฐ ์ค์
|
804 |
+
switch (this.maneuverState) {
|
805 |
+
case 'straight':
|
806 |
+
this.maneuverTimer = 2 + Math.random() * 3;
|
807 |
+
break;
|
808 |
+
case 'turning_left':
|
809 |
+
case 'turning_right':
|
810 |
+
this.maneuverTimer = 3 + Math.random() * 4;
|
811 |
+
this.turnDirection = this.maneuverState === 'turning_left' ? -1 : 1;
|
812 |
+
break;
|
813 |
+
case 'climbing':
|
814 |
+
case 'diving':
|
815 |
+
this.maneuverTimer = 2 + Math.random() * 2;
|
816 |
+
break;
|
817 |
+
case 'barrel_roll':
|
818 |
+
this.maneuverTimer = 4;
|
819 |
+
break;
|
820 |
+
}
|
821 |
+
}
|
822 |
+
|
823 |
+
// ์๋ก์ด ๋ฉ์๋: ์ ํฌ ๊ธฐ๋ ํจํด ์ ํ
|
824 |
+
selectCombatPattern(playerPosition, distance) {
|
825 |
+
const angleToPlayer = this.getAngleToTarget(playerPosition);
|
826 |
+
|
827 |
+
if (this.combatPattern === 'approach' && distance < 2000) {
|
828 |
+
// ์ ๊ทผ ์๋ฃ, ๊ณต๊ฒฉ ํจํด์ผ๋ก ์ ํ
|
829 |
+
this.combatPattern = 'attack';
|
830 |
+
this.lastAttackPosition = this.position.clone();
|
831 |
+
} else if (this.combatPattern === 'attack' && distance < 500) {
|
832 |
+
// ๋๋ฌด ๊ฐ๊น์, ํํผ ๊ธฐ๋
|
833 |
+
this.combatPattern = 'evade';
|
834 |
+
this.evasionDirection = new THREE.Vector3(
|
835 |
+
Math.random() - 0.5,
|
836 |
+
Math.random() * 0.5,
|
837 |
+
Math.random() - 0.5
|
838 |
+
).normalize();
|
839 |
+
} else if (this.combatPattern === 'evade' && distance > 1500) {
|
840 |
+
// ์์ ๊ฑฐ๋ฆฌ ํ๋ณด, ์ฌ์์น ์ ์
|
841 |
+
this.combatPattern = 'reposition';
|
842 |
+
} else if (this.combatPattern === 'reposition' && distance > 1000 && distance < 3000) {
|
843 |
+
// ์ฌ์์น ์๋ฃ, ๋ค์ ์ ๊ทผ
|
844 |
+
this.combatPattern = 'approach';
|
845 |
+
}
|
846 |
+
|
847 |
+
// ๊ณต๊ฒฉ ์์น ์คํ์
๊ณ์ฐ (ํ๋ ์ด์ด ์ฃผ๋ณ 300m ๋ฐ๊ฒฝ)
|
848 |
+
if (this.combatPattern === 'reposition' || this.combatPattern === 'approach') {
|
849 |
+
const offsetAngle = Math.random() * Math.PI * 2;
|
850 |
+
const offsetDistance = 200 + Math.random() * 100; // 200-300m
|
851 |
+
this.combatTargetOffset = new THREE.Vector3(
|
852 |
+
Math.cos(offsetAngle) * offsetDistance,
|
853 |
+
(Math.random() - 0.5) * 100,
|
854 |
+
Math.sin(offsetAngle) * offsetDistance
|
855 |
+
);
|
856 |
+
}
|
857 |
+
}
|
858 |
+
|
859 |
+
// ์๋ก์ด ๋ฉ์๋: ํ๊ฒ๊น์ง์ ๊ฐ๋ ๊ณ์ฐ
|
860 |
+
getAngleToTarget(targetPosition) {
|
861 |
+
const toTarget = targetPosition.clone().sub(this.position).normalize();
|
862 |
+
const forward = new THREE.Vector3(0, 0, 1).applyEuler(this.rotation);
|
863 |
+
return Math.acos(Math.max(-1, Math.min(1, forward.dot(toTarget))));
|
864 |
+
}
|
865 |
+
async initialize(loader) {
|
866 |
+
try {
|
867 |
+
const result = await loader.loadAsync('models/mig-29.glb');
|
868 |
+
this.mesh = result.scene;
|
869 |
+
this.mesh.position.copy(this.position);
|
870 |
+
this.mesh.scale.set(1.5, 1.5, 1.5);
|
871 |
+
this.mesh.rotation.y = 3 * Math.PI / 2;
|
872 |
+
|
873 |
+
this.mesh.traverse((child) => {
|
874 |
+
if (child.isMesh) {
|
875 |
+
child.castShadow = true;
|
876 |
+
child.receiveShadow = true;
|
877 |
+
}
|
878 |
+
});
|
879 |
+
|
880 |
+
this.scene.add(this.mesh);
|
881 |
+
this.isLoaded = true;
|
882 |
+
console.log('MiG-29 ์ ๊ธฐ ๋ก๋ฉ ์๋ฃ');
|
883 |
+
} catch (error) {
|
884 |
+
console.error('MiG-29 ๋ชจ๋ธ ๋ก๋ฉ ์คํจ:', error);
|
885 |
+
this.createFallbackModel();
|
886 |
+
}
|
887 |
+
}
|
888 |
|
889 |
+
createFallbackModel() {
|
890 |
+
const group = new THREE.Group();
|
891 |
+
|
892 |
+
const fuselageGeometry = new THREE.CylinderGeometry(0.6, 1.0, 8, 8);
|
893 |
+
const fuselageMaterial = new THREE.MeshLambertMaterial({ color: 0x800000 });
|
894 |
+
const fuselage = new THREE.Mesh(fuselageGeometry, fuselageMaterial);
|
895 |
+
fuselage.rotation.x = -Math.PI / 2;
|
896 |
+
group.add(fuselage);
|
897 |
+
|
898 |
+
const wingGeometry = new THREE.BoxGeometry(12, 0.3, 3);
|
899 |
+
const wingMaterial = new THREE.MeshLambertMaterial({ color: 0x600000 });
|
900 |
+
const wings = new THREE.Mesh(wingGeometry, wingMaterial);
|
901 |
+
wings.position.z = -0.5;
|
902 |
+
group.add(wings);
|
903 |
+
|
904 |
+
this.mesh = group;
|
905 |
+
this.mesh.position.copy(this.position);
|
906 |
+
this.mesh.scale.set(1.5, 1.5, 1.5);
|
907 |
+
this.scene.add(this.mesh);
|
908 |
+
this.isLoaded = true;
|
909 |
+
|
910 |
+
console.log('Fallback ์ ๊ธฐ ๋ชจ๋ธ ์์ฑ ์๋ฃ');
|
911 |
+
}
|
912 |
|
913 |
+
update(playerPosition, deltaTime) {
|
914 |
+
if (!this.mesh) return;
|
915 |
+
|
916 |
+
// AI ์ํ ์
๋ฐ์ดํธ
|
917 |
+
const distanceToPlayer = this.position.distanceTo(playerPosition);
|
918 |
+
|
919 |
+
// ์ ํฌ ๊ฑฐ๋ฆฌ ์ฒดํฌ (3000m ์ด๋ด)
|
920 |
+
if (distanceToPlayer < 3000) {
|
921 |
+
this.aiState = 'combat';
|
922 |
+
this.isEngaged = true;
|
923 |
+
this.targetPosition = playerPosition.clone();
|
924 |
+
} else if (distanceToPlayer > 5000) {
|
925 |
+
this.aiState = 'patrol';
|
926 |
+
this.isEngaged = false;
|
927 |
+
this.combatPattern = 'approach'; // ์ ํฌ ํจํด ๋ฆฌ์
|
928 |
+
}
|
929 |
+
|
930 |
+
// ๋ค๋ฅธ ์ ๊ธฐ์์ ์ถฉ๋ ํํผ
|
931 |
+
this.avoidOtherEnemies(deltaTime);
|
932 |
+
|
933 |
+
// ๊ธฐ๋ ํ์ด๋จธ ์
๋ฐ์ดํธ
|
934 |
+
this.maneuverTimer -= deltaTime;
|
935 |
+
if (this.maneuverTimer <= 0 && this.aiState === 'patrol') {
|
936 |
+
this.selectNewManeuver();
|
937 |
+
}
|
938 |
+
|
939 |
+
// AI ํ๋ ์คํ
|
940 |
+
switch (this.aiState) {
|
941 |
+
case 'patrol':
|
942 |
+
this.patrol(deltaTime);
|
943 |
+
break;
|
944 |
+
case 'combat':
|
945 |
+
this.combat(playerPosition, deltaTime);
|
946 |
+
break;
|
947 |
+
}
|
948 |
+
|
949 |
+
// ๋ฌผ๋ฆฌ ์
๋ฐ์ดํธ
|
950 |
+
this.updatePhysics(deltaTime);
|
951 |
+
|
952 |
+
// ํํ ์
๋ฐ์ดํธ
|
953 |
+
this.updateBullets(deltaTime);
|
954 |
+
}
|
955 |
+
|
956 |
+
avoidOtherEnemies(deltaTime) {
|
957 |
+
if (!this.nearbyEnemies) return;
|
958 |
+
|
959 |
+
let closestDistance = Infinity;
|
960 |
+
let avoidanceNeeded = false;
|
961 |
+
let avoidDirection = new THREE.Vector3();
|
962 |
+
|
963 |
+
this.nearbyEnemies.forEach(enemy => {
|
964 |
+
if (enemy === this || !enemy.position) return;
|
965 |
+
|
966 |
+
const distance = this.position.distanceTo(enemy.position);
|
967 |
+
if (distance < this.separationRadius && distance > 0) {
|
968 |
+
avoidanceNeeded = true;
|
969 |
+
if (distance < closestDistance) {
|
970 |
+
closestDistance = distance;
|
971 |
+
// ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ํํผ
|
972 |
+
avoidDirection = this.position.clone().sub(enemy.position).normalize();
|
973 |
+
}
|
974 |
+
}
|
975 |
+
});
|
976 |
+
|
977 |
+
if (avoidanceNeeded) {
|
978 |
+
// ๊ธด๊ธ ํํผ: ๊ธ์ ํ
|
979 |
+
const avoidAngle = Math.atan2(avoidDirection.x, avoidDirection.z);
|
980 |
+
this.targetRotation.y = avoidAngle;
|
981 |
+
this.isTurning = true;
|
982 |
+
|
983 |
+
// ๊ณ ๋๋ ๋ณ๊ฒฝ (๋ ๋ถ๋๋ฝ๊ฒ)
|
984 |
+
if (avoidDirection.y > 0) {
|
985 |
+
this.targetRotation.x = -0.15;
|
986 |
+
} else {
|
987 |
+
this.targetRotation.x = 0.15;
|
988 |
+
}
|
989 |
+
}
|
990 |
+
}
|
991 |
+
|
992 |
+
patrol(deltaTime) {
|
993 |
+
// ์์ฐ์ค๋ฌ์ด ๊ธฐ๋ ์คํ
|
994 |
+
switch (this.maneuverState) {
|
995 |
+
case 'straight':
|
996 |
+
// ์ง์ง ๋นํ
|
997 |
+
this.targetRotation.x = 0;
|
998 |
+
this.targetRotation.z = 0;
|
999 |
+
|
1000 |
+
// ๋ชฉํ ์ง์ ์ ํฅํด ์ฒ์ฒํ ๋ฐฉํฅ ์กฐ์
|
1001 |
+
const dirToTarget = this.targetPosition.clone().sub(this.position);
|
1002 |
+
if (dirToTarget.length() > 0) {
|
1003 |
+
dirToTarget.normalize();
|
1004 |
+
const targetYaw = Math.atan2(dirToTarget.x, dirToTarget.z);
|
1005 |
+
const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
|
1006 |
+
this.targetRotation.y = this.rotation.y + yawDiff * deltaTime * 0.8;
|
1007 |
+
}
|
1008 |
+
break;
|
1009 |
+
|
1010 |
+
case 'turning_left':
|
1011 |
+
case 'turning_right':
|
1012 |
+
// ๋ฑ
ํฌ ํด ์คํ
|
1013 |
+
const bankAngle = this.turnDirection * Math.PI / 4; // 45๋ ๋ฑ
ํฌ
|
1014 |
+
this.targetRotation.z = bankAngle;
|
1015 |
+
this.targetRotation.y += this.turnDirection * deltaTime * 0.8;
|
1016 |
+
|
1017 |
+
// ํด ์ค ์ฝ๊ฐ์ ๊ธฐ์ ํ๊ฐ
|
1018 |
+
this.targetRotation.x = 0.1;
|
1019 |
+
break;
|
1020 |
+
|
1021 |
+
case 'climbing':
|
1022 |
+
// ์์น
|
1023 |
+
this.targetRotation.x = -Math.PI / 6; // 30๋ ์์น
|
1024 |
+
this.targetRotation.z = 0;
|
1025 |
+
this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.3);
|
1026 |
+
break;
|
1027 |
+
|
1028 |
+
case 'diving':
|
1029 |
+
// ํ๊ฐ
|
1030 |
+
this.targetRotation.x = Math.PI / 8; // 22.5๋ ํ๊ฐ
|
1031 |
+
this.targetRotation.z = 0;
|
1032 |
+
this.throttle = Math.max(0.5, this.throttle - deltaTime * 0.2);
|
1033 |
+
break;
|
1034 |
+
|
1035 |
+
case 'barrel_roll':
|
1036 |
+
// ๋ฐฐ๋ด ๋กค
|
1037 |
+
const rollProgress = (4 - this.maneuverTimer) / 4;
|
1038 |
+
this.targetRotation.z = Math.sin(rollProgress * Math.PI * 4) * Math.PI / 2;
|
1039 |
+
this.targetRotation.x = Math.sin(rollProgress * Math.PI * 2) * 0.2;
|
1040 |
+
break;
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
// ๋ชฉํ ์ง์ ์ ๋๋ฌํ๋์ง ํ์ธ
|
1044 |
+
const distanceToTarget = this.position.distanceTo(this.targetPosition);
|
1045 |
+
if (distanceToTarget < 500) {
|
1046 |
+
// ์๋ก์ด ๋ชฉํ ์์ฑ
|
1047 |
+
this.targetPosition = this.generateRandomTarget();
|
1048 |
+
this.selectNewManeuver();
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
// ๊ณ ๋ ์กฐ์
|
1052 |
+
const altitudeDiff = this.targetPosition.y - this.position.y;
|
1053 |
+
if (Math.abs(altitudeDiff) > 200 && this.maneuverState === 'straight') {
|
1054 |
+
if (altitudeDiff > 0) {
|
1055 |
+
this.targetRotation.x = Math.max(-0.3, Math.min(0, altitudeDiff * 0.0001));
|
1056 |
+
} else {
|
1057 |
+
this.targetRotation.x = Math.min(0.3, Math.max(0, altitudeDiff * 0.0001));
|
1058 |
+
}
|
1059 |
+
}
|
1060 |
+
|
1061 |
+
// ์๋ ๊ด๋ฆฌ
|
1062 |
+
this.updateSpeedControl(deltaTime);
|
1063 |
+
}
|
1064 |
+
|
1065 |
+
combat(playerPosition, deltaTime) {
|
1066 |
+
const distance = this.position.distanceTo(playerPosition);
|
1067 |
+
|
1068 |
+
// ์ ํฌ ํจํด ์
๋ฐ์ดํธ
|
1069 |
+
this.selectCombatPattern(playerPosition, distance);
|
1070 |
+
|
1071 |
+
// ์ ํฌ ํจํด๋ณ ๊ธฐ๋
|
1072 |
+
switch (this.combatPattern) {
|
1073 |
+
case 'approach':
|
1074 |
+
// ํ๋ ์ด์ด ๊ทผ์ฒ ๋ชฉํ์ ์ผ๋ก ์ ๊ทผ
|
1075 |
+
const approachTarget = playerPosition.clone().add(this.combatTargetOffset);
|
1076 |
+
this.executeInterceptCourse(approachTarget, deltaTime);
|
1077 |
+
|
1078 |
+
// ์๋์ง ๊ด๋ฆฌ - ์๋ ์ ์ง
|
1079 |
+
this.throttle = 0.8;
|
1080 |
+
break;
|
1081 |
+
|
1082 |
+
case 'attack':
|
1083 |
+
// ์์ธก ์ฌ๊ฒฉ์ ์ํ ๋ฆฌ๋ ๊ณ์ฐ
|
1084 |
+
if (this.playerFighter && this.playerFighter.velocity) {
|
1085 |
+
const bulletTravelTime = distance / 1200;
|
1086 |
+
this.predictedTargetPos = playerPosition.clone().add(
|
1087 |
+
this.playerFighter.velocity.clone().multiplyScalar(bulletTravelTime * 0.7)
|
1088 |
+
);
|
1089 |
+
} else {
|
1090 |
+
this.predictedTargetPos = playerPosition.clone();
|
1091 |
+
}
|
1092 |
+
|
1093 |
+
// ๊ณต๊ฒฉ ์์ธ ์ ์ง
|
1094 |
+
this.executeAttackRun(this.predictedTargetPos, deltaTime);
|
1095 |
+
|
1096 |
+
// ์ฌ๊ฒฉ ํ๋จ
|
1097 |
+
const aimAccuracy = this.calculateAimAccuracy(this.predictedTargetPos);
|
1098 |
+
if (distance < 1500 && aimAccuracy < 0.15) {
|
1099 |
+
this.fireWeapon();
|
1100 |
+
}
|
1101 |
+
break;
|
1102 |
+
|
1103 |
+
case 'evade':
|
1104 |
+
// ํํผ ๊ธฐ๋ - ๋ธ๋ ์ดํฌ ํด ๋๋ ๋ฐฐ๋ด ๋กค
|
1105 |
+
this.executeEvasiveManeuver(deltaTime);
|
1106 |
+
break;
|
1107 |
+
|
1108 |
+
case 'reposition':
|
1109 |
+
// ์ฌ์์น - ๊ณ ๋์ ์๋ ์ด์ ํ๋ณด
|
1110 |
+
const repositionTarget = playerPosition.clone();
|
1111 |
+
repositionTarget.y += 500 + Math.random() * 1000; // ์์์ ๊ณต๊ฒฉ
|
1112 |
+
repositionTarget.add(this.combatTargetOffset);
|
1113 |
+
|
1114 |
+
this.executeInterceptCourse(repositionTarget, deltaTime);
|
1115 |
+
|
1116 |
+
// ์๋ ํ๋ณต
|
1117 |
+
this.throttle = 0.9;
|
1118 |
+
break;
|
1119 |
+
}
|
1120 |
+
|
1121 |
+
// ์๋ ๊ด๋ฆฌ
|
1122 |
+
this.updateSpeedControl(deltaTime);
|
1123 |
+
}
|
1124 |
+
|
1125 |
+
// ์๊ฒฉ ์ฝ์ค ์คํ
|
1126 |
+
executeInterceptCourse(target, deltaTime) {
|
1127 |
+
const toTarget = target.clone().sub(this.position);
|
1128 |
+
const distance = toTarget.length();
|
1129 |
+
|
1130 |
+
if (distance > 0) {
|
1131 |
+
toTarget.normalize();
|
1132 |
+
|
1133 |
+
// ๋ฆฌ๋ ํด - ๋ชฉํ์ ๋ฏธ๋ ์์น๋ฅผ ์์ธกํ์ฌ ์ ํ
|
1134 |
+
const targetYaw = Math.atan2(toTarget.x, toTarget.z);
|
1135 |
+
const targetPitch = Math.asin(-toTarget.y);
|
1136 |
+
|
1137 |
+
// ๋ถ๋๋ฌ์ด ์ ํ๋ฅผ ์ํ ๊ฐ๋ ์ฐจ์ด ๊ณ์ฐ
|
1138 |
+
const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
|
1139 |
+
const pitchDiff = targetPitch - this.rotation.x;
|
1140 |
+
|
1141 |
+
// ๋ฑ
ํฌ ๊ฐ๋๋ฅผ ์ด์ฉํ ์์ฐ์ค๋ฌ์ด ์ ํ
|
1142 |
+
if (Math.abs(yawDiff) > 0.1) {
|
1143 |
+
// ์ ํ์ ์ ๋ฐ๋ฅธ ๋กค ์ ์ฉ
|
1144 |
+
this.targetRotation.z = Math.max(-this.maxBankAngle,
|
1145 |
+
Math.min(this.maxBankAngle, -yawDiff * 1.5));
|
1146 |
+
} else {
|
1147 |
+
this.targetRotation.z *= 0.9; // ๋กค ๋ณต๊ท
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
// ๋ชฉํ ๋ฐฉํฅ์ผ๋ก ํ์
|
1151 |
+
this.targetRotation.y = this.rotation.y + yawDiff * deltaTime * 1.0;
|
1152 |
+
this.targetRotation.x = this.rotation.x + pitchDiff * deltaTime * 0.6;
|
1153 |
+
|
1154 |
+
// ํผ์น ์ ํ
|
1155 |
+
this.targetRotation.x = Math.max(-Math.PI / 4, Math.min(Math.PI / 4, this.targetRotation.x));
|
1156 |
+
}
|
1157 |
+
}
|
1158 |
+
|
1159 |
+
// ๊ณต๊ฒฉ ์ง์
|
1160 |
+
executeAttackRun(target, deltaTime) {
|
1161 |
+
const toTarget = target.clone().sub(this.position);
|
1162 |
+
const distance = toTarget.length();
|
1163 |
+
|
1164 |
+
if (distance > 0) {
|
1165 |
+
toTarget.normalize();
|
1166 |
+
const targetYaw = Math.atan2(toTarget.x, toTarget.z);
|
1167 |
+
const targetPitch = Math.asin(-toTarget.y);
|
1168 |
+
|
1169 |
+
// ์ ๋ฐ ์กฐ์ค์ ์ํ ์์ ์์
|
1170 |
+
const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
|
1171 |
+
const pitchDiff = targetPitch - this.rotation.x;
|
1172 |
+
|
1173 |
+
// ์์ ์ ์ธ ์ฌ๊ฒฉ ์์ธ ์ ์ง
|
1174 |
+
this.targetRotation.y = this.rotation.y + yawDiff * deltaTime * 1.5;
|
1175 |
+
this.targetRotation.x = this.rotation.x + pitchDiff * deltaTime * 1.0;
|
1176 |
+
this.targetRotation.z = -yawDiff * 0.3;
|
1177 |
+
|
1178 |
+
// ์๋ ์กฐ์ - ๋ชฉํ์์ ์๋ ์๋ ๊ด๋ฆฌ
|
1179 |
+
if (distance < 800) {
|
1180 |
+
this.throttle = 0.6; // ๊ฐ์
|
1181 |
+
} else {
|
1182 |
+
this.throttle = 0.85;
|
1183 |
+
}
|
1184 |
+
}
|
1185 |
+
}
|
1186 |
+
|
1187 |
+
// ํํผ ๊ธฐ๋
|
1188 |
+
executeEvasiveManeuver(deltaTime) {
|
1189 |
+
// ๋ธ๋ ์ดํฌ ํด ๋๋ ์คํ๋ฆฟ-S
|
1190 |
+
const evasiveType = Math.random() > 0.5 ? 'break' : 'split_s';
|
1191 |
+
|
1192 |
+
if (evasiveType === 'break') {
|
1193 |
+
// ๊ธ๊ฒฉํ ๋ธ๋ ์ดํฌ ํด
|
1194 |
+
this.targetRotation.z = this.evasionDirection.x * this.maxBankAngle * 1.2;
|
1195 |
+
this.targetRotation.y += this.evasionDirection.x * deltaTime * 3.0;
|
1196 |
+
this.targetRotation.x = 0.2; // ์ฝ๊ฐ์ ๊ธฐ์ ํ๊ฐ
|
1197 |
+
this.throttle = 0.4; // ๊ธ๊ฐ์
|
1198 |
+
} else {
|
1199 |
+
// ์คํ๋ฆฟ-S (๋ฐ์ ํ๊ฐ)
|
1200 |
+
this.targetRotation.z += deltaTime * 4.0; // ๋น ๋ฅธ ๋กค
|
1201 |
+
if (Math.abs(this.rotation.z) > Math.PI * 0.8) {
|
1202 |
+
this.targetRotation.x = Math.PI / 3; // ๊ธํ๊ฐ
|
1203 |
+
}
|
1204 |
+
this.throttle = 0.3;
|
1205 |
+
}
|
1206 |
+
|
1207 |
+
// G-Force ์๋ฎฌ๋ ์ด์
|
1208 |
+
this.currentG = 3.0 + Math.abs(this.rotation.z) * 2;
|
1209 |
+
}
|
1210 |
+
|
1211 |
+
// ์กฐ์ค ์ ํ๋ ๊ณ์ฐ
|
1212 |
+
calculateAimAccuracy(target) {
|
1213 |
+
const toTarget = target.clone().sub(this.position).normalize();
|
1214 |
+
const forward = new THREE.Vector3(0, 0, 1).applyEuler(this.rotation);
|
1215 |
+
|
1216 |
+
const dotProduct = forward.dot(toTarget);
|
1217 |
+
const angle = Math.acos(Math.max(-1, Math.min(1, dotProduct)));
|
1218 |
+
|
1219 |
+
return angle;
|
1220 |
+
}
|
1221 |
+
|
1222 |
+
// ๋ฌด๊ธฐ ๋ฐ์ฌ
|
1223 |
+
fireWeapon() {
|
1224 |
+
const now = Date.now();
|
1225 |
+
if (now - this.lastBurstTime > 2000) {
|
1226 |
+
this.burstCount = 0;
|
1227 |
+
this.lastBurstTime = now;
|
1228 |
+
}
|
1229 |
+
|
1230 |
+
if (this.burstCount < 5 && now - this.lastShootTime > 200) {
|
1231 |
+
this.shoot();
|
1232 |
+
this.burstCount++;
|
1233 |
+
}
|
1234 |
+
}
|
1235 |
+
|
1236 |
+
// ์๋ ์ ์ด
|
1237 |
+
updateSpeedControl(deltaTime) {
|
1238 |
+
// ๋ชฉํ ์๋ ๊ณ์ฐ
|
1239 |
+
let targetSpeed = this.optimalSpeed * this.throttle;
|
1240 |
+
|
1241 |
+
// ๊ณ ๋์ ๋ฐ๋ฅธ ์๋ ๋ณด์
|
1242 |
+
const altitudeFactor = 1 + (this.position.y / 10000) * 0.2;
|
1243 |
+
targetSpeed *= altitudeFactor;
|
1244 |
+
|
1245 |
+
// ๊ธฐ๋์ ๋ฐ๋ฅธ ์๋ ์์ค
|
1246 |
+
if (this.currentG > 2.0) {
|
1247 |
+
targetSpeed *= (1 - (this.currentG - 2.0) * 0.05);
|
1248 |
+
}
|
1249 |
+
|
1250 |
+
// ๋ถ๋๋ฌ์ด ์๋ ๋ณํ
|
1251 |
+
this.speed = THREE.MathUtils.lerp(this.speed, targetSpeed, deltaTime * 0.5);
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
// ๊ฐ๋ ์ ๊ทํ ํฌํผ ๋ฉ์๋
|
1255 |
+
normalizeAngle(angle) {
|
1256 |
+
while (angle > Math.PI) angle -= Math.PI * 2;
|
1257 |
+
while (angle < -Math.PI) angle += Math.PI * 2;
|
1258 |
+
return angle;
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
updatePhysics(deltaTime) {
|
1262 |
+
if (!this.mesh) return;
|
1263 |
+
|
1264 |
+
// ๋ถ๋๋ฌ์ด ํ์ ์ ์ฉ - ํญ๊ณต์ญํ์ ์ ํ ์ ์ฉ
|
1265 |
+
const rotationSpeed = deltaTime * 2.0;
|
1266 |
+
const rollSpeed = deltaTime * this.maxRollRate;
|
1267 |
+
const pitchSpeed = deltaTime * this.maxPitchRate;
|
1268 |
+
|
1269 |
+
// ๊ฐ ์ถ๋ณ๋ก ๋ค๋ฅธ ์๋๋ก ํ์
|
1270 |
+
this.rotation.x = THREE.MathUtils.lerp(this.rotation.x, this.targetRotation.x, pitchSpeed);
|
1271 |
+
this.rotation.y = THREE.MathUtils.lerp(this.rotation.y, this.targetRotation.y, rotationSpeed);
|
1272 |
+
this.rotation.z = THREE.MathUtils.lerp(this.rotation.z, this.targetRotation.z, rollSpeed);
|
1273 |
+
|
1274 |
+
// G-Force ๊ณ์ฐ
|
1275 |
+
const turnRate = Math.abs(this.targetRotation.y - this.rotation.y) * 10;
|
1276 |
+
const pitchRate = Math.abs(this.targetRotation.x - this.rotation.x) * 10;
|
1277 |
+
this.currentG = 1.0 + turnRate + pitchRate + Math.abs(this.rotation.z) * 2;
|
1278 |
+
|
1279 |
+
// ์๋ ๋ฒกํฐ ๊ณ์ฐ - ์ค์ ํญ๊ณต๊ธฐ์ฒ๋ผ ๊ธฐ์ ๋ฐฉํฅ์ผ๋ก
|
1280 |
+
const forward = new THREE.Vector3(0, 0, 1);
|
1281 |
+
forward.applyEuler(this.rotation);
|
1282 |
+
|
1283 |
+
// ์ ์ง ์๋ ์ ์ฉ
|
1284 |
+
this.velocity = forward.multiplyScalar(this.speed);
|
1285 |
+
|
1286 |
+
// ๋ฑ
ํฌ ๊ฐ๋์ ๋ฐ๋ฅธ ์ ํ๋ ฅ
|
1287 |
+
if (Math.abs(this.rotation.z) > 0.1) {
|
1288 |
+
const lift = new THREE.Vector3(0, 1, 0);
|
1289 |
+
lift.applyEuler(this.rotation);
|
1290 |
+
const turnForce = Math.sin(this.rotation.z) * this.currentG * 30;
|
1291 |
+
this.velocity.add(lift.multiplyScalar(turnForce * deltaTime));
|
1292 |
+
}
|
1293 |
+
|
1294 |
+
// ์ค๋ ฅ ํจ๊ณผ
|
1295 |
+
const gravity = GAME_CONSTANTS.GRAVITY * deltaTime;
|
1296 |
+
this.velocity.y -= gravity;
|
1297 |
+
|
1298 |
+
// ์๋ ฅ ๊ณ์ฐ (์๋์ ๋น๋ก)
|
1299 |
+
const liftFactor = (this.speed / this.optimalSpeed) * 0.8;
|
1300 |
+
const lift = gravity * liftFactor * Math.cos(this.rotation.x);
|
1301 |
+
this.velocity.y += lift;
|
1302 |
+
|
1303 |
+
// ํญ๋ ฅ (๋๋๊ทธ)
|
1304 |
+
const dragFactor = 0.02 + Math.abs(this.rotation.x) * 0.01;
|
1305 |
+
this.velocity.multiplyScalar(1 - dragFactor * deltaTime);
|
1306 |
+
|
1307 |
+
// ์์น ์
๋ฐ์ดํธ
|
1308 |
+
this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
|
1309 |
+
|
1310 |
+
// ๊ณ ๋ ์ ํ
|
1311 |
+
if (this.position.y < 300) {
|
1312 |
+
this.position.y = 300;
|
1313 |
+
this.velocity.y = Math.max(0, this.velocity.y);
|
1314 |
+
this.targetRotation.x = -0.3; // ๊ฐ์ ์์น
|
1315 |
+
} else if (this.position.y > 8000) {
|
1316 |
+
this.position.y = 8000;
|
1317 |
+
this.velocity.y = Math.min(0, this.velocity.y);
|
1318 |
+
this.targetRotation.x = 0.2; // ํ๊ฐ
|
1319 |
+
}
|
1320 |
+
|
1321 |
+
// ๋งต ๊ฒฝ๊ณ ์ฒ๋ฆฌ - ๋ถ๋๋ฌ์ด ํ๊ท
|
1322 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
1323 |
+
const boundaryBuffer = mapLimit * 0.9;
|
1324 |
+
|
1325 |
+
if (Math.abs(this.position.x) > boundaryBuffer || Math.abs(this.position.z) > boundaryBuffer) {
|
1326 |
+
// ๋งต ์ค์์ ํฅํด ์์ฐ์ค๋ฝ๊ฒ ํ์
|
1327 |
+
const centerDirection = new THREE.Vector3(-this.position.x, 0, -this.position.z).normalize();
|
1328 |
+
const targetYaw = Math.atan2(centerDirection.x, centerDirection.z);
|
1329 |
+
this.targetRotation.y = targetYaw;
|
1330 |
+
|
1331 |
+
// ๊ฒฝ๊ณ์์ ๋ฑ
ํฌ ํด
|
1332 |
+
if (this.position.x > boundaryBuffer) {
|
1333 |
+
this.targetRotation.z = -this.maxBankAngle;
|
1334 |
+
} else if (this.position.x < -boundaryBuffer) {
|
1335 |
+
this.targetRotation.z = this.maxBankAngle;
|
1336 |
+
}
|
1337 |
+
}
|
1338 |
+
|
1339 |
+
// ํ๋ ๋ฆฌ๋ฏธํธ
|
1340 |
+
if (this.position.x > mapLimit) this.position.x = mapLimit;
|
1341 |
+
if (this.position.x < -mapLimit) this.position.x = -mapLimit;
|
1342 |
+
if (this.position.z > mapLimit) this.position.z = mapLimit;
|
1343 |
+
if (this.position.z < -mapLimit) this.position.z = -mapLimit;
|
1344 |
+
|
1345 |
+
// ๋ฉ์ ์
๋ฐ์ดํธ
|
1346 |
+
this.mesh.position.copy(this.position);
|
1347 |
+
this.mesh.rotation.x = this.rotation.x;
|
1348 |
+
this.mesh.rotation.y = this.rotation.y + Math.PI;
|
1349 |
+
this.mesh.rotation.z = this.rotation.z;
|
1350 |
+
|
1351 |
+
// ์๋ ๋กค ๋ณต๊ท (์ ํฌ ์ค์ด ์๋ ๋)
|
1352 |
+
if (!this.isEngaged && Math.abs(this.targetRotation.z) > 0.01) {
|
1353 |
+
this.targetRotation.z *= 0.95;
|
1354 |
+
}
|
1355 |
+
}
|
1356 |
+
|
1357 |
+
shoot() {
|
1358 |
+
this.lastShootTime = Date.now();
|
1359 |
+
|
1360 |
+
// ์ง์ ๋ชจ์์ ํํ (100% ๋ ํฌ๊ฒ)
|
1361 |
+
const bulletGeometry = new THREE.CylinderGeometry(0.8, 0.8, 12, 8);
|
1362 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
1363 |
+
color: 0xff0000,
|
1364 |
+
emissive: 0xff0000,
|
1365 |
+
emissiveIntensity: 1.0
|
1366 |
+
});
|
1367 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
1368 |
+
|
1369 |
+
// ๊ธฐ์ ๋์์ ๋ฐ์ฌ
|
1370 |
+
const muzzleOffset = new THREE.Vector3(0, 0, 12);
|
1371 |
+
muzzleOffset.applyEuler(this.rotation);
|
1372 |
+
bullet.position.copy(this.position).add(muzzleOffset);
|
1373 |
+
|
1374 |
+
// ํํ์ ๋ฐ์ฌ ๋ฐฉํฅ์ผ๋ก ํ์
|
1375 |
+
bullet.rotation.copy(this.rotation);
|
1376 |
+
bullet.rotateX(Math.PI / 2);
|
1377 |
+
|
1378 |
+
const direction = new THREE.Vector3(0, 0, 1);
|
1379 |
+
direction.applyEuler(this.rotation);
|
1380 |
+
bullet.velocity = direction.multiplyScalar(1200);
|
1381 |
+
|
1382 |
+
this.scene.add(bullet);
|
1383 |
+
this.bullets.push(bullet);
|
1384 |
+
|
1385 |
+
// MGLAUNCH.ogg ์๋ฆฌ ์ฌ์ - ํ๋ ์ด์ด๊ฐ 3000m ์ด๋ด์ ์์ ๋๋ง
|
1386 |
+
if (this.playerFighter) {
|
1387 |
+
const distanceToPlayer = this.position.distanceTo(this.playerFighter.position);
|
1388 |
+
if (distanceToPlayer < 3000) {
|
1389 |
+
try {
|
1390 |
+
const audio = new Audio('sounds/MGLAUNCH.ogg');
|
1391 |
+
audio.volume = 0.5;
|
1392 |
+
|
1393 |
+
// ๊ฑฐ๋ฆฌ์ ๋ฐ๋ฅธ ์๋ ์กฐ์
|
1394 |
+
const volumeMultiplier = 1 - (distanceToPlayer / 3000);
|
1395 |
+
audio.volume = 0.5 * volumeMultiplier;
|
1396 |
+
|
1397 |
+
audio.play().catch(e => console.log('Enemy gunfire sound failed to play'));
|
1398 |
+
|
1399 |
+
audio.addEventListener('ended', () => {
|
1400 |
+
audio.remove();
|
1401 |
+
});
|
1402 |
+
} catch (e) {
|
1403 |
+
console.log('Audio error:', e);
|
1404 |
+
}
|
1405 |
+
}
|
1406 |
+
}
|
1407 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1408 |
|
1409 |
+
updateBullets(deltaTime) {
|
1410 |
+
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
1411 |
+
const bullet = this.bullets[i];
|
1412 |
+
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
1413 |
+
|
1414 |
+
// ์ง๋ฉด ์ถฉ๋ ์ฒดํฌ
|
1415 |
+
if (bullet.position.y <= 0) {
|
1416 |
+
// ํฌ๊ณ ํ๋ คํ ์ง๋ฉด ์ถฉ๋ ํจ๊ณผ
|
1417 |
+
if (window.gameInstance) {
|
1418 |
+
window.gameInstance.createGroundImpactEffect(bullet.position);
|
1419 |
+
}
|
1420 |
+
this.scene.remove(bullet);
|
1421 |
+
this.bullets.splice(i, 1);
|
1422 |
+
continue;
|
1423 |
+
}
|
1424 |
+
|
1425 |
+
if (bullet.position.distanceTo(this.position) > 5000) {
|
1426 |
+
this.scene.remove(bullet);
|
1427 |
+
this.bullets.splice(i, 1);
|
1428 |
+
}
|
1429 |
+
}
|
1430 |
+
}
|
1431 |
|
1432 |
+
takeDamage(damage) {
|
1433 |
+
this.health -= damage;
|
1434 |
+
return this.health <= 0;
|
1435 |
+
}
|
1436 |
|
1437 |
+
destroy() {
|
1438 |
+
if (this.mesh) {
|
1439 |
+
this.scene.remove(this.mesh);
|
1440 |
+
this.bullets.forEach(bullet => this.scene.remove(bullet));
|
1441 |
+
this.bullets = [];
|
1442 |
+
this.isLoaded = false;
|
1443 |
+
}
|
1444 |
+
}
|
1445 |
}
|
1446 |
|
1447 |
// ๋ฉ์ธ ๊ฒ์ ํด๋์ค
|