Spaces:
Running
Running
cutechicken
commited on
Commit
β’
70004e8
1
Parent(s):
1413f15
Update game.js
Browse files
game.js
CHANGED
@@ -1120,56 +1120,56 @@ class Game {
|
|
1120 |
|
1121 |
// λ μ΄λ μ
λ°μ΄νΈ λ©μλ μΆκ°
|
1122 |
updateRadar() {
|
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 |
async addDesertDecorations() {
|
1175 |
if (!this.obstacles) {
|
@@ -1881,45 +1881,47 @@ this.enemies.forEach(enemy => {
|
|
1881 |
}
|
1882 |
|
1883 |
animate() {
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
}
|
1888 |
-
return;
|
1889 |
-
}
|
1890 |
-
|
1891 |
-
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
1892 |
-
// κ²μμ΄ μμλμ§ μμμΌλ©΄ λ λλ§λ§ μν
|
1893 |
-
if (!this.isStarted) {
|
1894 |
-
this.renderer.render(this.scene, this.camera);
|
1895 |
-
return;
|
1896 |
}
|
|
|
|
|
1897 |
|
1898 |
-
|
1899 |
-
|
1900 |
-
|
|
|
|
|
|
|
1901 |
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
const tankPosition = this.tank.getPosition();
|
1907 |
-
this.enemies.forEach(enemy => {
|
1908 |
-
enemy.update(tankPosition);
|
1909 |
-
|
1910 |
-
if (enemy.isLoaded && enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
|
1911 |
-
enemy.shoot(tankPosition);
|
1912 |
-
}
|
1913 |
-
});
|
1914 |
|
1915 |
-
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1923 |
}
|
1924 |
|
1925 |
// Start game
|
|
|
1120 |
|
1121 |
// λ μ΄λ μ
λ°μ΄νΈ λ©μλ μΆκ°
|
1122 |
updateRadar() {
|
1123 |
+
const currentTime = Date.now();
|
1124 |
+
if (currentTime - this.lastRadarUpdate < this.radarUpdateInterval) return;
|
1125 |
+
|
1126 |
+
const radar = document.getElementById('radar');
|
1127 |
+
const radarRect = radar.getBoundingClientRect();
|
1128 |
+
const radarCenter = {
|
1129 |
+
x: radarRect.width / 2,
|
1130 |
+
y: radarRect.height / 2
|
1131 |
+
};
|
1132 |
|
1133 |
+
// κΈ°μ‘΄ μ λνΈ μ κ±°
|
1134 |
+
const oldDots = radar.getElementsByClassName('enemy-dot');
|
1135 |
+
while (oldDots[0]) {
|
1136 |
+
oldDots[0].remove();
|
1137 |
+
}
|
1138 |
|
1139 |
+
// ν±ν¬ μμΉ κ°μ Έμ€κΈ°
|
1140 |
+
const tankPos = this.tank.getPosition();
|
1141 |
|
1142 |
+
// λͺ¨λ μ μ λν΄ λ μ΄λμ νμ
|
1143 |
+
this.enemies.forEach(enemy => {
|
1144 |
+
if (!enemy.isLoaded || !enemy.body) return;
|
1145 |
|
1146 |
+
const enemyPos = enemy.body.position;
|
1147 |
+
const distance = tankPos.distanceTo(enemyPos);
|
1148 |
|
1149 |
+
// λ μ΄λ λ²μ λ΄μ μλ κ²½μ°λ§ νμ
|
1150 |
+
if (distance <= this.radarRange) {
|
1151 |
+
// ν±ν¬ κΈ°μ€ μλ κ°λ κ³μ°
|
1152 |
+
const angle = Math.atan2(
|
1153 |
+
enemyPos.x - tankPos.x,
|
1154 |
+
enemyPos.z - tankPos.z
|
1155 |
+
);
|
1156 |
|
1157 |
+
// μλ 거리λ₯Ό λ μ΄λ ν¬κΈ°μ λ§κ² μ€μΌμΌλ§
|
1158 |
+
const relativeDistance = distance / this.radarRange;
|
1159 |
+
const dotX = radarCenter.x + Math.sin(angle) * (radarCenter.x * relativeDistance);
|
1160 |
+
const dotY = radarCenter.y + Math.cos(angle) * (radarCenter.y * relativeDistance);
|
1161 |
+
|
1162 |
+
// μ λνΈ μμ± λ° μΆκ°
|
1163 |
+
const dot = document.createElement('div');
|
1164 |
+
dot.className = 'enemy-dot';
|
1165 |
+
dot.style.left = `${dotX}px`;
|
1166 |
+
dot.style.top = `${dotY}px`;
|
1167 |
+
radar.appendChild(dot);
|
1168 |
+
}
|
1169 |
+
});
|
1170 |
|
1171 |
+
this.lastRadarUpdate = currentTime;
|
1172 |
+
}
|
1173 |
|
1174 |
async addDesertDecorations() {
|
1175 |
if (!this.obstacles) {
|
|
|
1881 |
}
|
1882 |
|
1883 |
animate() {
|
1884 |
+
if (this.isGameOver) {
|
1885 |
+
if (this.animationFrameId) {
|
1886 |
+
cancelAnimationFrame(this.animationFrameId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1887 |
}
|
1888 |
+
return;
|
1889 |
+
}
|
1890 |
|
1891 |
+
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
1892 |
+
// κ²μμ΄ μμλμ§ μμμΌλ©΄ λ λλ§λ§ μν
|
1893 |
+
if (!this.isStarted) {
|
1894 |
+
this.renderer.render(this.scene, this.camera);
|
1895 |
+
return;
|
1896 |
+
}
|
1897 |
|
1898 |
+
const currentTime = performance.now();
|
1899 |
+
const deltaTime = (currentTime - this.lastTime) / 1000;
|
1900 |
+
this.lastTime = currentTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1901 |
|
1902 |
+
if (!this.isLoading) {
|
1903 |
+
this.handleMovement();
|
1904 |
+
this.tank.update(this.mouse.x, this.mouse.y, this.scene);
|
1905 |
+
|
1906 |
+
const tankPosition = this.tank.getPosition();
|
1907 |
+
this.enemies.forEach(enemy => {
|
1908 |
+
if (enemy && enemy.isLoaded && enemy.body) { // body μ‘΄μ¬ μ¬λΆ νμΈ
|
1909 |
+
enemy.update(tankPosition);
|
1910 |
+
|
1911 |
+
const distanceToPlayer = enemy.body.position.distanceTo(tankPosition);
|
1912 |
+
if (distanceToPlayer < ENEMY_CONFIG.ATTACK_RANGE) {
|
1913 |
+
enemy.shoot(tankPosition);
|
1914 |
+
}
|
1915 |
+
}
|
1916 |
+
});
|
1917 |
+
|
1918 |
+
this.updateParticles();
|
1919 |
+
this.checkCollisions();
|
1920 |
+
this.updateUI();
|
1921 |
+
this.updateRadar();
|
1922 |
+
}
|
1923 |
+
|
1924 |
+
this.renderer.render(this.scene, this.camera);
|
1925 |
}
|
1926 |
|
1927 |
// Start game
|