cutechicken commited on
Commit
3bb416a
β€’
1 Parent(s): 0c1c5d6

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +53 -49
game.js CHANGED
@@ -1211,7 +1211,7 @@ class Game {
1211
  }
1212
 
1213
  // 엔진 정지 μ‚¬μš΄λ“œ μž¬μƒ
1214
- this.engineStopSound = new Audio('sounds/enginestop.ogg');
1215
  this.engineStopSound.play();
1216
 
1217
  // 엔진 정지 μ‚¬μš΄λ“œ μ’…λ£Œ ν›„ 엔진 μ‚¬μš΄λ“œ μ‹œμž‘
@@ -1466,14 +1466,12 @@ class Game {
1466
 
1467
  // λͺ…쀑 μ‚¬μš΄λ“œ λ°°μ—΄ μ •μ˜
1468
  const hitSounds = [
1469
- 'sounds/hit1.ogg',
1470
- 'sounds/hit2.ogg',
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 randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
1488
- const hitAudio = new Audio(randomHitSound);
1489
- hitAudio.play();
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
- if (this.isGameOver) return;
1545
-
1546
- this.isGameOver = true;
1547
-
1548
- if (this.gameTimer) {
1549
- clearInterval(this.gameTimer);
1550
- }
 
 
 
 
 
 
1551
 
1552
- if (this.animationFrameId) {
1553
- cancelAnimationFrame(this.animationFrameId);
1554
- }
1555
 
1556
- document.exitPointerLock();
1557
-
1558
- const gameOverDiv = document.createElement('div');
1559
- gameOverDiv.style.position = 'absolute';
1560
- gameOverDiv.style.top = '50%';
1561
- gameOverDiv.style.left = '50%';
1562
- gameOverDiv.style.transform = 'translate(-50%, -50%)';
1563
- gameOverDiv.style.color = '#0f0';
1564
- gameOverDiv.style.fontSize = '48px';
1565
- gameOverDiv.style.backgroundColor = 'rgba(0, 20, 0, 0.7)';
1566
- gameOverDiv.style.padding = '20px';
1567
- gameOverDiv.style.borderRadius = '10px';
1568
- gameOverDiv.style.textAlign = 'center';
1569
- gameOverDiv.innerHTML = `
1570
- Game Over<br>
1571
- Score: ${this.score}<br>
1572
- Time Survived: ${GAME_DURATION - this.gameTime}s<br>
1573
- <button onclick="location.reload()"
1574
- style="font-size: 24px; padding: 10px; margin-top: 20px;
1575
- cursor: pointer; background: #0f0; border: none;
1576
- color: black; border-radius: 5px;">
1577
- Play Again
1578
- </button>
1579
- `;
1580
- document.body.appendChild(gameOverDiv);
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) {