Spaces:
Running
Running
cutechicken
commited on
Update game.js
Browse files
game.js
CHANGED
@@ -1166,69 +1166,6 @@ class Game {
|
|
1166 |
this.handleLoadingError();
|
1167 |
}
|
1168 |
}
|
1169 |
-
checkTargetAlignment() {
|
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 |
-
|
1178 |
-
// ์กฐ์ค ๋ฐฉํฅ ๋ฒกํฐ ๊ณ์ฐ
|
1179 |
-
const aimVector = new THREE.Vector3(
|
1180 |
-
Math.sin(turretRotation),
|
1181 |
-
0,
|
1182 |
-
Math.cos(turretRotation)
|
1183 |
-
).normalize();
|
1184 |
-
|
1185 |
-
let targetInSight = false;
|
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()
|
1194 |
-
.subVectors(enemy.mesh.position, tankPosition)
|
1195 |
-
.normalize();
|
1196 |
-
|
1197 |
-
// ๋ ๋ฒกํฐ ์ฌ์ด์ ๊ฐ๋ ๊ณ์ฐ
|
1198 |
-
const angle = aimVector.angleTo(enemyVector);
|
1199 |
-
|
1200 |
-
// ๊ฑฐ๋ฆฌ ๊ณ์ฐ
|
1201 |
-
const distance = tankPosition.distanceTo(enemy.mesh.position);
|
1202 |
-
|
1203 |
-
// ๊ฐ๋๊ฐ ๋งค์ฐ ์๊ณ (๊ฑฐ์ ์ผ์ง์ ), ์ ์ ๊ฑฐ๋ฆฌ ๋ด์ ์์ ๋
|
1204 |
-
if (angle < 0.1 && distance < 100) {
|
1205 |
-
// ๋ ์ด์บ์คํธ๋ก ์ฅ์ ๋ฌผ ์ฒดํฌ
|
1206 |
-
const raycaster = new THREE.Raycaster(tankPosition, enemyVector);
|
1207 |
-
const intersects = raycaster.intersectObjects(this.obstacles);
|
1208 |
-
|
1209 |
-
// ์ฅ์ ๋ฌผ์ด ์์ผ๋ฉด ์กฐ์ค ๊ฐ๋ฅ ์ํ
|
1210 |
-
if (intersects.length === 0) {
|
1211 |
-
targetInSight = true;
|
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,47 +1984,45 @@ this.enemies.forEach(enemy => {
|
|
2047 |
}
|
2048 |
|
2049 |
animate() {
|
2050 |
-
|
2051 |
-
|
2052 |
-
|
2053 |
-
|
2054 |
-
|
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 |
-
|
2066 |
-
|
2067 |
-
|
|
|
|
|
|
|
2068 |
|
2069 |
-
|
2070 |
-
|
2071 |
-
|
2072 |
-
this.checkTargetAlignment(); // ์กฐ์ค ์ ๋ ฌ ์ฒดํฌ ์ถ๊ฐ
|
2073 |
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
|
2078 |
-
|
2079 |
-
|
2080 |
-
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
2084 |
-
|
2085 |
-
|
2086 |
-
|
2087 |
-
|
2088 |
-
|
2089 |
-
|
2090 |
-
|
|
|
|
|
|
|
|
|
2091 |
}
|
2092 |
|
2093 |
// Start game
|
|
|
1166 |
this.handleLoadingError();
|
1167 |
}
|
1168 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1169 |
|
1170 |
// ๋ ์ด๋ ์
๋ฐ์ดํธ ๋ฉ์๋ ์ถ๊ฐ
|
1171 |
updateRadar() {
|
|
|
1984 |
}
|
1985 |
|
1986 |
animate() {
|
1987 |
+
if (this.isGameOver) {
|
1988 |
+
if (this.animationFrameId) {
|
1989 |
+
cancelAnimationFrame(this.animationFrameId);
|
1990 |
+
}
|
1991 |
+
return;
|
1992 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1993 |
|
1994 |
+
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
1995 |
+
// ๊ฒ์์ด ์์๋์ง ์์์ผ๋ฉด ๋ ๋๋ง๋ง ์ํ
|
1996 |
+
if (!this.isStarted) {
|
1997 |
+
this.renderer.render(this.scene, this.camera);
|
1998 |
+
return;
|
1999 |
+
}
|
2000 |
|
2001 |
+
const currentTime = performance.now();
|
2002 |
+
const deltaTime = (currentTime - this.lastTime) / 1000;
|
2003 |
+
this.lastTime = currentTime;
|
|
|
2004 |
|
2005 |
+
if (!this.isLoading) {
|
2006 |
+
this.handleMovement();
|
2007 |
+
this.tank.update(this.mouse.x, this.mouse.y, this.scene);
|
2008 |
+
|
2009 |
+
const tankPosition = this.tank.getPosition();
|
2010 |
+
this.enemies.forEach(enemy => {
|
2011 |
+
enemy.update(tankPosition);
|
2012 |
+
|
2013 |
+
if (enemy.isLoaded && enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
|
2014 |
+
enemy.shoot(tankPosition);
|
2015 |
+
}
|
2016 |
+
});
|
2017 |
+
this.updateEnemyLabels(); // ์ ๋ผ๋ฒจ ์
๋ฐ์ดํธ ์ถ๊ฐ
|
2018 |
+
this.updateParticles();
|
2019 |
+
this.checkCollisions();
|
2020 |
+
this.updateUI();
|
2021 |
+
this.updateRadar(); // ๋ ์ด๋ ์
๋ฐ์ดํธ ์ถ๊ฐ
|
2022 |
+
}
|
2023 |
+
|
2024 |
+
this.renderer.render(this.scene, this.camera);
|
2025 |
+
}
|
2026 |
}
|
2027 |
|
2028 |
// Start game
|