Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -1382,15 +1382,6 @@ class EnemyFighter {
|
|
| 1382 |
|
| 1383 |
// ์ด๊ธฐ ๋ชฉํ ์ค์
|
| 1384 |
this.selectNewPatrolTarget();
|
| 1385 |
-
// AIM-9 ๋ฏธ์ฌ์ผ ์์คํ
|
| 1386 |
-
this.aim9Missiles = 4; // ์ ์ 4๋ฐ์ AIM-9 ๋ณด์
|
| 1387 |
-
this.firedMissiles = [];
|
| 1388 |
-
this.currentWeapon = 'MG'; // ๊ธฐ๋ณธ ๋ฌด๊ธฐ
|
| 1389 |
-
this.lockTarget = null;
|
| 1390 |
-
this.lockProgress = 0;
|
| 1391 |
-
this.lastLockTime = 0;
|
| 1392 |
-
this.lastMissileFireTime = 0; // ๋ง์ง๋ง ๋ฏธ์ฌ์ผ ๋ฐ์ฌ ์๊ฐ
|
| 1393 |
-
}
|
| 1394 |
}
|
| 1395 |
|
| 1396 |
async initialize(loader) {
|
|
@@ -1439,11 +1430,11 @@ class EnemyFighter {
|
|
| 1439 |
this.isLoaded = true;
|
| 1440 |
}
|
| 1441 |
|
| 1442 |
-
// EnemyFighter ํด๋์ค์ update ๋ฉ์๋
|
| 1443 |
update(playerPosition, deltaTime) {
|
| 1444 |
if (!this.mesh || !this.isLoaded) return;
|
| 1445 |
|
| 1446 |
-
// ํํผ ํ์ด๋จธ ์
๋ฐ์ดํธ
|
| 1447 |
if (this.temporaryEvadeMode && this.evadeTimer > 0) {
|
| 1448 |
this.evadeTimer -= deltaTime;
|
| 1449 |
if (this.evadeTimer <= 0) {
|
|
@@ -1453,39 +1444,7 @@ update(playerPosition, deltaTime) {
|
|
| 1453 |
|
| 1454 |
const distanceToPlayer = this.position.distanceTo(playerPosition);
|
| 1455 |
|
| 1456 |
-
//
|
| 1457 |
-
if (this.playerFighter && this.playerFighter.firedMissiles) {
|
| 1458 |
-
for (const missile of this.playerFighter.firedMissiles) {
|
| 1459 |
-
if (!missile || !missile.target) continue;
|
| 1460 |
-
|
| 1461 |
-
// ์ด ์ ๊ธฐ๋ฅผ ํ๊ฒ์ผ๋ก ํ๋ ๋ฏธ์ฌ์ผ ๊ฐ์ง
|
| 1462 |
-
if (missile.target === this && missile.position) {
|
| 1463 |
-
const missileDistance = this.position.distanceTo(missile.position);
|
| 1464 |
-
|
| 1465 |
-
// 1500m ์ด๋ด์ ๋ฏธ์ฌ์ผ ๊ฐ์ง ์ ๊ธด๊ธ ํํผ
|
| 1466 |
-
if (missileDistance < 1500) {
|
| 1467 |
-
this.aiState = 'evade';
|
| 1468 |
-
this.temporaryEvadeMode = true;
|
| 1469 |
-
this.evadeTimer = 3.0; // 3์ด๊ฐ ํํผ ๊ธฐ๋
|
| 1470 |
-
|
| 1471 |
-
// ๋ฏธ์ฌ์ผ ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ํํผ
|
| 1472 |
-
const evadeDirection = this.position.clone().sub(missile.position).normalize();
|
| 1473 |
-
this.targetPosition = this.position.clone().add(evadeDirection.multiplyScalar(2000));
|
| 1474 |
-
|
| 1475 |
-
// ๊ณ ๋ ๋ณํ ์ถ๊ฐ
|
| 1476 |
-
if (this.position.y > 3000) {
|
| 1477 |
-
this.targetPosition.y -= 1000; // ๊ธํ๊ฐ
|
| 1478 |
-
} else {
|
| 1479 |
-
this.targetPosition.y += 1000; // ๊ธ์์น
|
| 1480 |
-
}
|
| 1481 |
-
|
| 1482 |
-
break; // ํ๋์ ๋ฏธ์ฌ์ผ๋ง ํํผ
|
| 1483 |
-
}
|
| 1484 |
-
}
|
| 1485 |
-
}
|
| 1486 |
-
}
|
| 1487 |
-
|
| 1488 |
-
// ์ํ ๊ฒฐ์
|
| 1489 |
if (this.temporaryEvadeMode) {
|
| 1490 |
this.aiState = 'evade';
|
| 1491 |
} else if (distanceToPlayer <= 3000) {
|
|
@@ -1516,48 +1475,31 @@ update(playerPosition, deltaTime) {
|
|
| 1516 |
|
| 1517 |
// ํํ ์
๋ฐ์ดํธ
|
| 1518 |
this.updateBullets(deltaTime);
|
| 1519 |
-
|
| 1520 |
-
// AIM-9 ๋ฏธ์ฌ์ผ ์
๋ฐ์ดํธ
|
| 1521 |
-
this.updateMissiles(deltaTime);
|
| 1522 |
-
|
| 1523 |
-
// ๋ฝ์จ ์
๋ฐ์ดํธ (์ ํฌ ์ํ์์๋ง)
|
| 1524 |
-
if (this.aiState === 'combat' && this.playerFighter) {
|
| 1525 |
-
this.updateLockOn(deltaTime);
|
| 1526 |
-
}
|
| 1527 |
}
|
| 1528 |
-
|
| 1529 |
-
executePatrol(deltaTime) {
|
| 1530 |
-
// ๋ชฉํ ์ง์ ๊น์ง์ ๊ฑฐ๋ฆฌ ํ์ธ
|
| 1531 |
-
if (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {
|
| 1532 |
-
this.selectNewPatrolTarget();
|
| 1533 |
-
}
|
| 1534 |
|
| 1535 |
-
|
| 1536 |
-
|
| 1537 |
-
|
| 1538 |
-
|
| 1539 |
-
|
| 1540 |
-
|
| 1541 |
-
|
| 1542 |
-
|
| 1543 |
-
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
-
|
| 1547 |
-
|
| 1548 |
-
|
| 1549 |
-
if (distance > 1500 && distance < 5000 && this.aim9Missiles > 0) {
|
| 1550 |
-
// ์ค๊ฑฐ๋ฆฌ์์ AIM-9 ์ฌ์ฉ
|
| 1551 |
-
this.currentWeapon = 'AIM9';
|
| 1552 |
-
} else {
|
| 1553 |
-
// ๊ทผ๊ฑฐ๋ฆฌ ๋๋ ๋ฏธ์ฌ์ผ ์์ ๋ MG ์ฌ์ฉ
|
| 1554 |
-
this.currentWeapon = 'MG';
|
| 1555 |
}
|
| 1556 |
|
| 1557 |
-
|
| 1558 |
-
|
| 1559 |
-
|
| 1560 |
-
|
|
|
|
|
|
|
|
|
|
| 1561 |
// ์กฐ์ค ์ ํ๋ ํ์ธ
|
| 1562 |
const aimAccuracy = this.calculateAimAccuracy(playerPosition);
|
| 1563 |
|
|
@@ -1576,74 +1518,122 @@ executeCombat(playerPosition, deltaTime) {
|
|
| 1576 |
// ๋ฐ์ฌํ ์ ์์ผ๋ฉด ์ฐ๋ฐ ์นด์ดํฐ ๋ฆฌ์
|
| 1577 |
this.burstCounter = 0;
|
| 1578 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1579 |
}
|
| 1580 |
-
// AIM-9 ๋ชจ๋์์๋ ๋ฝ์จ๋ง ์๋ (๋ฐ์ฌ๋ updateLockOn์์ ์ฒ๋ฆฌ)
|
| 1581 |
-
|
| 1582 |
-
// ๊ฑฐ๋ฆฌ์ ๋ฐ๋ผ ๊ธฐ๋ ๊ฒฐ์
|
| 1583 |
-
if (distance < 150) {
|
| 1584 |
-
// 150m ์ด๋ด๋ฉด ํํผ ๊ธฐ๋ ์์
|
| 1585 |
-
this.selectEvadeTarget();
|
| 1586 |
-
// ์ผ์์ ํํผ ๋ชจ๋ ํ์ฑํ
|
| 1587 |
-
this.temporaryEvadeMode = true;
|
| 1588 |
-
this.evadeTimer = 1.0;
|
| 1589 |
-
} else if (distance < 500) {
|
| 1590 |
-
// 500m ์ด๋ด๋ฉด ์ธก๋ฉด ํํผ
|
| 1591 |
-
this.selectEvadeTarget();
|
| 1592 |
-
} else if (distance > 2000 && this.currentWeapon === 'MG') {
|
| 1593 |
-
// MG ๋ชจ๋์์๋ง ์ ๊ทผ
|
| 1594 |
-
this.targetPosition = playerPosition.clone();
|
| 1595 |
-
}
|
| 1596 |
-
}
|
| 1597 |
-
|
| 1598 |
-
// ์๋ก์ด ๋ฉ์๋: ์ถฉ๋ ์์ธก
|
| 1599 |
-
checkCollisionPrediction(deltaTime) {
|
| 1600 |
-
if (!this.nearbyEnemies) return;
|
| 1601 |
-
|
| 1602 |
-
// 2์ด ํ ์์ ์์น ๊ณ์ฐ
|
| 1603 |
-
const predictTime = 2.0;
|
| 1604 |
-
const forward = new THREE.Vector3(0, 0, 1).applyEuler(this.rotation);
|
| 1605 |
-
this.predictedPosition.copy(this.position).add(forward.multiplyScalar(this.speed * predictTime));
|
| 1606 |
|
| 1607 |
-
|
| 1608 |
-
|
|
|
|
| 1609 |
|
| 1610 |
-
//
|
| 1611 |
-
const
|
| 1612 |
-
const
|
| 1613 |
-
|
| 1614 |
-
// ์์ ๊ฑฐ๋ฆฌ
|
| 1615 |
-
const predictedDistance = this.predictedPosition.distanceTo(enemyPredicted);
|
| 1616 |
|
| 1617 |
-
|
| 1618 |
-
|
| 1619 |
-
|
| 1620 |
-
|
|
|
|
|
|
|
| 1621 |
|
| 1622 |
-
//
|
| 1623 |
-
|
| 1624 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1625 |
} else {
|
| 1626 |
-
|
| 1627 |
}
|
| 1628 |
|
| 1629 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1630 |
}
|
| 1631 |
-
});
|
| 1632 |
-
}
|
| 1633 |
-
|
| 1634 |
-
// ์๋ก์ด ๋ฉ์๋: ๊ธด๊ธ ํํผ ์คํ
|
| 1635 |
-
executeEmergencyEvade(deltaTime) {
|
| 1636 |
-
// ํํผ ๋ฒกํฐ๊ฐ ์์ผ๋ฉด ๊ทธ ๋ฐฉํฅ์ผ๋ก, ์์ผ๋ฉด ๊ธ์์น
|
| 1637 |
-
if (this.avoidanceVector.length() > 0) {
|
| 1638 |
-
const evadeDirection = this.avoidanceVector.clone().normalize();
|
| 1639 |
|
| 1640 |
-
//
|
| 1641 |
-
|
| 1642 |
-
|
|
|
|
|
|
|
| 1643 |
|
| 1644 |
-
|
| 1645 |
-
|
| 1646 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1647 |
|
| 1648 |
// Yaw ํ์
|
| 1649 |
const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
|
|
@@ -1653,181 +1643,132 @@ executeEmergencyEvade(deltaTime) {
|
|
| 1653 |
this.rotation.y = targetYaw;
|
| 1654 |
}
|
| 1655 |
|
| 1656 |
-
// Pitch ํ์
|
| 1657 |
-
const
|
| 1658 |
-
if (Math.abs(
|
| 1659 |
-
this.rotation.x += Math.sign(
|
| 1660 |
} else {
|
| 1661 |
this.rotation.x = targetPitch;
|
| 1662 |
}
|
| 1663 |
|
| 1664 |
-
//
|
| 1665 |
-
|
| 1666 |
-
|
| 1667 |
-
|
| 1668 |
-
|
| 1669 |
-
|
| 1670 |
-
|
| 1671 |
-
|
| 1672 |
-
|
| 1673 |
-
}
|
| 1674 |
-
|
| 1675 |
-
smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {
|
| 1676 |
-
// ๊ธฐ์กด ๋ก์ง (ํํด๊ฐ ์๋ ๋)
|
| 1677 |
-
const direction = targetPos.clone().sub(this.position);
|
| 1678 |
-
direction.y *= 0.5;
|
| 1679 |
-
direction.normalize();
|
| 1680 |
-
|
| 1681 |
-
// ์ถฉ๋ ํํผ ๋ฒกํฐ ์ ์ฉ (ํํผ๊ฐ ์ฐ์ )
|
| 1682 |
-
if (this.avoidanceVector.length() > 0) {
|
| 1683 |
-
const avoidanceStrength = this.temporaryEvadeMode ? 1.0 : 0.5;
|
| 1684 |
-
direction.add(this.avoidanceVector.multiplyScalar(avoidanceStrength));
|
| 1685 |
-
direction.normalize();
|
| 1686 |
-
}
|
| 1687 |
-
|
| 1688 |
-
// ๋ชฉํ ํ์ ๊ณ์ฐ
|
| 1689 |
-
const targetYaw = Math.atan2(direction.x, direction.z);
|
| 1690 |
-
const targetPitch = Math.asin(-direction.y);
|
| 1691 |
-
|
| 1692 |
-
// ๋ถ๋๋ฌ์ด ํ์ (์ต๋ ํ์ ์๋ ์ ํ)
|
| 1693 |
-
const turnSpeed = isEmergency ? this.turnSpeed * 2.0 : (this.temporaryEvadeMode ? this.turnSpeed * 1.5 : this.turnSpeed);
|
| 1694 |
-
const maxTurnRate = turnSpeed * deltaTime;
|
| 1695 |
-
|
| 1696 |
-
// Yaw ํ์
|
| 1697 |
-
const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
|
| 1698 |
-
if (Math.abs(yawDiff) > maxTurnRate) {
|
| 1699 |
-
this.rotation.y += Math.sign(yawDiff) * maxTurnRate;
|
| 1700 |
-
} else {
|
| 1701 |
-
this.rotation.y = targetYaw;
|
| 1702 |
-
}
|
| 1703 |
-
|
| 1704 |
-
// Pitch ํ์ (์ ํ์ )
|
| 1705 |
-
const maxPitchRate = maxTurnRate * 0.7;
|
| 1706 |
-
if (Math.abs(targetPitch - this.rotation.x) > maxPitchRate) {
|
| 1707 |
-
this.rotation.x += Math.sign(targetPitch - this.rotation.x) * maxPitchRate;
|
| 1708 |
-
} else {
|
| 1709 |
-
this.rotation.x = targetPitch;
|
| 1710 |
-
}
|
| 1711 |
-
|
| 1712 |
-
// Pitch ์ ํ (ยฑ40๋)
|
| 1713 |
-
const maxPitchAngle = Math.PI * 40 / 180;
|
| 1714 |
-
this.rotation.x = THREE.MathUtils.clamp(this.rotation.x, -maxPitchAngle, maxPitchAngle);
|
| 1715 |
-
|
| 1716 |
-
// ๋กค ์๋ ๊ณ์ฐ (์ ํ ์)
|
| 1717 |
-
if (!this.temporaryEvadeMode) {
|
| 1718 |
-
this.rotation.z = -yawDiff * 0.5;
|
| 1719 |
-
this.rotation.z = THREE.MathUtils.clamp(this.rotation.z, -Math.PI / 4, Math.PI / 4);
|
| 1720 |
}
|
| 1721 |
-
}
|
| 1722 |
-
|
| 1723 |
-
calculateAvoidance() {
|
| 1724 |
-
this.avoidanceVector.set(0, 0, 0);
|
| 1725 |
-
|
| 1726 |
-
if (!this.nearbyEnemies) return;
|
| 1727 |
|
| 1728 |
-
|
| 1729 |
-
|
| 1730 |
-
|
| 1731 |
-
|
| 1732 |
-
if (enemy === this || !enemy.position) return;
|
| 1733 |
|
| 1734 |
-
|
|
|
|
| 1735 |
|
| 1736 |
-
|
| 1737 |
-
|
| 1738 |
-
criticalAvoidance = true;
|
| 1739 |
|
| 1740 |
-
|
| 1741 |
-
const avoidDir = this.position.clone().sub(enemy.position).normalize();
|
| 1742 |
-
const strength = 2.0; // ๋งค์ฐ ๊ฐํ ํํผ
|
| 1743 |
-
this.avoidanceVector.add(avoidDir.multiplyScalar(strength));
|
| 1744 |
|
| 1745 |
-
//
|
| 1746 |
-
if (
|
| 1747 |
-
|
| 1748 |
-
|
| 1749 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1750 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1751 |
|
| 1752 |
-
|
| 1753 |
-
|
| 1754 |
-
|
| 1755 |
-
|
| 1756 |
-
|
| 1757 |
-
|
| 1758 |
-
|
| 1759 |
-
this.avoidanceVector.add(avoidDir.multiplyScalar(strength));
|
| 1760 |
-
avoidCount++;
|
| 1761 |
-
}
|
| 1762 |
-
});
|
| 1763 |
-
|
| 1764 |
-
if (avoidCount > 0) {
|
| 1765 |
-
this.avoidanceVector.divideScalar(avoidCount);
|
| 1766 |
-
this.avoidanceVector.normalize();
|
| 1767 |
-
|
| 1768 |
-
// ๊ธด๊ธ ํํผ ์ ๋ ๊ฐํ ํํผ๋ ฅ ์ ์ฉ
|
| 1769 |
-
if (criticalAvoidance) {
|
| 1770 |
-
this.avoidanceVector.multiplyScalar(2.0);
|
| 1771 |
-
// ์ผ์์ ์ผ๋ก ์ ํฌ ์ํ ํด์
|
| 1772 |
-
this.temporaryEvadeMode = true;
|
| 1773 |
-
this.evadeTimer = 2.0; // 2์ด ๋์ ํํผ ์ฐ์
|
| 1774 |
}
|
| 1775 |
}
|
| 1776 |
-
}
|
| 1777 |
-
|
| 1778 |
-
updatePhysics(deltaTime) {
|
| 1779 |
-
if (!this.mesh) return;
|
| 1780 |
|
| 1781 |
-
|
| 1782 |
-
|
| 1783 |
-
|
| 1784 |
-
|
| 1785 |
-
|
| 1786 |
-
|
| 1787 |
-
|
| 1788 |
-
|
| 1789 |
-
|
| 1790 |
-
|
| 1791 |
-
|
| 1792 |
-
|
| 1793 |
-
|
| 1794 |
-
|
| 1795 |
-
|
| 1796 |
-
|
| 1797 |
-
|
| 1798 |
-
|
| 1799 |
-
|
| 1800 |
-
|
| 1801 |
-
|
| 1802 |
-
|
| 1803 |
-
|
| 1804 |
-
|
| 1805 |
-
|
| 1806 |
-
|
| 1807 |
-
|
| 1808 |
-
|
| 1809 |
-
|
| 1810 |
-
|
| 1811 |
-
|
| 1812 |
-
|
| 1813 |
-
|
| 1814 |
-
|
| 1815 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1816 |
}
|
| 1817 |
|
| 1818 |
-
|
| 1819 |
-
this.position.x = THREE.MathUtils.clamp(this.position.x, -mapLimit, mapLimit);
|
| 1820 |
-
this.position.z = THREE.MathUtils.clamp(this.position.z, -mapLimit, mapLimit);
|
| 1821 |
-
|
| 1822 |
-
// ๋ฉ์ ์
๋ฐ์ดํธ
|
| 1823 |
-
this.mesh.position.copy(this.position);
|
| 1824 |
-
this.mesh.rotation.x = this.rotation.x;
|
| 1825 |
-
this.mesh.rotation.y = this.rotation.y + 3 * Math.PI / 2; // ํ๋ ์ด์ด์ ๋์ผํ ํ์ ์คํ์
|
| 1826 |
-
this.mesh.rotation.z = this.rotation.z;
|
| 1827 |
-
}
|
| 1828 |
-
|
| 1829 |
-
fireWeapon() {
|
| 1830 |
-
if (this.currentWeapon === 'MG') {
|
| 1831 |
const now = Date.now();
|
| 1832 |
|
| 1833 |
// 0.1์ด์ 1๋ฐ์ฉ, 10๋ฐ ์ฐ๋ฐ
|
|
@@ -1849,227 +1790,119 @@ fireWeapon() {
|
|
| 1849 |
}
|
| 1850 |
}
|
| 1851 |
}
|
| 1852 |
-
// AIM-9๋ updateLockOn์์ ์๋ ๋ฐ์ฌ
|
| 1853 |
-
}
|
| 1854 |
-
|
| 1855 |
-
shoot() {
|
| 1856 |
-
// ํํ ์์ฑ (ํ๋ ์ด์ด์ ๋์ผํ ํฌ๊ธฐ)
|
| 1857 |
-
const bulletGeometry = new THREE.CylinderGeometry(1.0, 1.0, 16, 8);
|
| 1858 |
-
const bulletMaterial = new THREE.MeshBasicMaterial({
|
| 1859 |
-
color: 0xff0000,
|
| 1860 |
-
});
|
| 1861 |
-
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 1862 |
-
|
| 1863 |
-
// ๊ธฐ์ ๋์์๋ง ๋ฐ์ฌ - ์ ํํ ์ ๋ฐฉ ์ค์์์
|
| 1864 |
-
const muzzleOffset = new THREE.Vector3(0, 0, 10); // X=0, Y=0์ผ๋ก ์ค์ ๊ณ ์
|
| 1865 |
-
muzzleOffset.applyEuler(this.rotation);
|
| 1866 |
-
bullet.position.copy(this.position).add(muzzleOffset);
|
| 1867 |
-
|
| 1868 |
-
// ํํ์ ๋ฐ์ฌ ๋ฐฉํฅ์ผ๋ก ํ์
|
| 1869 |
-
bullet.rotation.copy(this.rotation);
|
| 1870 |
-
bullet.rotateX(Math.PI / 2); // ์ค๋ฆฐ๋๊ฐ Z์ถ ๋ฐฉํฅ์ ํฅํ๋๋ก
|
| 1871 |
-
|
| 1872 |
-
// ํํ ์ด๊ธฐ ์์น ์ ์ฅ
|
| 1873 |
-
bullet.startPosition = bullet.position.clone();
|
| 1874 |
-
|
| 1875 |
-
// ํํ ์๋ (ํ๋ ์ด์ด์ ๋์ผํ๊ฒ 1500) - ์ ํํ ์ ๋ฐฉ์ผ๋ก
|
| 1876 |
-
const direction = new THREE.Vector3(0, 0, 1);
|
| 1877 |
-
direction.applyEuler(this.rotation);
|
| 1878 |
-
bullet.velocity = direction.multiplyScalar(1500);
|
| 1879 |
|
| 1880 |
-
|
| 1881 |
-
|
| 1882 |
-
|
| 1883 |
-
|
| 1884 |
-
|
| 1885 |
-
|
| 1886 |
-
|
| 1887 |
-
|
| 1888 |
-
|
| 1889 |
-
|
| 1890 |
-
|
| 1891 |
-
|
| 1892 |
-
|
| 1893 |
-
|
| 1894 |
-
|
| 1895 |
-
|
| 1896 |
-
|
| 1897 |
-
updateBullets(deltaTime) {
|
| 1898 |
-
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
| 1899 |
-
const bullet = this.bullets[i];
|
| 1900 |
-
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
| 1901 |
-
|
| 1902 |
-
// ์ง๋ฉด ์ถฉ๋
|
| 1903 |
-
if (bullet.position.y <= 0) {
|
| 1904 |
-
if (window.gameInstance) {
|
| 1905 |
-
window.gameInstance.createGroundImpactEffect(bullet.position);
|
| 1906 |
-
}
|
| 1907 |
-
this.scene.remove(bullet);
|
| 1908 |
-
this.bullets.splice(i, 1);
|
| 1909 |
-
continue;
|
| 1910 |
-
}
|
| 1911 |
|
| 1912 |
-
//
|
| 1913 |
-
|
| 1914 |
-
|
| 1915 |
-
|
| 1916 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1917 |
}
|
| 1918 |
}
|
| 1919 |
-
}
|
| 1920 |
-
|
| 1921 |
-
// ์ ๊ธฐ์ฉ AIM-9 ๋ฝ์จ ์์คํ
|
| 1922 |
-
updateLockOn(deltaTime) {
|
| 1923 |
-
if (!this.playerFighter || this.currentWeapon !== 'AIM9') {
|
| 1924 |
-
this.lockTarget = null;
|
| 1925 |
-
this.lockProgress = 0;
|
| 1926 |
-
return;
|
| 1927 |
-
}
|
| 1928 |
-
|
| 1929 |
-
const now = Date.now();
|
| 1930 |
-
if (now - this.lastLockTime < 1000) return;
|
| 1931 |
-
|
| 1932 |
-
const distance = this.position.distanceTo(this.playerFighter.position);
|
| 1933 |
|
| 1934 |
-
|
| 1935 |
-
|
| 1936 |
-
|
| 1937 |
-
|
| 1938 |
-
|
| 1939 |
-
|
| 1940 |
-
|
| 1941 |
-
// 15๋ ์ด๋ด์ ์์ผ๋ฉด ๋ฝ์จ
|
| 1942 |
-
if (angle < Math.PI / 12) {
|
| 1943 |
-
if (this.lockTarget === this.playerFighter) {
|
| 1944 |
-
this.lockProgress++;
|
| 1945 |
-
this.lastLockTime = now;
|
| 1946 |
-
|
| 1947 |
-
// ๋ฝ์จ ์์ ์ ํ๋ ์ด์ด์๊ฒ ๊ฒฝ๊ณ
|
| 1948 |
-
if (this.lockProgress === 1 && window.gameInstance) {
|
| 1949 |
-
window.gameInstance.onEnemyLockStart(this);
|
| 1950 |
-
}
|
| 1951 |
-
|
| 1952 |
-
// ๋ฝ์จ ์๋ฃ ์ ๋ฏธ์ฌ์ผ ๋ฐ์ฌ
|
| 1953 |
-
if (this.lockProgress >= GAME_CONSTANTS.AIM9_LOCK_REQUIRED) {
|
| 1954 |
-
this.fireMissile();
|
| 1955 |
-
}
|
| 1956 |
-
} else {
|
| 1957 |
-
// ์๋ก์ด ๋ฝ์จ ์์
|
| 1958 |
-
this.lockTarget = this.playerFighter;
|
| 1959 |
-
this.lockProgress = 1;
|
| 1960 |
-
this.lastLockTime = now;
|
| 1961 |
-
|
| 1962 |
if (window.gameInstance) {
|
| 1963 |
-
window.gameInstance.
|
| 1964 |
}
|
|
|
|
|
|
|
|
|
|
| 1965 |
}
|
| 1966 |
-
|
| 1967 |
-
//
|
| 1968 |
-
if (
|
| 1969 |
-
|
|
|
|
|
|
|
| 1970 |
}
|
| 1971 |
-
this.lockTarget = null;
|
| 1972 |
-
this.lockProgress = 0;
|
| 1973 |
}
|
| 1974 |
-
} else {
|
| 1975 |
-
// ๋ฒ์ ๋ฐ
|
| 1976 |
-
if (this.lockTarget && window.gameInstance) {
|
| 1977 |
-
window.gameInstance.onEnemyLockLost(this);
|
| 1978 |
-
}
|
| 1979 |
-
this.lockTarget = null;
|
| 1980 |
-
this.lockProgress = 0;
|
| 1981 |
}
|
| 1982 |
-
}
|
| 1983 |
-
|
| 1984 |
-
// ์ ๊ธฐ ๋ฏธ์ฌ์ผ ๋ฐ์ฌ
|
| 1985 |
-
fireMissile() {
|
| 1986 |
-
if (this.aim9Missiles <= 0 || !this.lockTarget) return;
|
| 1987 |
-
|
| 1988 |
-
const now = Date.now();
|
| 1989 |
-
// ๋ฏธ์ฌ์ผ ๋ฐ์ฌ ๊ฐ๊ฒฉ ์ต์ 5์ด
|
| 1990 |
-
if (now - this.lastMissileFireTime < 5000) return;
|
| 1991 |
-
|
| 1992 |
-
this.aim9Missiles--;
|
| 1993 |
-
this.lastMissileFireTime = now;
|
| 1994 |
|
| 1995 |
-
|
| 1996 |
-
|
| 1997 |
-
|
| 1998 |
-
|
| 1999 |
-
|
| 2000 |
-
|
| 2001 |
-
// ์ ๊ธฐ์ฉ AIM-9 ๋ฏธ์ฌ์ผ ์์ฑ
|
| 2002 |
-
const missile = new EnemyAIM9Missile(this.scene, missileStartPos, this.lockTarget, this.rotation.clone());
|
| 2003 |
-
this.firedMissiles.push(missile);
|
| 2004 |
-
|
| 2005 |
-
// ๋ฝ์จ ์ด๊ธฐํ
|
| 2006 |
-
this.lockTarget = null;
|
| 2007 |
-
this.lockProgress = 0;
|
| 2008 |
-
|
| 2009 |
-
// ํ๋ ์ด์ด์๊ฒ ๋ฏธ์ฌ์ผ ๋ฐ์ฌ ๊ฒฝ๊ณ
|
| 2010 |
-
if (window.gameInstance) {
|
| 2011 |
-
window.gameInstance.onEnemyMissileLaunch(this, missile);
|
| 2012 |
-
}
|
| 2013 |
-
}
|
| 2014 |
-
|
| 2015 |
-
// ๋ฏธ์ฌ์ผ ์
๋ฐ์ดํธ
|
| 2016 |
-
updateMissiles(deltaTime) {
|
| 2017 |
-
for (let i = this.firedMissiles.length - 1; i >= 0; i--) {
|
| 2018 |
-
const missile = this.firedMissiles[i];
|
| 2019 |
-
const result = missile.update(deltaTime, this.position);
|
| 2020 |
-
|
| 2021 |
-
if (result === 'hit' || result === 'expired') {
|
| 2022 |
-
this.firedMissiles.splice(i, 1);
|
| 2023 |
-
}
|
| 2024 |
}
|
| 2025 |
-
}
|
| 2026 |
-
|
| 2027 |
-
calculateAimAccuracy(target) {
|
| 2028 |
-
const toTarget = target.clone().sub(this.position).normalize();
|
| 2029 |
-
const forward = new THREE.Vector3(0, 0, 1).applyEuler(this.rotation);
|
| 2030 |
-
const dotProduct = forward.dot(toTarget);
|
| 2031 |
-
return Math.acos(Math.max(-1, Math.min(1, dotProduct)));
|
| 2032 |
-
}
|
| 2033 |
-
|
| 2034 |
-
selectNewPatrolTarget() {
|
| 2035 |
-
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2 * 0.7;
|
| 2036 |
|
| 2037 |
-
|
| 2038 |
-
|
| 2039 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2040 |
|
| 2041 |
-
|
| 2042 |
-
|
| 2043 |
-
|
| 2044 |
-
|
| 2045 |
-
|
| 2046 |
-
|
| 2047 |
-
|
| 2048 |
-
|
| 2049 |
-
|
| 2050 |
-
|
| 2051 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2052 |
|
| 2053 |
-
|
| 2054 |
-
|
| 2055 |
-
|
| 2056 |
-
|
| 2057 |
-
|
| 2058 |
|
| 2059 |
-
|
| 2060 |
-
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2 * 0.8;
|
| 2061 |
-
this.targetPosition.x = THREE.MathUtils.clamp(this.targetPosition.x, -mapLimit, mapLimit);
|
| 2062 |
-
this.targetPosition.z = THREE.MathUtils.clamp(this.targetPosition.z, -mapLimit, mapLimit);
|
| 2063 |
-
this.targetPosition.y = THREE.MathUtils.clamp(this.targetPosition.y, 1000, 6000);
|
| 2064 |
-
}
|
| 2065 |
-
|
| 2066 |
-
normalizeAngle(angle) {
|
| 2067 |
-
while (angle > Math.PI) angle -= Math.PI * 2;
|
| 2068 |
-
while (angle < -Math.PI) angle += Math.PI * 2;
|
| 2069 |
-
return angle;
|
| 2070 |
-
}
|
| 2071 |
-
|
| 2072 |
-
takeDamage(damage) {
|
| 2073 |
console.log(`Enemy taking damage: ${damage}, Current health: ${this.health}`);
|
| 2074 |
this.health -= damage;
|
| 2075 |
console.log(`Enemy health after damage: ${this.health}`);
|
|
@@ -2077,22 +1910,14 @@ takeDamage(damage) {
|
|
| 2077 |
console.log(`Enemy is dead: ${isDead}`);
|
| 2078 |
return isDead;
|
| 2079 |
}
|
| 2080 |
-
|
| 2081 |
-
destroy() {
|
| 2082 |
-
|
| 2083 |
-
|
| 2084 |
-
|
| 2085 |
-
|
| 2086 |
-
|
| 2087 |
-
|
| 2088 |
-
this.firedMissiles.forEach(missile => {
|
| 2089 |
-
if (missile.destroy) {
|
| 2090 |
-
missile.destroy();
|
| 2091 |
-
}
|
| 2092 |
-
});
|
| 2093 |
-
this.firedMissiles = [];
|
| 2094 |
-
|
| 2095 |
-
this.isLoaded = false;
|
| 2096 |
}
|
| 2097 |
}
|
| 2098 |
|
|
|
|
| 1382 |
|
| 1383 |
// ์ด๊ธฐ ๋ชฉํ ์ค์
|
| 1384 |
this.selectNewPatrolTarget();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1385 |
}
|
| 1386 |
|
| 1387 |
async initialize(loader) {
|
|
|
|
| 1430 |
this.isLoaded = true;
|
| 1431 |
}
|
| 1432 |
|
| 1433 |
+
// EnemyFighter ํด๋์ค์ update ๋ฉ์๋์์ ๋ฏธ์ฌ์ผ ํํผ ๋ก์ง ์ ๊ฑฐ
|
| 1434 |
update(playerPosition, deltaTime) {
|
| 1435 |
if (!this.mesh || !this.isLoaded) return;
|
| 1436 |
|
| 1437 |
+
// ํํผ ํ์ด๋จธ ์
๋ฐ์ดํธ (๋ฏธ์ฌ์ผ ํํผ ์ ์ธ)
|
| 1438 |
if (this.temporaryEvadeMode && this.evadeTimer > 0) {
|
| 1439 |
this.evadeTimer -= deltaTime;
|
| 1440 |
if (this.evadeTimer <= 0) {
|
|
|
|
| 1444 |
|
| 1445 |
const distanceToPlayer = this.position.distanceTo(playerPosition);
|
| 1446 |
|
| 1447 |
+
// ์ํ ๊ฒฐ์ (๋ฏธ์ฌ์ผ ํ์ง ์ ๊ฑฐ)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1448 |
if (this.temporaryEvadeMode) {
|
| 1449 |
this.aiState = 'evade';
|
| 1450 |
} else if (distanceToPlayer <= 3000) {
|
|
|
|
| 1475 |
|
| 1476 |
// ํํ ์
๋ฐ์ดํธ
|
| 1477 |
this.updateBullets(deltaTime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1478 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1479 |
|
| 1480 |
+
executePatrol(deltaTime) {
|
| 1481 |
+
// ๋ชฉํ ์ง์ ๊น์ง์ ๊ฑฐ๋ฆฌ ํ์ธ
|
| 1482 |
+
if (!this.targetPosition || this.position.distanceTo(this.targetPosition) < 500) {
|
| 1483 |
+
this.selectNewPatrolTarget();
|
| 1484 |
+
}
|
| 1485 |
+
|
| 1486 |
+
// ๋ชฉํ๋ฅผ ํฅํด ๋ถ๋๋ฝ๊ฒ ํ์
|
| 1487 |
+
this.smoothTurnToTarget(this.targetPosition, deltaTime);
|
| 1488 |
+
|
| 1489 |
+
// ์๋ ์ ์ง (500-750kt) - ํญ์ ์ต์ ์๋ ์ด์ ์ ์ง
|
| 1490 |
+
if (this.speed < this.minSpeed) {
|
| 1491 |
+
this.speed = this.minSpeed;
|
| 1492 |
+
}
|
| 1493 |
+
this.speed = THREE.MathUtils.clamp(this.speed, this.minSpeed, this.maxSpeed);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1494 |
}
|
| 1495 |
|
| 1496 |
+
executeCombat(playerPosition, deltaTime) {
|
| 1497 |
+
const distance = this.position.distanceTo(playerPosition);
|
| 1498 |
+
|
| 1499 |
+
|
| 1500 |
+
// ํ๋ ์ด์ด๋ฅผ ํฅํด ํ์
|
| 1501 |
+
this.smoothTurnToTarget(playerPosition, deltaTime);
|
| 1502 |
+
|
| 1503 |
// ์กฐ์ค ์ ํ๋ ํ์ธ
|
| 1504 |
const aimAccuracy = this.calculateAimAccuracy(playerPosition);
|
| 1505 |
|
|
|
|
| 1518 |
// ๋ฐ์ฌํ ์ ์์ผ๋ฉด ์ฐ๋ฐ ์นด์ดํฐ ๋ฆฌ์
|
| 1519 |
this.burstCounter = 0;
|
| 1520 |
}
|
| 1521 |
+
|
| 1522 |
+
// ๊ฑฐ๋ฆฌ์ ๋ฐ๋ผ ๊ธฐ๋ ๊ฒฐ์
|
| 1523 |
+
if (distance < 150) {
|
| 1524 |
+
// 150m ์ด๋ด๋ฉด ํํผ ๊ธฐ๋ ์์
|
| 1525 |
+
this.selectEvadeTarget();
|
| 1526 |
+
// ์ผ์์ ํํผ ๋ชจ๋ ํ์ฑํ
|
| 1527 |
+
this.temporaryEvadeMode = true;
|
| 1528 |
+
this.evadeTimer = 1.0;
|
| 1529 |
+
} else if (distance < 500) {
|
| 1530 |
+
// 500m ์ด๋ด๋ฉด ์ธก๋ฉด ํํผ
|
| 1531 |
+
this.selectEvadeTarget();
|
| 1532 |
+
} else if (distance > 2000) {
|
| 1533 |
+
// ๋ฉ๋ฉด ์ ๊ทผ
|
| 1534 |
+
this.targetPosition = playerPosition.clone();
|
| 1535 |
+
}
|
| 1536 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1537 |
|
| 1538 |
+
// ์๋ก์ด ๋ฉ์๋: ์ถฉ๋ ์์ธก
|
| 1539 |
+
checkCollisionPrediction(deltaTime) {
|
| 1540 |
+
if (!this.nearbyEnemies) return;
|
| 1541 |
|
| 1542 |
+
// 2์ด ํ ์์ ์์น ๊ณ์ฐ
|
| 1543 |
+
const predictTime = 2.0;
|
| 1544 |
+
const forward = new THREE.Vector3(0, 0, 1).applyEuler(this.rotation);
|
| 1545 |
+
this.predictedPosition.copy(this.position).add(forward.multiplyScalar(this.speed * predictTime));
|
|
|
|
|
|
|
| 1546 |
|
| 1547 |
+
this.nearbyEnemies.forEach(enemy => {
|
| 1548 |
+
if (enemy === this || !enemy.position) return;
|
| 1549 |
+
|
| 1550 |
+
// ๋ค๋ฅธ ์ ๊ธฐ์ ์์ ์์น
|
| 1551 |
+
const enemyForward = new THREE.Vector3(0, 0, 1).applyEuler(enemy.rotation);
|
| 1552 |
+
const enemyPredicted = enemy.position.clone().add(enemyForward.multiplyScalar(enemy.speed * predictTime));
|
| 1553 |
|
| 1554 |
+
// ์์ ๊ฑฐ๋ฆฌ
|
| 1555 |
+
const predictedDistance = this.predictedPosition.distanceTo(enemyPredicted);
|
| 1556 |
+
|
| 1557 |
+
// 150m ์ด๋ด๋ก ์ ๊ทผ ์์ ์ ์ฌ์ ํํผ
|
| 1558 |
+
if (predictedDistance < 150) {
|
| 1559 |
+
// ์๋ฐฉ์ ํํผ ๋ฐฉํฅ ์ค์
|
| 1560 |
+
const avoidDir = this.predictedPosition.clone().sub(enemyPredicted).normalize();
|
| 1561 |
+
|
| 1562 |
+
// ์์ง ๋ถ๋ฆฌ ์ถ๊ฐ
|
| 1563 |
+
if (this.position.y > enemy.position.y) {
|
| 1564 |
+
avoidDir.y += 0.3;
|
| 1565 |
+
} else {
|
| 1566 |
+
avoidDir.y -= 0.3;
|
| 1567 |
+
}
|
| 1568 |
+
|
| 1569 |
+
this.avoidanceVector.add(avoidDir.multiplyScalar(1.5));
|
| 1570 |
+
}
|
| 1571 |
+
});
|
| 1572 |
+
}
|
| 1573 |
+
|
| 1574 |
+
// ์๋ก์ด ๋ฉ์๋: ๊ธด๊ธ ํํผ ์คํ
|
| 1575 |
+
executeEmergencyEvade(deltaTime) {
|
| 1576 |
+
// ํํผ ๋ฒกํฐ๊ฐ ์์ผ๋ฉด ๊ทธ ๋ฐฉํฅ์ผ๋ก, ์์ผ๋ฉด ๊ธ์์น
|
| 1577 |
+
if (this.avoidanceVector.length() > 0) {
|
| 1578 |
+
const evadeDirection = this.avoidanceVector.clone().normalize();
|
| 1579 |
+
|
| 1580 |
+
// ๊ธ์ ํ
|
| 1581 |
+
const targetYaw = Math.atan2(evadeDirection.x, evadeDirection.z);
|
| 1582 |
+
const targetPitch = Math.asin(-evadeDirection.y) * 0.5; // ํผ์น๋ ์ ๋ฐ๋ง
|
| 1583 |
+
|
| 1584 |
+
// ๋น ๋ฅธ ํ์ ์๋
|
| 1585 |
+
const emergencyTurnSpeed = this.turnSpeed * 2.0;
|
| 1586 |
+
const maxTurnRate = emergencyTurnSpeed * deltaTime;
|
| 1587 |
+
|
| 1588 |
+
// Yaw ํ์
|
| 1589 |
+
const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
|
| 1590 |
+
if (Math.abs(yawDiff) > maxTurnRate) {
|
| 1591 |
+
this.rotation.y += Math.sign(yawDiff) * maxTurnRate;
|
| 1592 |
} else {
|
| 1593 |
+
this.rotation.y = targetYaw;
|
| 1594 |
}
|
| 1595 |
|
| 1596 |
+
// Pitch ํ์
|
| 1597 |
+
const pitchDiff = targetPitch - this.rotation.x;
|
| 1598 |
+
if (Math.abs(pitchDiff) > maxTurnRate * 0.7) {
|
| 1599 |
+
this.rotation.x += Math.sign(pitchDiff) * maxTurnRate * 0.7;
|
| 1600 |
+
} else {
|
| 1601 |
+
this.rotation.x = targetPitch;
|
| 1602 |
+
}
|
| 1603 |
+
|
| 1604 |
+
// ๊ธ์ ํ ์ ์ฝ๊ฐ์ ๋กค ์ถ๊ฐ
|
| 1605 |
+
this.rotation.z = Math.sign(yawDiff) * Math.min(Math.abs(yawDiff), Math.PI / 6);
|
| 1606 |
+
} else {
|
| 1607 |
+
// ๊ธฐ๋ณธ ํํผ: ๊ธ์์น
|
| 1608 |
+
this.rotation.x = -Math.PI / 6; // 30๋ ์์น
|
| 1609 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1610 |
|
| 1611 |
+
// ํํผ ์ค์๋ ์ต๋ ์๋
|
| 1612 |
+
this.speed = this.maxSpeed;
|
| 1613 |
+
}
|
| 1614 |
+
|
| 1615 |
+
smoothTurnToTarget(targetPos, deltaTime, isEmergency = false) {
|
| 1616 |
|
| 1617 |
+
|
| 1618 |
+
// ๊ธฐ์กด ๋ก์ง (ํํด๊ฐ ์๋ ๋)
|
| 1619 |
+
const direction = targetPos.clone().sub(this.position);
|
| 1620 |
+
direction.y *= 0.5;
|
| 1621 |
+
direction.normalize();
|
| 1622 |
+
|
| 1623 |
+
// ์ถฉ๋ ํํผ ๋ฒกํฐ ์ ์ฉ (ํํผ๊ฐ ์ฐ์ )
|
| 1624 |
+
if (this.avoidanceVector.length() > 0) {
|
| 1625 |
+
const avoidanceStrength = this.temporaryEvadeMode ? 1.0 : 0.5;
|
| 1626 |
+
direction.add(this.avoidanceVector.multiplyScalar(avoidanceStrength));
|
| 1627 |
+
direction.normalize();
|
| 1628 |
+
}
|
| 1629 |
+
|
| 1630 |
+
// ๋ชฉํ ํ์ ๊ณ์ฐ
|
| 1631 |
+
const targetYaw = Math.atan2(direction.x, direction.z);
|
| 1632 |
+
const targetPitch = Math.asin(-direction.y);
|
| 1633 |
+
|
| 1634 |
+
// ๋ถ๋๋ฌ์ด ํ์ (์ต๋ ํ์ ์๋ ์ ํ)
|
| 1635 |
+
const turnSpeed = isEmergency ? this.turnSpeed * 2.0 : (this.temporaryEvadeMode ? this.turnSpeed * 1.5 : this.turnSpeed);
|
| 1636 |
+
const maxTurnRate = turnSpeed * deltaTime;
|
| 1637 |
|
| 1638 |
// Yaw ํ์
|
| 1639 |
const yawDiff = this.normalizeAngle(targetYaw - this.rotation.y);
|
|
|
|
| 1643 |
this.rotation.y = targetYaw;
|
| 1644 |
}
|
| 1645 |
|
| 1646 |
+
// Pitch ํ์ (์ ํ์ )
|
| 1647 |
+
const maxPitchRate = maxTurnRate * 0.7;
|
| 1648 |
+
if (Math.abs(targetPitch - this.rotation.x) > maxPitchRate) {
|
| 1649 |
+
this.rotation.x += Math.sign(targetPitch - this.rotation.x) * maxPitchRate;
|
| 1650 |
} else {
|
| 1651 |
this.rotation.x = targetPitch;
|
| 1652 |
}
|
| 1653 |
|
| 1654 |
+
// Pitch ์ ํ (ยฑ40๋)
|
| 1655 |
+
const maxPitchAngle = Math.PI * 40 / 180;
|
| 1656 |
+
this.rotation.x = THREE.MathUtils.clamp(this.rotation.x, -maxPitchAngle, maxPitchAngle);
|
| 1657 |
+
|
| 1658 |
+
// ๋กค ์๋ ๊ณ์ฐ (์ ํ ์)
|
| 1659 |
+
if (!this.temporaryEvadeMode) {
|
| 1660 |
+
this.rotation.z = -yawDiff * 0.5;
|
| 1661 |
+
this.rotation.z = THREE.MathUtils.clamp(this.rotation.z, -Math.PI / 4, Math.PI / 4);
|
| 1662 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1663 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1664 |
|
| 1665 |
+
calculateAvoidance() {
|
| 1666 |
+
this.avoidanceVector.set(0, 0, 0);
|
| 1667 |
+
|
| 1668 |
+
if (!this.nearbyEnemies) return;
|
|
|
|
| 1669 |
|
| 1670 |
+
let avoidCount = 0;
|
| 1671 |
+
let criticalAvoidance = false;
|
| 1672 |
|
| 1673 |
+
this.nearbyEnemies.forEach(enemy => {
|
| 1674 |
+
if (enemy === this || !enemy.position) return;
|
|
|
|
| 1675 |
|
| 1676 |
+
const distance = this.position.distanceTo(enemy.position);
|
|
|
|
|
|
|
|
|
|
| 1677 |
|
| 1678 |
+
// 100m ๋ฏธ๋ง: ๊ธด๊ธ ํํผ
|
| 1679 |
+
if (distance < 100 && distance > 0) {
|
| 1680 |
+
criticalAvoidance = true;
|
| 1681 |
+
|
| 1682 |
+
// ๊ฐํ ๋ฐ๋ฐ๋ ฅ
|
| 1683 |
+
const avoidDir = this.position.clone().sub(enemy.position).normalize();
|
| 1684 |
+
const strength = 2.0; // ๋งค์ฐ ๊ฐํ ํํผ
|
| 1685 |
+
this.avoidanceVector.add(avoidDir.multiplyScalar(strength));
|
| 1686 |
+
|
| 1687 |
+
// ๊ณ ๋ ์ฐจ์ด ์ถ๊ฐ (์/์๋๋ก ๋ถ์ฐ)
|
| 1688 |
+
if (this.position.y > enemy.position.y) {
|
| 1689 |
+
this.avoidanceVector.y += 0.5; // ์๋ก
|
| 1690 |
+
} else {
|
| 1691 |
+
this.avoidanceVector.y -= 0.5; // ์๋๋ก
|
| 1692 |
+
}
|
| 1693 |
+
|
| 1694 |
+
avoidCount++;
|
| 1695 |
+
}
|
| 1696 |
+
// 100-300m: ์๋ฐฉ์ ํํผ
|
| 1697 |
+
else if (distance < 300) {
|
| 1698 |
+
// ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ํํผ
|
| 1699 |
+
const avoidDir = this.position.clone().sub(enemy.position).normalize();
|
| 1700 |
+
const strength = (300 - distance) / 200; // 100-300m ๋ฒ์์์ ๊ฐ๋ ๊ณ์ฐ
|
| 1701 |
+
this.avoidanceVector.add(avoidDir.multiplyScalar(strength));
|
| 1702 |
+
avoidCount++;
|
| 1703 |
}
|
| 1704 |
+
});
|
| 1705 |
+
|
| 1706 |
+
if (avoidCount > 0) {
|
| 1707 |
+
this.avoidanceVector.divideScalar(avoidCount);
|
| 1708 |
+
this.avoidanceVector.normalize();
|
| 1709 |
|
| 1710 |
+
// ๊ธด๊ธ ํํผ ์ ๋ ๊ฐํ ํํผ๋ ฅ ์ ์ฉ
|
| 1711 |
+
if (criticalAvoidance) {
|
| 1712 |
+
this.avoidanceVector.multiplyScalar(2.0);
|
| 1713 |
+
// ์ผ์์ ์ผ๋ก ์ ํฌ ์ํ ํด์
|
| 1714 |
+
this.temporaryEvadeMode = true;
|
| 1715 |
+
this.evadeTimer = 2.0; // 2์ด ๋์ ํํผ ์ฐ์
|
| 1716 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1717 |
}
|
| 1718 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1719 |
|
| 1720 |
+
updatePhysics(deltaTime) {
|
| 1721 |
+
if (!this.mesh) return;
|
| 1722 |
+
|
| 1723 |
+
// ์๋ ๋ฒกํฐ ๊ณ์ฐ (ํญ์ ์ ์ง)
|
| 1724 |
+
const forward = new THREE.Vector3(0, 0, 1);
|
| 1725 |
+
forward.applyEuler(this.rotation);
|
| 1726 |
+
|
| 1727 |
+
// ์๋ ์ ์ง (500-750kt, m/s๋ก ๋ณํ) - ๊ฐ์ ๋ก ์ต์ ์๋ ์ ์ง
|
| 1728 |
+
if (this.speed < this.minSpeed) {
|
| 1729 |
+
this.speed = this.minSpeed;
|
| 1730 |
+
}
|
| 1731 |
+
this.speed = THREE.MathUtils.clamp(this.speed, this.minSpeed, this.maxSpeed);
|
| 1732 |
+
|
| 1733 |
+
// ์๋ ๋ฒกํฐ ์์ฑ - ํญ์ ์ ์ง
|
| 1734 |
+
this.velocity = forward.multiplyScalar(this.speed);
|
| 1735 |
+
|
| 1736 |
+
// ์์น ์
๋ฐ์ดํธ - ํญ์ ์ด๋
|
| 1737 |
+
this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
|
| 1738 |
+
|
| 1739 |
+
// ๊ณ ๋ ์ ํ
|
| 1740 |
+
if (this.position.y < 500) {
|
| 1741 |
+
this.position.y = 500;
|
| 1742 |
+
this.rotation.x = -0.2; // ์์น
|
| 1743 |
+
} else if (this.position.y > 8000) {
|
| 1744 |
+
this.position.y = 8000;
|
| 1745 |
+
this.rotation.x = 0.2; // ํ๊ฐ
|
| 1746 |
+
}
|
| 1747 |
+
|
| 1748 |
+
// ๋งต ๊ฒฝ๊ณ ์ฒ๋ฆฌ
|
| 1749 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
| 1750 |
+
const boundaryBuffer = mapLimit * 0.9;
|
| 1751 |
+
|
| 1752 |
+
if (Math.abs(this.position.x) > boundaryBuffer || Math.abs(this.position.z) > boundaryBuffer) {
|
| 1753 |
+
// ๋งต ์ค์์ ํฅํด ํ์
|
| 1754 |
+
const centerDirection = new THREE.Vector3(-this.position.x, 0, -this.position.z).normalize();
|
| 1755 |
+
const targetYaw = Math.atan2(centerDirection.x, centerDirection.z);
|
| 1756 |
+
this.rotation.y = targetYaw;
|
| 1757 |
+
this.selectNewPatrolTarget(); // ์๋ก์ด ๋ชฉํ ์ ํ
|
| 1758 |
+
}
|
| 1759 |
+
|
| 1760 |
+
// ํ๋ ๋ฆฌ๋ฏธํธ
|
| 1761 |
+
this.position.x = THREE.MathUtils.clamp(this.position.x, -mapLimit, mapLimit);
|
| 1762 |
+
this.position.z = THREE.MathUtils.clamp(this.position.z, -mapLimit, mapLimit);
|
| 1763 |
+
|
| 1764 |
+
// ๋ฉ์ ์
๋ฐ์ดํธ
|
| 1765 |
+
this.mesh.position.copy(this.position);
|
| 1766 |
+
this.mesh.rotation.x = this.rotation.x;
|
| 1767 |
+
this.mesh.rotation.y = this.rotation.y + 3 * Math.PI / 2; // ํ๋ ์ด์ด์ ๋์ผํ ํ์ ์คํ์
|
| 1768 |
+
this.mesh.rotation.z = this.rotation.z;
|
| 1769 |
}
|
| 1770 |
|
| 1771 |
+
fireWeapon() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1772 |
const now = Date.now();
|
| 1773 |
|
| 1774 |
// 0.1์ด์ 1๋ฐ์ฉ, 10๋ฐ ์ฐ๋ฐ
|
|
|
|
| 1790 |
}
|
| 1791 |
}
|
| 1792 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1793 |
|
| 1794 |
+
shoot() {
|
| 1795 |
+
// ํํ ์์ฑ (ํ๋ ์ด์ด์ ๋์ผํ ํฌ๊ธฐ)
|
| 1796 |
+
const bulletGeometry = new THREE.CylinderGeometry(1.0, 1.0, 16, 8);
|
| 1797 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
| 1798 |
+
color: 0xff0000,
|
| 1799 |
+
});
|
| 1800 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
| 1801 |
+
|
| 1802 |
+
// ๊ธฐ์ ๋์์๋ง ๋ฐ์ฌ - ์ ํํ ์ ๋ฐฉ ์ค์์์
|
| 1803 |
+
const muzzleOffset = new THREE.Vector3(0, 0, 10); // X=0, Y=0์ผ๋ก ์ค์ ๊ณ ์
|
| 1804 |
+
muzzleOffset.applyEuler(this.rotation);
|
| 1805 |
+
bullet.position.copy(this.position).add(muzzleOffset);
|
| 1806 |
+
|
| 1807 |
+
// ํํ์ ๋ฐ์ฌ ๋ฐฉํฅ์ผ๋ก ํ์
|
| 1808 |
+
bullet.rotation.copy(this.rotation);
|
| 1809 |
+
bullet.rotateX(Math.PI / 2); // ์ค๋ฆฐ๋๊ฐ Z์ถ ๋ฐฉํฅ์ ํฅํ๋๋ก
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1810 |
|
| 1811 |
+
// ํํ ์ด๊ธฐ ์์น ์ ์ฅ
|
| 1812 |
+
bullet.startPosition = bullet.position.clone();
|
| 1813 |
+
|
| 1814 |
+
// ํํ ์๋ (ํ๋ ์ด์ด์ ๋์ผํ๊ฒ 1500) - ์ ํํ ์ ๋ฐฉ์ผ๋ก
|
| 1815 |
+
const direction = new THREE.Vector3(0, 0, 1);
|
| 1816 |
+
direction.applyEuler(this.rotation);
|
| 1817 |
+
bullet.velocity = direction.multiplyScalar(1500);
|
| 1818 |
+
|
| 1819 |
+
this.scene.add(bullet);
|
| 1820 |
+
this.bullets.push(bullet);
|
| 1821 |
+
|
| 1822 |
+
// ์ฌ์ด๋ ์ฌ์
|
| 1823 |
+
if (this.playerFighter) {
|
| 1824 |
+
const distanceToPlayer = this.position.distanceTo(this.playerFighter.position);
|
| 1825 |
+
if (distanceToPlayer < 3000) {
|
| 1826 |
+
try {
|
| 1827 |
+
const audio = new Audio('sounds/MGLAUNCH.ogg');
|
| 1828 |
+
const volumeMultiplier = 1 - (distanceToPlayer / 3000);
|
| 1829 |
+
audio.volume = 0.5 * volumeMultiplier;
|
| 1830 |
+
audio.play().catch(e => {});
|
| 1831 |
+
} catch (e) {}
|
| 1832 |
+
}
|
| 1833 |
}
|
| 1834 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1835 |
|
| 1836 |
+
updateBullets(deltaTime) {
|
| 1837 |
+
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
| 1838 |
+
const bullet = this.bullets[i];
|
| 1839 |
+
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
| 1840 |
+
|
| 1841 |
+
// ์ง๋ฉด ์ถฉ๋
|
| 1842 |
+
if (bullet.position.y <= 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1843 |
if (window.gameInstance) {
|
| 1844 |
+
window.gameInstance.createGroundImpactEffect(bullet.position);
|
| 1845 |
}
|
| 1846 |
+
this.scene.remove(bullet);
|
| 1847 |
+
this.bullets.splice(i, 1);
|
| 1848 |
+
continue;
|
| 1849 |
}
|
| 1850 |
+
|
| 1851 |
+
// ๊ฑฐ๋ฆฌ ์ ํ (ํ๋ ์ด์ด์ ๋์ผํ๊ฒ 6000m)
|
| 1852 |
+
if (bullet.position.distanceTo(bullet.startPosition) > 6000 ||
|
| 1853 |
+
bullet.position.y > GAME_CONSTANTS.MAX_ALTITUDE + 500) {
|
| 1854 |
+
this.scene.remove(bullet);
|
| 1855 |
+
this.bullets.splice(i, 1);
|
| 1856 |
}
|
|
|
|
|
|
|
| 1857 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1858 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1859 |
|
| 1860 |
+
calculateAimAccuracy(target) {
|
| 1861 |
+
const toTarget = target.clone().sub(this.position).normalize();
|
| 1862 |
+
const forward = new THREE.Vector3(0, 0, 1).applyEuler(this.rotation);
|
| 1863 |
+
const dotProduct = forward.dot(toTarget);
|
| 1864 |
+
return Math.acos(Math.max(-1, Math.min(1, dotProduct)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1865 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1866 |
|
| 1867 |
+
selectNewPatrolTarget() {
|
| 1868 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2 * 0.7;
|
| 1869 |
+
|
| 1870 |
+
// ๋ ๋ค์ํ ๊ณ ๋ ์ ํ
|
| 1871 |
+
const minAltitude = 1000;
|
| 1872 |
+
const maxAltitude = 6000;
|
| 1873 |
+
|
| 1874 |
+
this.targetPosition = new THREE.Vector3(
|
| 1875 |
+
(Math.random() - 0.5) * 2 * mapLimit,
|
| 1876 |
+
minAltitude + Math.random() * (maxAltitude - minAltitude),
|
| 1877 |
+
(Math.random() - 0.5) * 2 * mapLimit
|
| 1878 |
+
);
|
| 1879 |
+
}
|
| 1880 |
|
| 1881 |
+
selectEvadeTarget() {
|
| 1882 |
+
// ํ์ฌ ์์น์์ ๋๋ค ๋ฐฉํฅ์ผ๋ก ํํผ
|
| 1883 |
+
const evadeDistance = 1000 + Math.random() * 1000;
|
| 1884 |
+
const evadeAngle = Math.random() * Math.PI * 2;
|
| 1885 |
+
|
| 1886 |
+
this.targetPosition = new THREE.Vector3(
|
| 1887 |
+
this.position.x + Math.cos(evadeAngle) * evadeDistance,
|
| 1888 |
+
this.position.y + (Math.random() - 0.5) * 500,
|
| 1889 |
+
this.position.z + Math.sin(evadeAngle) * evadeDistance
|
| 1890 |
+
);
|
| 1891 |
+
|
| 1892 |
+
// ๋งต ๊ฒฝ๊ณ ํ์ธ
|
| 1893 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2 * 0.8;
|
| 1894 |
+
this.targetPosition.x = THREE.MathUtils.clamp(this.targetPosition.x, -mapLimit, mapLimit);
|
| 1895 |
+
this.targetPosition.z = THREE.MathUtils.clamp(this.targetPosition.z, -mapLimit, mapLimit);
|
| 1896 |
+
this.targetPosition.y = THREE.MathUtils.clamp(this.targetPosition.y, 1000, 6000);
|
| 1897 |
+
}
|
| 1898 |
|
| 1899 |
+
normalizeAngle(angle) {
|
| 1900 |
+
while (angle > Math.PI) angle -= Math.PI * 2;
|
| 1901 |
+
while (angle < -Math.PI) angle += Math.PI * 2;
|
| 1902 |
+
return angle;
|
| 1903 |
+
}
|
| 1904 |
|
| 1905 |
+
takeDamage(damage) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1906 |
console.log(`Enemy taking damage: ${damage}, Current health: ${this.health}`);
|
| 1907 |
this.health -= damage;
|
| 1908 |
console.log(`Enemy health after damage: ${this.health}`);
|
|
|
|
| 1910 |
console.log(`Enemy is dead: ${isDead}`);
|
| 1911 |
return isDead;
|
| 1912 |
}
|
| 1913 |
+
|
| 1914 |
+
destroy() {
|
| 1915 |
+
if (this.mesh) {
|
| 1916 |
+
this.scene.remove(this.mesh);
|
| 1917 |
+
this.bullets.forEach(bullet => this.scene.remove(bullet));
|
| 1918 |
+
this.bullets = [];
|
| 1919 |
+
this.isLoaded = false;
|
| 1920 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1921 |
}
|
| 1922 |
}
|
| 1923 |
|