Spaces:
Running
Running
Update game.js
Browse files
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 |
-
|
| 1717 |
-
|
| 1718 |
-
|
| 1719 |
-
|
| 1720 |
-
|
| 1721 |
-
const
|
| 1722 |
-
|
| 1723 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 1733 |
-
|
| 1734 |
-
|
| 1735 |
-
|
| 1736 |
-
|
| 1737 |
-
|
| 1738 |
-
|
| 1739 |
-
|
| 1740 |
-
|
| 1741 |
-
|
| 1742 |
-
|
| 1743 |
-
|
| 1744 |
-
|
| 1745 |
-
|
| 1746 |
-
|
| 1747 |
-
|
| 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 => {
|