cutechicken commited on
Commit
2cd9fd9
ยท
verified ยท
1 Parent(s): 5e8c187

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +36 -101
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
- 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
 
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