Spaces:
Running
Running
cutechicken
commited on
Commit
โข
65ff90d
1
Parent(s):
09bf3cb
Update game.js
Browse files
game.js
CHANGED
@@ -1772,29 +1772,41 @@ class Game {
|
|
1772 |
});
|
1773 |
|
1774 |
// ์ ์ด์๊ณผ ํ๋ ์ด์ด ํฑํฌ ์ถฉ๋ ์ฒดํฌ
|
1775 |
-
|
1776 |
-
|
1777 |
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
1781 |
-
|
1782 |
-
|
1783 |
-
|
1784 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1785 |
|
1786 |
-
|
1787 |
-
|
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 |
// ํ๋ ์ด์ด ์ด์๊ณผ ์ ์ถฉ๋ ์ฒดํฌ
|