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

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +17 -0
game.js CHANGED
@@ -1728,7 +1728,24 @@ class Game {
1728
  const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
1729
 
1730
  const tankPosition = this.tank.getPosition();
 
1731
  const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1732
 
1733
  // ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ (๊ฐœ์„ )
1734
  this.obstacles.forEach(obstacle => {
 
1728
  const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
1729
 
1730
  const tankPosition = this.tank.getPosition();
1731
+ // ์ „์ฒด ํƒฑํฌ ๋ชจ๋ธ์— ๋Œ€ํ•œ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ƒ์„ฑ
1732
  const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
1733
+ // ์—ฌ์œ  ๊ณต๊ฐ„์„ ์ฃผ๊ธฐ ์œ„ํ•ด ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ํ™•์žฅ
1734
+ tankBoundingBox.expandByScalar(1); // ๋ชจ๋“  ๋ฐฉํ–ฅ์œผ๋กœ 1์œ ๋‹› ํ™•์žฅ
1735
+ // ์  ํƒฑํฌ๋“ค์˜ ์ถฉ๋Œ ๊ฒ€์‚ฌ
1736
+ this.enemies.forEach(enemy => {
1737
+ if (!enemy.mesh || !enemy.isLoaded) return;
1738
+
1739
+ // ์  ํƒฑํฌ์˜ ์ „์ฒด ๋ชจ๋ธ์— ๋Œ€ํ•œ ๋ฐ”์šด๋”ฉ ๋ฐ•์Šค ์ƒ์„ฑ
1740
+ const enemyBoundingBox = new THREE.Box3().setFromObject(enemy.mesh);
1741
+ enemyBoundingBox.expandByScalar(1); // ์—ฌ์œ  ๊ณต๊ฐ„
1742
+
1743
+ // ํƒฑํฌ์™€ ์  ํƒฑํฌ ๊ฐ„์˜ ์ถฉ๋Œ ์ฒดํฌ
1744
+ if (tankBoundingBox.intersectsBox(enemyBoundingBox)) {
1745
+ // ์ถฉ๋Œ ์‹œ ์ด์ „ ์œ„์น˜๋กœ ๋ณต๊ท€
1746
+ this.tank.body.position.copy(this.previousTankPosition);
1747
+ }
1748
+ });
1749
 
1750
  // ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ (๊ฐœ์„ )
1751
  this.obstacles.forEach(obstacle => {