Spaces:
Running
Running
cutechicken
commited on
Commit
โข
f35bcf4
1
Parent(s):
b3db824
Update game.js
Browse files
game.js
CHANGED
@@ -1756,29 +1756,36 @@ class Game {
|
|
1756 |
|
1757 |
// ์ ์ด์๊ณผ ํ๋ ์ด์ด ํฑํฌ ์ถฉ๋ ์ฒดํฌ
|
1758 |
this.enemies.forEach(enemy => {
|
1759 |
-
|
1760 |
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
|
|
|
|
1768 |
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
|
1773 |
-
|
1774 |
-
|
1775 |
-
this.
|
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 |
-
|
1841 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|