Spaces:
Running
Running
cutechicken
commited on
Commit
โข
5e8c187
1
Parent(s):
4755951
Update game.js
Browse files
game.js
CHANGED
@@ -1170,6 +1170,8 @@ class Game {
|
|
1170 |
if (!this.tank || !this.tank.isLoaded) return;
|
1171 |
|
1172 |
const crosshair = document.getElementById('crosshair');
|
|
|
|
|
1173 |
const tankPosition = this.tank.getPosition();
|
1174 |
const turretRotation = this.tank.turretRotation;
|
1175 |
|
@@ -1184,8 +1186,8 @@ class Game {
|
|
1184 |
let closestDistance = Infinity;
|
1185 |
|
1186 |
// ๋ชจ๋ ์ ์ ๋ํด ๊ฒ์ฌ
|
1187 |
-
this.enemies
|
1188 |
-
if (!enemy.mesh || !enemy.isLoaded)
|
1189 |
|
1190 |
// ์ ๊ณผ์ ๋ฐฉํฅ ๋ฒกํฐ ๊ณ์ฐ
|
1191 |
const enemyVector = new THREE.Vector3()
|
@@ -1210,37 +1212,23 @@ class Game {
|
|
1210 |
closestDistance = Math.min(closestDistance, distance);
|
1211 |
}
|
1212 |
}
|
1213 |
-
}
|
1214 |
|
1215 |
// ํฌ๋ก์คํค์ด ์ํ ์
๋ฐ์ดํธ
|
1216 |
if (targetInSight) {
|
1217 |
-
if (!crosshair.classList.contains('target-locked')) {
|
1218 |
-
// ๋ชฉํ๋ฌผ ์กฐ์ค ์ ์ฌ์ด๋ ํจ๊ณผ
|
1219 |
-
const targetLockSound = new Audio('sounds/targetlock.ogg');
|
1220 |
-
targetLockSound.volume = 0.3;
|
1221 |
-
targetLockSound.play();
|
1222 |
-
|
1223 |
-
// ํฌ๋ก์คํค์ด ์ ๋๋ฉ์ด์
ํจ๊ณผ
|
1224 |
-
crosshair.style.transform = 'scale(1.2)';
|
1225 |
-
setTimeout(() => {
|
1226 |
-
crosshair.style.transform = 'scale(1)';
|
1227 |
-
}, 200);
|
1228 |
-
}
|
1229 |
-
|
1230 |
crosshair.classList.add('target-locked');
|
1231 |
|
1232 |
// ๊ฑฐ๋ฆฌ์ ๋ฐ๋ฅธ ํฌ๋ก์คํค์ด ํฌ๊ธฐ ์กฐ์
|
1233 |
-
const baseSize = 32;
|
1234 |
const size = baseSize * (1 + (100 - closestDistance) / 200);
|
1235 |
crosshair.style.width = `${size}px`;
|
1236 |
crosshair.style.height = `${size}px`;
|
1237 |
-
|
1238 |
} else {
|
1239 |
crosshair.classList.remove('target-locked');
|
1240 |
-
// ๊ธฐ๋ณธ ํฌ๊ธฐ๋ก ๋ณต๊ท
|
1241 |
crosshair.style.width = '32px';
|
1242 |
crosshair.style.height = '32px';
|
1243 |
}
|
|
|
1244 |
|
1245 |
// ๋ ์ด๋ ์
๋ฐ์ดํธ ๋ฉ์๋ ์ถ๊ฐ
|
1246 |
updateRadar() {
|
@@ -2059,45 +2047,47 @@ this.enemies.forEach(enemy => {
|
|
2059 |
}
|
2060 |
|
2061 |
animate() {
|
2062 |
-
|
2063 |
-
|
2064 |
-
|
2065 |
-
}
|
2066 |
-
return;
|
2067 |
-
}
|
2068 |
-
|
2069 |
-
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
2070 |
-
// ๊ฒ์์ด ์์๋์ง ์์์ผ๋ฉด ๋ ๋๋ง๋ง ์ํ
|
2071 |
-
if (!this.isStarted) {
|
2072 |
-
this.renderer.render(this.scene, this.camera);
|
2073 |
-
return;
|
2074 |
}
|
|
|
|
|
2075 |
|
2076 |
-
|
2077 |
-
const deltaTime = (currentTime - this.lastTime) / 1000;
|
2078 |
-
this.lastTime = currentTime;
|
2079 |
|
2080 |
-
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
2084 |
-
|
2085 |
-
|
2086 |
-
|
2087 |
-
|
2088 |
-
|
2089 |
-
|
2090 |
-
|
2091 |
-
|
2092 |
-
|
2093 |
-
|
2094 |
-
|
2095 |
-
|
2096 |
-
|
2097 |
-
|
2098 |
-
|
2099 |
-
|
2100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2101 |
}
|
2102 |
|
2103 |
// Start game
|
|
|
1170 |
if (!this.tank || !this.tank.isLoaded) return;
|
1171 |
|
1172 |
const crosshair = document.getElementById('crosshair');
|
1173 |
+
if (!crosshair) return; // crosshair ์์๊ฐ ์์ผ๋ฉด ๋ฆฌํด
|
1174 |
+
|
1175 |
const tankPosition = this.tank.getPosition();
|
1176 |
const turretRotation = this.tank.turretRotation;
|
1177 |
|
|
|
1186 |
let closestDistance = Infinity;
|
1187 |
|
1188 |
// ๋ชจ๋ ์ ์ ๋ํด ๊ฒ์ฌ
|
1189 |
+
for (const enemy of this.enemies) {
|
1190 |
+
if (!enemy.mesh || !enemy.isLoaded) continue;
|
1191 |
|
1192 |
// ์ ๊ณผ์ ๋ฐฉํฅ ๋ฒกํฐ ๊ณ์ฐ
|
1193 |
const enemyVector = new THREE.Vector3()
|
|
|
1212 |
closestDistance = Math.min(closestDistance, distance);
|
1213 |
}
|
1214 |
}
|
1215 |
+
}
|
1216 |
|
1217 |
// ํฌ๋ก์คํค์ด ์ํ ์
๋ฐ์ดํธ
|
1218 |
if (targetInSight) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1219 |
crosshair.classList.add('target-locked');
|
1220 |
|
1221 |
// ๊ฑฐ๋ฆฌ์ ๋ฐ๋ฅธ ํฌ๋ก์คํค์ด ํฌ๊ธฐ ์กฐ์
|
1222 |
+
const baseSize = 32;
|
1223 |
const size = baseSize * (1 + (100 - closestDistance) / 200);
|
1224 |
crosshair.style.width = `${size}px`;
|
1225 |
crosshair.style.height = `${size}px`;
|
|
|
1226 |
} else {
|
1227 |
crosshair.classList.remove('target-locked');
|
|
|
1228 |
crosshair.style.width = '32px';
|
1229 |
crosshair.style.height = '32px';
|
1230 |
}
|
1231 |
+
}
|
1232 |
|
1233 |
// ๋ ์ด๋ ์
๋ฐ์ดํธ ๋ฉ์๋ ์ถ๊ฐ
|
1234 |
updateRadar() {
|
|
|
2047 |
}
|
2048 |
|
2049 |
animate() {
|
2050 |
+
if (this.isGameOver) {
|
2051 |
+
if (this.animationFrameId) {
|
2052 |
+
cancelAnimationFrame(this.animationFrameId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2053 |
}
|
2054 |
+
return;
|
2055 |
+
}
|
2056 |
|
2057 |
+
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
|
|
|
|
2058 |
|
2059 |
+
// ๊ฒ์์ด ์์๋์ง ์์์ผ๋ฉด ๋ ๋๋ง๋ง ์ํ
|
2060 |
+
if (!this.isStarted) {
|
2061 |
+
this.renderer.render(this.scene, this.camera);
|
2062 |
+
return;
|
2063 |
+
}
|
2064 |
+
|
2065 |
+
const currentTime = performance.now();
|
2066 |
+
const deltaTime = (currentTime - this.lastTime) / 1000;
|
2067 |
+
this.lastTime = currentTime;
|
2068 |
+
|
2069 |
+
if (!this.isLoading) {
|
2070 |
+
this.handleMovement();
|
2071 |
+
this.tank.update(this.mouse.x, this.mouse.y, this.scene);
|
2072 |
+
this.checkTargetAlignment(); // ์กฐ์ค ์ ๋ ฌ ์ฒดํฌ ์ถ๊ฐ
|
2073 |
+
|
2074 |
+
const tankPosition = this.tank.getPosition();
|
2075 |
+
this.enemies.forEach(enemy => {
|
2076 |
+
enemy.update(tankPosition);
|
2077 |
+
|
2078 |
+
if (enemy.isLoaded && enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
|
2079 |
+
enemy.shoot(tankPosition);
|
2080 |
+
}
|
2081 |
+
});
|
2082 |
+
|
2083 |
+
this.updateEnemyLabels();
|
2084 |
+
this.updateParticles();
|
2085 |
+
this.checkCollisions();
|
2086 |
+
this.updateUI();
|
2087 |
+
this.updateRadar();
|
2088 |
+
}
|
2089 |
+
|
2090 |
+
this.renderer.render(this.scene, this.camera);
|
2091 |
}
|
2092 |
|
2093 |
// Start game
|