Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -1211,7 +1211,7 @@ class Game {
|
|
| 1211 |
}
|
| 1212 |
|
| 1213 |
// μμ§ μ μ§ μ¬μ΄λ μ¬μ
|
| 1214 |
-
this.engineStopSound = new Audio('sounds/
|
| 1215 |
this.engineStopSound.play();
|
| 1216 |
|
| 1217 |
// μμ§ μ μ§ μ¬μ΄λ μ’
λ£ ν μμ§ μ¬μ΄λ μμ
|
|
@@ -1466,14 +1466,12 @@ class Game {
|
|
| 1466 |
|
| 1467 |
// λͺ
μ€ μ¬μ΄λ λ°°μ΄ μ μ
|
| 1468 |
const hitSounds = [
|
| 1469 |
-
'sounds/hit1.ogg',
|
| 1470 |
-
'sounds/
|
| 1471 |
-
'sounds/hit3.ogg',
|
| 1472 |
-
'sounds/hit4.ogg',
|
| 1473 |
-
'sounds/hit5.ogg',
|
| 1474 |
-
'sounds/hit6.ogg',
|
| 1475 |
-
'sounds/hit7.ogg'
|
| 1476 |
];
|
|
|
|
|
|
|
|
|
|
| 1477 |
|
| 1478 |
const tankPosition = this.tank.getPosition();
|
| 1479 |
// μ μ΄μκ³Ό νλ μ΄μ΄ ν±ν¬ μΆ©λ 체ν¬
|
|
@@ -1483,10 +1481,10 @@ class Game {
|
|
| 1483 |
enemy.bullets.forEach(bullet => {
|
| 1484 |
const distance = bullet.position.distanceTo(tankPosition);
|
| 1485 |
if (distance < 1) {
|
| 1486 |
-
//
|
| 1487 |
-
const
|
| 1488 |
-
const
|
| 1489 |
-
|
| 1490 |
|
| 1491 |
if (this.tank.takeDamage(250)) { // λ°λ―Έμ§λ₯Ό 250μΌλ‘ μμ
|
| 1492 |
this.endGame();
|
|
@@ -1508,7 +1506,7 @@ class Game {
|
|
| 1508 |
|
| 1509 |
const distance = bullet.position.distanceTo(enemy.mesh.position);
|
| 1510 |
if (distance < 2) {
|
| 1511 |
-
//
|
| 1512 |
const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
|
| 1513 |
const hitAudio = new Audio(randomHitSound);
|
| 1514 |
hitAudio.play();
|
|
@@ -1541,44 +1539,50 @@ class Game {
|
|
| 1541 |
this.previousTankPosition.copy(this.tank.body.position);
|
| 1542 |
}
|
| 1543 |
endGame() {
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
-
|
| 1547 |
-
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1551 |
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
|
| 1555 |
|
| 1556 |
-
|
| 1557 |
-
|
| 1558 |
-
|
| 1559 |
-
|
| 1560 |
-
|
| 1561 |
-
|
| 1562 |
-
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
|
| 1567 |
-
|
| 1568 |
-
|
| 1569 |
-
|
| 1570 |
-
|
| 1571 |
-
|
| 1572 |
-
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
-
|
| 1579 |
-
|
| 1580 |
-
|
| 1581 |
-
|
| 1582 |
|
| 1583 |
updateUI() {
|
| 1584 |
if (!this.isGameOver) {
|
|
|
|
| 1211 |
}
|
| 1212 |
|
| 1213 |
// μμ§ μ μ§ μ¬μ΄λ μ¬μ
|
| 1214 |
+
this.engineStopSound = new Audio('sounds/engine.ogg');
|
| 1215 |
this.engineStopSound.play();
|
| 1216 |
|
| 1217 |
// μμ§ μ μ§ μ¬μ΄λ μ’
λ£ ν μμ§ μ¬μ΄λ μμ
|
|
|
|
| 1466 |
|
| 1467 |
// λͺ
μ€ μ¬μ΄λ λ°°μ΄ μ μ
|
| 1468 |
const hitSounds = [
|
| 1469 |
+
'sounds/hit1.ogg', 'sounds/hit2.ogg', 'sounds/hit3.ogg',
|
| 1470 |
+
'sounds/hit4.ogg', 'sounds/hit5.ogg', 'sounds/hit6.ogg', 'sounds/hit7.ogg'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1471 |
];
|
| 1472 |
+
|
| 1473 |
+
// νΌκ²© μ¬μ΄λ λ°°μ΄ μ μ
|
| 1474 |
+
const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
|
| 1475 |
|
| 1476 |
const tankPosition = this.tank.getPosition();
|
| 1477 |
// μ μ΄μκ³Ό νλ μ΄μ΄ ν±ν¬ μΆ©λ 체ν¬
|
|
|
|
| 1481 |
enemy.bullets.forEach(bullet => {
|
| 1482 |
const distance = bullet.position.distanceTo(tankPosition);
|
| 1483 |
if (distance < 1) {
|
| 1484 |
+
// νλ μ΄μ΄ νΌκ²© μ¬μ΄λ μ¬μ
|
| 1485 |
+
const randomBeatSound = beatSounds[Math.floor(Math.random() * beatSounds.length)];
|
| 1486 |
+
const beatAudio = new Audio(randomBeatSound);
|
| 1487 |
+
beatAudio.play();
|
| 1488 |
|
| 1489 |
if (this.tank.takeDamage(250)) { // λ°λ―Έμ§λ₯Ό 250μΌλ‘ μμ
|
| 1490 |
this.endGame();
|
|
|
|
| 1506 |
|
| 1507 |
const distance = bullet.position.distanceTo(enemy.mesh.position);
|
| 1508 |
if (distance < 2) {
|
| 1509 |
+
// μ νΌκ²© μ¬μ΄λ μ¬μ
|
| 1510 |
const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
|
| 1511 |
const hitAudio = new Audio(randomHitSound);
|
| 1512 |
hitAudio.play();
|
|
|
|
| 1539 |
this.previousTankPosition.copy(this.tank.body.position);
|
| 1540 |
}
|
| 1541 |
endGame() {
|
| 1542 |
+
if (this.isGameOver) return;
|
| 1543 |
+
|
| 1544 |
+
this.isGameOver = true;
|
| 1545 |
+
|
| 1546 |
+
// μ¬λ§ μ¬μ΄λ μ¬μ
|
| 1547 |
+
const deathSounds = ['sounds/death1.ogg', 'sounds/death2.ogg'];
|
| 1548 |
+
const randomDeathSound = deathSounds[Math.floor(Math.random() * deathSounds.length)];
|
| 1549 |
+
const deathAudio = new Audio(randomDeathSound);
|
| 1550 |
+
deathAudio.play();
|
| 1551 |
+
|
| 1552 |
+
if (this.gameTimer) {
|
| 1553 |
+
clearInterval(this.gameTimer);
|
| 1554 |
+
}
|
| 1555 |
|
| 1556 |
+
if (this.animationFrameId) {
|
| 1557 |
+
cancelAnimationFrame(this.animationFrameId);
|
| 1558 |
+
}
|
| 1559 |
|
| 1560 |
+
document.exitPointerLock();
|
| 1561 |
+
|
| 1562 |
+
const gameOverDiv = document.createElement('div');
|
| 1563 |
+
gameOverDiv.style.position = 'absolute';
|
| 1564 |
+
gameOverDiv.style.top = '50%';
|
| 1565 |
+
gameOverDiv.style.left = '50%';
|
| 1566 |
+
gameOverDiv.style.transform = 'translate(-50%, -50%)';
|
| 1567 |
+
gameOverDiv.style.color = '#0f0';
|
| 1568 |
+
gameOverDiv.style.fontSize = '48px';
|
| 1569 |
+
gameOverDiv.style.backgroundColor = 'rgba(0, 20, 0, 0.7)';
|
| 1570 |
+
gameOverDiv.style.padding = '20px';
|
| 1571 |
+
gameOverDiv.style.borderRadius = '10px';
|
| 1572 |
+
gameOverDiv.style.textAlign = 'center';
|
| 1573 |
+
gameOverDiv.innerHTML = `
|
| 1574 |
+
Game Over<br>
|
| 1575 |
+
Score: ${this.score}<br>
|
| 1576 |
+
Time Survived: ${GAME_DURATION - this.gameTime}s<br>
|
| 1577 |
+
<button onclick="location.reload()"
|
| 1578 |
+
style="font-size: 24px; padding: 10px; margin-top: 20px;
|
| 1579 |
+
cursor: pointer; background: #0f0; border: none;
|
| 1580 |
+
color: black; border-radius: 5px;">
|
| 1581 |
+
Play Again
|
| 1582 |
+
</button>
|
| 1583 |
+
`;
|
| 1584 |
+
document.body.appendChild(gameOverDiv);
|
| 1585 |
+
}
|
| 1586 |
|
| 1587 |
updateUI() {
|
| 1588 |
if (!this.isGameOver) {
|