cutechicken commited on
Commit
f35bcf4
โ€ข
1 Parent(s): b3db824

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +37 -23
game.js CHANGED
@@ -1756,29 +1756,36 @@ class Game {
1756
 
1757
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1758
  this.enemies.forEach(enemy => {
1759
- if (!enemy.mesh || !enemy.isLoaded) return;
1760
 
1761
- enemy.bullets.forEach((bullet, bulletIndex) => {
1762
- const distance = bullet.position.distanceTo(tankPosition);
1763
- if (distance < 1) {
1764
- // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
1765
- const randomBeatSound = beatSounds[Math.floor(Math.random() * beatSounds.length)];
1766
- const beatAudio = new Audio(randomBeatSound);
1767
- beatAudio.play();
 
 
1768
 
1769
- if (this.tank.takeDamage(250)) {
1770
- this.endGame();
1771
- }
1772
- this.scene.remove(bullet);
1773
- enemy.bullets.splice(bulletIndex, 1); // filter ๋Œ€์‹  splice ์‚ฌ์šฉ
1774
-
1775
- this.createExplosion(bullet.position);
1776
- document.getElementById('health').style.width =
1777
- `${(this.tank.health / MAX_HEALTH) * 100}%`;
1778
  }
1779
- });
 
 
 
 
 
 
 
1780
  });
1781
-
1782
  // ํ”Œ๋ ˆ์ด์–ด ํฌํƒ„
1783
  // ํฌํƒ„๊ณผ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1784
  for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
@@ -1837,8 +1844,17 @@ this.enemies.forEach(enemy => {
1837
  const enemy = this.enemies[j];
1838
  if (!enemy.mesh || !enemy.isLoaded) continue;
1839
 
1840
- const distance = bullet.position.distanceTo(enemy.mesh.position);
1841
- if (distance < 2) {
 
 
 
 
 
 
 
 
 
1842
  const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
1843
  const hitAudio = new Audio(randomHitSound);
1844
  hitAudio.play();
@@ -1850,9 +1866,7 @@ this.enemies.forEach(enemy => {
1850
  document.getElementById('score').textContent = `Score: ${this.score}`;
1851
  }
1852
 
1853
- // ์—ฌ๊ธฐ๋„ ๋™์ผํ•˜๊ฒŒ ์ˆ˜์ •
1854
  this.tank.createExplosionEffect(this.scene, bullet.position);
1855
-
1856
  this.scene.remove(bullet);
1857
  this.tank.bullets.splice(i, 1);
1858
  break;
 
1756
 
1757
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1758
  this.enemies.forEach(enemy => {
1759
+ if (!enemy.mesh || !enemy.isLoaded) return;
1760
 
1761
+ enemy.bullets.forEach((bullet, bulletIndex) => {
1762
+ // ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ์˜ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ƒ์„ฑ
1763
+ const tankBox = new THREE.Box3().setFromObject(this.tank.body);
1764
+ // ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ํฌ๊ธฐ ์กฐ์ •
1765
+ tankBox.min.x -= 1;
1766
+ tankBox.max.x += 1;
1767
+
1768
+ // ์ด์•Œ์˜ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ƒ์„ฑ
1769
+ const bulletBox = new THREE.Box3().setFromObject(bullet);
1770
 
1771
+ if (bulletBox.intersectsBox(tankBox)) {
1772
+ const randomBeatSound = beatSounds[Math.floor(Math.random() * beatSounds.length)];
1773
+ const beatAudio = new Audio(randomBeatSound);
1774
+ beatAudio.play();
1775
+
1776
+ if (this.tank.takeDamage(250)) {
1777
+ this.endGame();
 
 
1778
  }
1779
+
1780
+ this.tank.createExplosionEffect(this.scene, bullet.position);
1781
+ this.scene.remove(bullet);
1782
+ enemy.bullets.splice(bulletIndex, 1);
1783
+
1784
+ document.getElementById('health').style.width =
1785
+ `${(this.tank.health / MAX_HEALTH) * 100}%`;
1786
+ }
1787
  });
1788
+ });
1789
  // ํ”Œ๋ ˆ์ด์–ด ํฌํƒ„
1790
  // ํฌํƒ„๊ณผ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1791
  for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
 
1844
  const enemy = this.enemies[j];
1845
  if (!enemy.mesh || !enemy.isLoaded) continue;
1846
 
1847
+ // ์  ์ „์ฐจ์˜ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ƒ์„ฑ
1848
+ const enemyBox = new THREE.Box3().setFromObject(enemy.mesh);
1849
+ // ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ํฌ๊ธฐ ์กฐ์ • (ํญ์„ 2๋ฐฐ๋กœ)
1850
+ enemyBox.min.x -= 1;
1851
+ enemyBox.max.x += 1;
1852
+
1853
+ // ์ด์•Œ์˜ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ƒ์„ฑ
1854
+ const bulletBox = new THREE.Box3().setFromObject(bullet);
1855
+
1856
+ // ๋ฐ•์Šค ์ถฉ๋Œ ๊ฒ€์‚ฌ
1857
+ if (bulletBox.intersectsBox(enemyBox)) {
1858
  const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
1859
  const hitAudio = new Audio(randomHitSound);
1860
  hitAudio.play();
 
1866
  document.getElementById('score').textContent = `Score: ${this.score}`;
1867
  }
1868
 
 
1869
  this.tank.createExplosionEffect(this.scene, bullet.position);
 
1870
  this.scene.remove(bullet);
1871
  this.tank.bullets.splice(i, 1);
1872
  break;