cutechicken commited on
Commit
5e8c187
โ€ข
1 Parent(s): 4755951

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +45 -55
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.forEach(enemy => {
1188
- if (!enemy.mesh || !enemy.isLoaded) return;
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
- if (this.isGameOver) {
2063
- if (this.animationFrameId) {
2064
- cancelAnimationFrame(this.animationFrameId);
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
- const currentTime = performance.now();
2077
- const deltaTime = (currentTime - this.lastTime) / 1000;
2078
- this.lastTime = currentTime;
2079
 
2080
- if (!this.isLoading) {
2081
- this.handleMovement();
2082
- this.tank.update(this.mouse.x, this.mouse.y, this.scene);
2083
-
2084
- const tankPosition = this.tank.getPosition();
2085
- this.enemies.forEach(enemy => {
2086
- enemy.update(tankPosition);
2087
-
2088
- if (enemy.isLoaded && enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
2089
- enemy.shoot(tankPosition);
2090
- }
2091
- });
2092
- this.updateEnemyLabels(); // ์  ๋ผ๋ฒจ ์—…๋ฐ์ดํŠธ ์ถ”๊ฐ€
2093
- this.updateParticles();
2094
- this.checkCollisions();
2095
- this.updateUI();
2096
- this.updateRadar(); // ๋ ˆ์ด๋” ์—…๋ฐ์ดํŠธ ์ถ”๊ฐ€
2097
- }
2098
-
2099
- this.renderer.render(this.scene, this.camera);
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