cutechicken commited on
Commit
540deca
โ€ข
1 Parent(s): 8d7fbfa

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +44 -2
game.js CHANGED
@@ -862,6 +862,7 @@ class Game {
862
  this.renderer.shadowMap.enabled = true;
863
  this.renderer.shadowMap.type = THREE.PCFSoftShadowMap; // ๋ถ€๋“œ๋Ÿฌ์šด ๊ทธ๋ฆผ์ž
864
  this.renderer.outputColorSpace = THREE.SRGBColorSpace;
 
865
  document.getElementById('gameContainer').appendChild(this.renderer.domElement);
866
 
867
 
@@ -923,7 +924,7 @@ class Game {
923
  maxZ: mapBoundary
924
  };
925
  }
926
-
927
  async initialize() {
928
  try {
929
  // BGM์ด ์•„์ง ์žฌ์ƒ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋งŒ ์žฌ์ƒ
@@ -1837,6 +1838,47 @@ this.enemies.forEach(enemy => {
1837
  }
1838
  }
1839
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1840
 
1841
  animate() {
1842
  if (this.isGameOver) {
@@ -1869,7 +1911,7 @@ this.enemies.forEach(enemy => {
1869
  enemy.shoot(tankPosition);
1870
  }
1871
  });
1872
-
1873
  this.updateParticles();
1874
  this.checkCollisions();
1875
  this.updateUI();
 
862
  this.renderer.shadowMap.enabled = true;
863
  this.renderer.shadowMap.type = THREE.PCFSoftShadowMap; // ๋ถ€๋“œ๋Ÿฌ์šด ๊ทธ๋ฆผ์ž
864
  this.renderer.outputColorSpace = THREE.SRGBColorSpace;
865
+ this.enemyLabels = new Map(); // ์  ๋ผ๋ฒจ์„ ์ถ”์ ํ•˜๊ธฐ ์œ„ํ•œ Map ์ถ”๊ฐ€
866
  document.getElementById('gameContainer').appendChild(this.renderer.domElement);
867
 
868
 
 
924
  maxZ: mapBoundary
925
  };
926
  }
927
+
928
  async initialize() {
929
  try {
930
  // BGM์ด ์•„์ง ์žฌ์ƒ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋งŒ ์žฌ์ƒ
 
1838
  }
1839
  }
1840
  }
1841
+ updateEnemyLabels() {
1842
+ const labelsContainer = document.getElementById('enemyLabels');
1843
+
1844
+ // ๊ธฐ์กด ๋ผ๋ฒจ ๋ชจ๋‘ ์ œ๊ฑฐ
1845
+ labelsContainer.innerHTML = '';
1846
+
1847
+ this.enemies.forEach((enemy, index) => {
1848
+ if (!enemy.mesh || !enemy.isLoaded) return;
1849
+
1850
+ // ์  ์œ„์น˜๋ฅผ ํ™”๋ฉด ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
1851
+ const enemyPosition = enemy.mesh.position.clone();
1852
+ enemyPosition.y += 3; // ์  ๋จธ๋ฆฌ ์œ„์— ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ๋†’์ด ์กฐ์ •
1853
+
1854
+ const screenPosition = enemyPosition.project(this.camera);
1855
+
1856
+ // ํ™”๋ฉด์— ๋ณด์ด๋Š”์ง€ ํ™•์ธ
1857
+ if (screenPosition.z > 1) return; // ์นด๋ฉ”๋ผ ๋’ค์— ์žˆ๋Š” ๊ฒฝ์šฐ
1858
+
1859
+ // ์ ๊ณผ ํ”Œ๋ ˆ์ด์–ด ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
1860
+ const distance = enemy.mesh.position.distanceTo(this.tank.getPosition());
1861
+
1862
+ // ๋ ˆ์ด๋” ๋ฒ”์œ„ ๋‚ด์— ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ํ‘œ์‹œ
1863
+ if (distance <= this.radarRange) {
1864
+ const x = (screenPosition.x + 1) / 2 * window.innerWidth;
1865
+ const y = (-screenPosition.y + 1) / 2 * window.innerHeight;
1866
+
1867
+ // ๋ผ๋ฒจ ์ƒ์„ฑ
1868
+ const label = document.createElement('div');
1869
+ label.className = 'enemy-label';
1870
+ label.textContent = 'T-90';
1871
+ label.style.left = `${x}px`;
1872
+ label.style.top = `${y}px`;
1873
+
1874
+ // ๊ฑฐ๋ฆฌ์— ๋”ฐ๋ฅธ ํˆฌ๋ช…๋„ ์กฐ์ •
1875
+ const opacity = Math.max(0.2, 1 - (distance / this.radarRange));
1876
+ label.style.opacity = opacity;
1877
+
1878
+ labelsContainer.appendChild(label);
1879
+ }
1880
+ });
1881
+ }
1882
 
1883
  animate() {
1884
  if (this.isGameOver) {
 
1911
  enemy.shoot(tankPosition);
1912
  }
1913
  });
1914
+ this.updateEnemyLabels(); // ์  ๋ผ๋ฒจ ์—…๋ฐ์ดํŠธ ์ถ”๊ฐ€
1915
  this.updateParticles();
1916
  this.checkCollisions();
1917
  this.updateUI();