cutechicken commited on
Commit
c7fc102
β€’
1 Parent(s): 23275ba

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +57 -51
game.js CHANGED
@@ -920,21 +920,22 @@ checkPathClear(start, end) {
920
 
921
  // μ‹œμ•Ό 확인 λ©”μ„œλ“œ (κΈ°μ‘΄ μ½”λ“œ μˆ˜μ •)
922
  checkLineOfSight(playerPosition) {
923
- if (!this.mesh) return false;
924
 
925
- const startPos = this.mesh.position.clone();
926
- startPos.y += 2; // 포탑 높이
927
- const direction = new THREE.Vector3()
928
- .subVectors(playerPosition, startPos)
929
- .normalize();
930
- const distance = startPos.distanceTo(playerPosition);
 
931
 
932
- const raycaster = new THREE.Raycaster(startPos, direction, 0, distance);
933
- const intersects = raycaster.intersectObjects(window.gameInstance.obstacles, true);
934
 
935
- // μž₯μ• λ¬Όκ³Όμ˜ 좩돌이 μžˆλŠ”μ§€ 확인
936
- return intersects.length === 0;
937
- }
938
  // λŒ€μ²΄ 경둜 μ°ΎκΈ° λ©”μ„œλ“œ
939
  findAlternativePath(playerPosition) {
940
  const currentPos = this.mesh.position.clone();
@@ -1577,7 +1578,7 @@ class Game {
1577
  this.obstacles = [];
1578
  }
1579
 
1580
- const BUILDING_COUNT = 70; // λ°”μœ„ λŒ€μ‹  건물둜 λ³€κ²½
1581
  const buildingModels = [
1582
  'models/house1.glb',
1583
  'models/house2.glb',
@@ -2373,47 +2374,52 @@ updateCrosshair() {
2373
  }
2374
 
2375
  animate() {
2376
- if (this.isGameOver) {
2377
- if (this.animationFrameId) {
2378
- cancelAnimationFrame(this.animationFrameId);
2379
- }
2380
- return;
2381
- }
2382
-
2383
- this.animationFrameId = requestAnimationFrame(() => this.animate());
2384
- // κ²Œμž„μ΄ μ‹œμž‘λ˜μ§€ μ•Šμ•˜μœΌλ©΄ λ Œλ”λ§λ§Œ μˆ˜ν–‰
2385
- if (!this.isStarted) {
2386
- this.renderer.render(this.scene, this.camera);
2387
- return;
2388
  }
 
 
2389
 
2390
- const currentTime = performance.now();
2391
- const deltaTime = (currentTime - this.lastTime) / 1000;
2392
- this.lastTime = currentTime;
 
 
 
 
2393
 
2394
- if (!this.isLoading) {
2395
- this.handleMovement();
2396
- this.tank.update(this.mouse.x, this.mouse.y, this.scene);
2397
-
2398
- const tankPosition = this.tank.getPosition();
2399
- this.enemies.forEach(enemy => {
2400
- enemy.update(tankPosition);
2401
-
2402
- if (enemy.isLoaded && enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
2403
- enemy.shoot(tankPosition);
2404
- }
2405
- });
2406
- this.updateEnemyLabels(); // 적 라벨 μ—…λ°μ΄νŠΈ μΆ”κ°€
2407
- this.updateParticles();
2408
- this.checkCollisions();
2409
- this.updateUI();
2410
- this.updateRadar(); // λ ˆμ΄λ” μ—…λ°μ΄νŠΈ μΆ”κ°€
2411
- // ν¬λ‘œμŠ€ν—€μ–΄ μ—…λ°μ΄νŠΈ μΆ”κ°€
2412
- this.updateCrosshair();
2413
- }
2414
-
2415
- this.renderer.render(this.scene, this.camera);
2416
- }
 
 
 
 
 
 
 
 
2417
  }
2418
 
2419
  // Start game
 
920
 
921
  // μ‹œμ•Ό 확인 λ©”μ„œλ“œ (κΈ°μ‘΄ μ½”λ“œ μˆ˜μ •)
922
  checkLineOfSight(playerPosition) {
923
+ if (!this.mesh) return false;
924
 
925
+ const startPos = this.mesh.position.clone();
926
+ startPos.y += 2; // 포탑 λ†’μ΄μ—μ„œ μ‹œμž‘
927
+
928
+ const direction = new THREE.Vector3()
929
+ .subVectors(playerPosition, startPos)
930
+ .normalize();
931
+ const distance = startPos.distanceTo(playerPosition);
932
 
933
+ const raycaster = new THREE.Raycaster(startPos, direction, 0, distance);
934
+ const intersects = raycaster.intersectObjects(window.gameInstance.obstacles, true);
935
 
936
+ // μž₯애물이 μžˆμ„ 경우 false λ°˜ν™˜
937
+ return intersects.length === 0;
938
+ }
939
  // λŒ€μ²΄ 경둜 μ°ΎκΈ° λ©”μ„œλ“œ
940
  findAlternativePath(playerPosition) {
941
  const currentPos = this.mesh.position.clone();
 
1578
  this.obstacles = [];
1579
  }
1580
 
1581
+ const BUILDING_COUNT = 50; // λ°”μœ„ λŒ€μ‹  건물둜 λ³€κ²½
1582
  const buildingModels = [
1583
  'models/house1.glb',
1584
  'models/house2.glb',
 
2374
  }
2375
 
2376
  animate() {
2377
+ if (this.isGameOver) {
2378
+ if (this.animationFrameId) {
2379
+ cancelAnimationFrame(this.animationFrameId);
 
 
 
 
 
 
 
 
 
2380
  }
2381
+ return;
2382
+ }
2383
 
2384
+ this.animationFrameId = requestAnimationFrame(() => this.animate());
2385
+
2386
+ // κ²Œμž„μ΄ μ‹œμž‘λ˜μ§€ μ•Šμ•˜μœΌλ©΄ λ Œλ”λ§λ§Œ μˆ˜ν–‰
2387
+ if (!this.isStarted) {
2388
+ this.renderer.render(this.scene, this.camera);
2389
+ return;
2390
+ }
2391
 
2392
+ const currentTime = performance.now();
2393
+ const deltaTime = (currentTime - this.lastTime) / 1000;
2394
+ this.lastTime = currentTime;
2395
+
2396
+ if (!this.isLoading) {
2397
+ this.handleMovement();
2398
+ this.tank.update(this.mouse.x, this.mouse.y, this.scene);
2399
+
2400
+ const tankPosition = this.tank.getPosition();
2401
+
2402
+ // 각 적 탱크 μ—…λ°μ΄νŠΈ
2403
+ this.enemies.forEach(enemy => {
2404
+ enemy.update(tankPosition);
2405
+
2406
+ // 적이 λ‘œλ“œλ˜μ—ˆκ³ , μ‹œμ•Ό ν™•λ³΄λ˜μ—ˆμ„ λ•Œλ§Œ λ°œμ‚¬
2407
+ if (enemy.isLoaded &&
2408
+ enemy.checkLineOfSight(tankPosition) &&
2409
+ enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
2410
+ enemy.shoot(tankPosition);
2411
+ }
2412
+ });
2413
+
2414
+ this.updateEnemyLabels();
2415
+ this.updateParticles();
2416
+ this.checkCollisions();
2417
+ this.updateUI();
2418
+ this.updateRadar();
2419
+ this.updateCrosshair();
2420
+ }
2421
+
2422
+ this.renderer.render(this.scene, this.camera);
2423
  }
2424
 
2425
  // Start game