cutechicken commited on
Commit
b02c095
โ€ข
1 Parent(s): c4ac838

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +44 -31
game.js CHANGED
@@ -1712,16 +1712,27 @@ for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
1712
  // ์  ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1713
  this.enemies.forEach(enemy => {
1714
  if (!enemy.mesh || !enemy.isLoaded) return;
1715
-
1716
- const enemyBoundingBox = new THREE.Box3().setFromObject(enemy.mesh);
1717
- const enemyPreviousPosition = enemy.mesh.position.clone();
1718
-
1719
- this.obstacles.forEach(obstacle => {
1720
- if (obstacle.userData.isCollidable) { // ์ถฉ๋Œ ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด๋งŒ ๊ฒ€์‚ฌ
1721
- const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
1722
- if (enemyBoundingBox.intersectsBox(obstacleBoundingBox)) {
1723
- enemy.mesh.position.copy(enemyPreviousPosition);
 
 
1724
  }
 
 
 
 
 
 
 
 
 
1725
  }
1726
  });
1727
  });
@@ -1729,31 +1740,33 @@ this.enemies.forEach(enemy => {
1729
 
1730
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ
1731
  for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
1732
- const bullet = this.tank.bullets[i];
1733
- for (let j = this.enemies.length - 1; j >= 0; j--) {
1734
- const enemy = this.enemies[j];
1735
- if (!enemy.mesh || !enemy.isLoaded) continue;
1736
-
1737
- const distance = bullet.position.distanceTo(enemy.mesh.position);
1738
- if (distance < 2) {
1739
- // ์  ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
1740
- const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
1741
- const hitAudio = new Audio(randomHitSound);
1742
- hitAudio.play();
1743
-
1744
- if (enemy.takeDamage(50)) {
1745
- enemy.destroy();
1746
- this.enemies.splice(j, 1);
1747
- this.score += 100;
1748
- document.getElementById('score').textContent = `Score: ${this.score}`;
1749
- }
1750
- this.scene.remove(bullet);
1751
- this.tank.bullets.splice(i, 1);
1752
- this.createExplosion(bullet.position);
1753
- break; // ํ•˜๋‚˜์˜ ์ด์•Œ์ด ์—ฌ๋Ÿฌ ์ ์„ ๊ด€ํ†ตํ•˜์ง€ ์•Š๋„๋ก
1754
  }
 
 
 
 
 
 
 
1755
  }
1756
  }
 
1757
 
1758
  // ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ์™€ ์  ์ „์ฐจ ์ถฉ๋Œ ์ฒดํฌ
1759
  this.enemies.forEach(enemy => {
 
1712
  // ์  ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1713
  this.enemies.forEach(enemy => {
1714
  if (!enemy.mesh || !enemy.isLoaded) return;
1715
+
1716
+ enemy.bullets.forEach((bullet, bulletIndex) => {
1717
+ const distance = bullet.position.distanceTo(tankPosition);
1718
+ if (distance < 1) {
1719
+ // ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
1720
+ const randomBeatSound = beatSounds[Math.floor(Math.random() * beatSounds.length)];
1721
+ const beatAudio = new Audio(randomBeatSound);
1722
+ beatAudio.play();
1723
+
1724
+ if (this.tank.takeDamage(250)) {
1725
+ this.endGame();
1726
  }
1727
+
1728
+ // ๊ธฐ์กด์˜ createExplosion ๋Œ€์‹  createExplosionEffect ์‚ฌ์šฉ
1729
+ this.tank.createExplosionEffect(this.scene, bullet.position);
1730
+
1731
+ this.scene.remove(bullet);
1732
+ enemy.bullets.splice(bulletIndex, 1);
1733
+
1734
+ document.getElementById('health').style.width =
1735
+ `${(this.tank.health / MAX_HEALTH) * 100}%`;
1736
  }
1737
  });
1738
  });
 
1740
 
1741
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ
1742
  for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
1743
+ const bullet = this.tank.bullets[i];
1744
+ for (let j = this.enemies.length - 1; j >= 0; j--) {
1745
+ const enemy = this.enemies[j];
1746
+ if (!enemy.mesh || !enemy.isLoaded) continue;
1747
+
1748
+ const distance = bullet.position.distanceTo(enemy.mesh.position);
1749
+ if (distance < 2) {
1750
+ const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
1751
+ const hitAudio = new Audio(randomHitSound);
1752
+ hitAudio.play();
1753
+
1754
+ if (enemy.takeDamage(50)) {
1755
+ enemy.destroy();
1756
+ this.enemies.splice(j, 1);
1757
+ this.score += 100;
1758
+ document.getElementById('score').textContent = `Score: ${this.score}`;
 
 
 
 
 
 
1759
  }
1760
+
1761
+ // ์—ฌ๊ธฐ๋„ ๋™์ผํ•˜๊ฒŒ ์ˆ˜์ •
1762
+ this.tank.createExplosionEffect(this.scene, bullet.position);
1763
+
1764
+ this.scene.remove(bullet);
1765
+ this.tank.bullets.splice(i, 1);
1766
+ break;
1767
  }
1768
  }
1769
+ }
1770
 
1771
  // ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ์™€ ์  ์ „์ฐจ ์ถฉ๋Œ ์ฒดํฌ
1772
  this.enemies.forEach(enemy => {