Spaces:
Running
Running
cutechicken
commited on
Commit
โข
a7148ee
1
Parent(s):
192b9c4
Update game.js
Browse files
game.js
CHANGED
@@ -1444,21 +1444,23 @@ this.scene.add(ground);
|
|
1444 |
// ํผ๊ฒฉ ์ฌ์ด๋ ๋ฐฐ์ด ์ ์
|
1445 |
const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
|
1446 |
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
|
|
1455 |
}
|
1456 |
});
|
|
|
1457 |
// ์ ์ด์๊ณผ ํ๋ ์ด์ด ํฑํฌ ์ถฉ๋ ์ฒดํฌ
|
1458 |
this.enemies.forEach(enemy => {
|
1459 |
if (!enemy.mesh || !enemy.isLoaded) return;
|
1460 |
|
1461 |
-
enemy.bullets.forEach(bullet => {
|
1462 |
const distance = bullet.position.distanceTo(tankPosition);
|
1463 |
if (distance < 1) {
|
1464 |
// ํ๋ ์ด์ด ํผ๊ฒฉ ์ฌ์ด๋ ์ฌ์
|
@@ -1466,11 +1468,11 @@ this.scene.add(ground);
|
|
1466 |
const beatAudio = new Audio(randomBeatSound);
|
1467 |
beatAudio.play();
|
1468 |
|
1469 |
-
if (this.tank.takeDamage(250)) {
|
1470 |
this.endGame();
|
1471 |
}
|
1472 |
this.scene.remove(bullet);
|
1473 |
-
enemy.bullets
|
1474 |
|
1475 |
this.createExplosion(bullet.position);
|
1476 |
document.getElementById('health').style.width =
|
@@ -1480,9 +1482,11 @@ this.scene.add(ground);
|
|
1480 |
});
|
1481 |
|
1482 |
// ํ๋ ์ด์ด ์ด์๊ณผ ์ ์ถฉ๋ ์ฒดํฌ
|
1483 |
-
this.tank.bullets.
|
1484 |
-
this.
|
1485 |
-
|
|
|
|
|
1486 |
|
1487 |
const distance = bullet.position.distanceTo(enemy.mesh.position);
|
1488 |
if (distance < 2) {
|
@@ -1493,19 +1497,19 @@ this.scene.add(ground);
|
|
1493 |
|
1494 |
if (enemy.takeDamage(50)) {
|
1495 |
enemy.destroy();
|
1496 |
-
this.enemies.splice(
|
1497 |
this.score += 100;
|
1498 |
document.getElementById('score').textContent = `Score: ${this.score}`;
|
1499 |
}
|
1500 |
this.scene.remove(bullet);
|
1501 |
-
this.tank.bullets.splice(
|
1502 |
this.createExplosion(bullet.position);
|
|
|
1503 |
}
|
1504 |
-
}
|
1505 |
-
}
|
1506 |
|
1507 |
// ํ๋ ์ด์ด ํฑํฌ์ ์ ์ ์ฐจ ์ถฉ๋ ์ฒดํฌ
|
1508 |
-
const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
|
1509 |
this.enemies.forEach(enemy => {
|
1510 |
if (!enemy.mesh || !enemy.isLoaded) return;
|
1511 |
|
|
|
1444 |
// ํผ๊ฒฉ ์ฌ์ด๋ ๋ฐฐ์ด ์ ์
|
1445 |
const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
|
1446 |
|
1447 |
+
const tankPosition = this.tank.getPosition();
|
1448 |
+
const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
|
1449 |
+
|
1450 |
+
// ํฑํฌ์ ์ฅ์ ๋ฌผ ์ถฉ๋ ์ฒดํฌ
|
1451 |
+
this.obstacles.forEach(obstacle => {
|
1452 |
+
const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
|
1453 |
+
if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
|
1454 |
+
// ์ถฉ๋ ์ ์ด์ ์์น๋ก ๋๋๋ฆฌ๊ธฐ
|
1455 |
+
this.tank.body.position.copy(this.previousTankPosition);
|
1456 |
}
|
1457 |
});
|
1458 |
+
|
1459 |
// ์ ์ด์๊ณผ ํ๋ ์ด์ด ํฑํฌ ์ถฉ๋ ์ฒดํฌ
|
1460 |
this.enemies.forEach(enemy => {
|
1461 |
if (!enemy.mesh || !enemy.isLoaded) return;
|
1462 |
|
1463 |
+
enemy.bullets.forEach((bullet, bulletIndex) => {
|
1464 |
const distance = bullet.position.distanceTo(tankPosition);
|
1465 |
if (distance < 1) {
|
1466 |
// ํ๋ ์ด์ด ํผ๊ฒฉ ์ฌ์ด๋ ์ฌ์
|
|
|
1468 |
const beatAudio = new Audio(randomBeatSound);
|
1469 |
beatAudio.play();
|
1470 |
|
1471 |
+
if (this.tank.takeDamage(250)) {
|
1472 |
this.endGame();
|
1473 |
}
|
1474 |
this.scene.remove(bullet);
|
1475 |
+
enemy.bullets.splice(bulletIndex, 1); // filter ๋์ splice ์ฌ์ฉ
|
1476 |
|
1477 |
this.createExplosion(bullet.position);
|
1478 |
document.getElementById('health').style.width =
|
|
|
1482 |
});
|
1483 |
|
1484 |
// ํ๋ ์ด์ด ์ด์๊ณผ ์ ์ถฉ๋ ์ฒดํฌ
|
1485 |
+
for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
|
1486 |
+
const bullet = this.tank.bullets[i];
|
1487 |
+
for (let j = this.enemies.length - 1; j >= 0; j--) {
|
1488 |
+
const enemy = this.enemies[j];
|
1489 |
+
if (!enemy.mesh || !enemy.isLoaded) continue;
|
1490 |
|
1491 |
const distance = bullet.position.distanceTo(enemy.mesh.position);
|
1492 |
if (distance < 2) {
|
|
|
1497 |
|
1498 |
if (enemy.takeDamage(50)) {
|
1499 |
enemy.destroy();
|
1500 |
+
this.enemies.splice(j, 1);
|
1501 |
this.score += 100;
|
1502 |
document.getElementById('score').textContent = `Score: ${this.score}`;
|
1503 |
}
|
1504 |
this.scene.remove(bullet);
|
1505 |
+
this.tank.bullets.splice(i, 1);
|
1506 |
this.createExplosion(bullet.position);
|
1507 |
+
break; // ํ๋์ ์ด์์ด ์ฌ๋ฌ ์ ์ ๊ดํตํ์ง ์๋๋ก
|
1508 |
}
|
1509 |
+
}
|
1510 |
+
}
|
1511 |
|
1512 |
// ํ๋ ์ด์ด ํฑํฌ์ ์ ์ ์ฐจ ์ถฉ๋ ์ฒดํฌ
|
|
|
1513 |
this.enemies.forEach(enemy => {
|
1514 |
if (!enemy.mesh || !enemy.isLoaded) return;
|
1515 |
|