cutechicken commited on
Commit
65ff90d
โ€ข
1 Parent(s): 09bf3cb

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +31 -46
game.js CHANGED
@@ -1772,29 +1772,41 @@ class Game {
1772
  });
1773
 
1774
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1775
- this.enemies.forEach(enemy => {
1776
- if (!enemy.mesh || !enemy.isLoaded) return;
1777
 
1778
- enemy.bullets.forEach((bullet, bulletIndex) => {
1779
- const distance = bullet.position.distanceTo(tankPosition);
1780
- if (distance < 1) {
1781
- // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
1782
- const randomBeatSound = beatSounds[Math.floor(Math.random() * beatSounds.length)];
1783
- const beatAudio = new Audio(randomBeatSound);
1784
- beatAudio.play();
 
 
 
 
 
 
 
 
 
 
 
1785
 
1786
- if (this.tank.takeDamage(250)) {
1787
- this.endGame();
1788
- }
1789
- this.scene.remove(bullet);
1790
- enemy.bullets.splice(bulletIndex, 1); // filter ๋Œ€์‹  splice ์‚ฌ์šฉ
1791
-
1792
- this.createExplosion(bullet.position);
1793
- document.getElementById('health').style.width =
1794
- `${(this.tank.health / MAX_HEALTH) * 100}%`;
1795
  }
1796
- });
 
 
 
 
 
 
 
1797
  });
 
1798
 
1799
  // ํ”Œ๋ ˆ์ด์–ด ํฌํƒ„
1800
  // ํฌํƒ„๊ณผ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
@@ -1818,33 +1830,6 @@ for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
1818
  }
1819
  }
1820
 
1821
- // ์  ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1822
- this.enemies.forEach(enemy => {
1823
- if (!enemy.mesh || !enemy.isLoaded) return;
1824
-
1825
- enemy.bullets.forEach((bullet, bulletIndex) => {
1826
- const distance = bullet.position.distanceTo(tankPosition);
1827
- if (distance < 1) {
1828
- // ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
1829
- const randomBeatSound = beatSounds[Math.floor(Math.random() * beatSounds.length)];
1830
- const beatAudio = new Audio(randomBeatSound);
1831
- beatAudio.play();
1832
-
1833
- if (this.tank.takeDamage(250)) {
1834
- this.endGame();
1835
- }
1836
-
1837
- // ๊ธฐ์กด์˜ createExplosion ๋Œ€์‹  createExplosionEffect ์‚ฌ์šฉ
1838
- this.tank.createExplosionEffect(this.scene, bullet.position);
1839
-
1840
- this.scene.remove(bullet);
1841
- enemy.bullets.splice(bulletIndex, 1);
1842
-
1843
- document.getElementById('health').style.width =
1844
- `${(this.tank.health / MAX_HEALTH) * 100}%`;
1845
- }
1846
- });
1847
- });
1848
 
1849
 
1850
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ
 
1772
  });
1773
 
1774
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1775
+ this.enemies.forEach(enemy => {
1776
+ if (!enemy.mesh || !enemy.isLoaded) return;
1777
 
1778
+ enemy.bullets.forEach((bullet, bulletIndex) => {
1779
+ // ์ด์•Œ์˜ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ƒ์„ฑ
1780
+ const bulletBox = new THREE.Box3().setFromObject(bullet);
1781
+ // ๋ ˆ์ด์บ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์ด์ „ ์œ„์น˜ ๊ณ„์‚ฐ
1782
+ const prevPosition = bullet.position.clone().sub(bullet.velocity);
1783
+
1784
+ // ๋ ˆ์ด์บ์Šคํ„ฐ ์„ค์ •
1785
+ const raycaster = new THREE.Raycaster();
1786
+ raycaster.set(prevPosition, bullet.velocity.clone().normalize());
1787
+
1788
+ // ํƒฑํฌ ๋ชจ๋ธ๊ณผ์˜ ๊ต์ฐจ ๊ฒ€์‚ฌ
1789
+ const intersects = raycaster.intersectObject(this.tank.body, true);
1790
+
1791
+ if (intersects.length > 0 || tankBoundingBox.intersectsBox(bulletBox)) {
1792
+ // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
1793
+ const randomBeatSound = beatSounds[Math.floor(Math.random() * beatSounds.length)];
1794
+ const beatAudio = new Audio(randomBeatSound);
1795
+ beatAudio.play();
1796
 
1797
+ if (this.tank.takeDamage(250)) {
1798
+ this.endGame();
 
 
 
 
 
 
 
1799
  }
1800
+
1801
+ this.tank.createExplosionEffect(this.scene, bullet.position);
1802
+ this.scene.remove(bullet);
1803
+ enemy.bullets.splice(bulletIndex, 1);
1804
+
1805
+ document.getElementById('health').style.width =
1806
+ `${(this.tank.health / MAX_HEALTH) * 100}%`;
1807
+ }
1808
  });
1809
+ });
1810
 
1811
  // ํ”Œ๋ ˆ์ด์–ด ํฌํƒ„
1812
  // ํฌํƒ„๊ณผ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
 
1830
  }
1831
  }
1832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1833
 
1834
 
1835
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ