cutechicken commited on
Commit
85cd92f
โ€ข
1 Parent(s): c8819a3

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +49 -31
game.js CHANGED
@@ -2150,25 +2150,26 @@ class Game {
2150
  }
2151
 
2152
  startGameTimer() {
2153
- if (this.gameTimer) {
2154
- clearInterval(this.gameTimer);
2155
- }
2156
-
2157
- this.gameTimer = setInterval(() => {
2158
- if (this.isLoading || this.isGameOver) {
2159
- clearInterval(this.gameTimer);
2160
- return;
2161
- }
2162
-
2163
- this.gameTime--;
2164
- document.getElementById('time').textContent = `Time: ${this.gameTime}s`;
2165
-
2166
- if (this.gameTime <= 0) {
2167
- clearInterval(this.gameTimer);
2168
- this.endGame();
2169
- }
2170
- }, 1000);
2171
- }
 
2172
 
2173
  spawnEnemies() {
2174
  const spawnEnemy = () => {
@@ -2445,33 +2446,49 @@ this.enemies.forEach(enemy => {
2445
  // ์ด์ „ ์œ„์น˜ ์ €์žฅ
2446
  this.previousTankPosition.copy(this.tank.body.position);
2447
  }
2448
- endGame() {
2449
  if (this.isGameOver) return;
2450
-
2451
  this.isGameOver = true;
2452
- // BGM ์ •์ง€
 
2453
  if (this.bgm) {
2454
  this.bgm.pause();
2455
  this.bgm = null;
2456
  this.bgmPlaying = false;
2457
  }
2458
-
2459
- // ์‚ฌ๋ง ์‚ฌ์šด๋“œ ์žฌ์ƒ
2460
- const deathSounds = ['sounds/death1.ogg', 'sounds/death2.ogg'];
2461
- const randomDeathSound = deathSounds[Math.floor(Math.random() * deathSounds.length)];
2462
- const deathAudio = new Audio(randomDeathSound);
2463
- deathAudio.play();
2464
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2465
  if (this.gameTimer) {
2466
  clearInterval(this.gameTimer);
2467
  }
2468
-
2469
  if (this.animationFrameId) {
2470
  cancelAnimationFrame(this.animationFrameId);
2471
  }
2472
 
2473
  document.exitPointerLock();
2474
 
 
2475
  const gameOverDiv = document.createElement('div');
2476
  gameOverDiv.style.position = 'absolute';
2477
  gameOverDiv.style.top = '50%';
@@ -2484,7 +2501,7 @@ this.enemies.forEach(enemy => {
2484
  gameOverDiv.style.borderRadius = '10px';
2485
  gameOverDiv.style.textAlign = 'center';
2486
  gameOverDiv.innerHTML = `
2487
- Game Over<br>
2488
  Score: ${this.score}<br>
2489
  Time Survived: ${GAME_DURATION - this.gameTime}s<br>
2490
  <button onclick="location.reload()"
@@ -2497,6 +2514,7 @@ this.enemies.forEach(enemy => {
2497
  document.body.appendChild(gameOverDiv);
2498
  }
2499
 
 
2500
  updateUI() {
2501
  if (!this.isGameOver) {
2502
  const healthBar = document.getElementById('health');
 
2150
  }
2151
 
2152
  startGameTimer() {
2153
+ if (this.gameTimer) {
2154
+ clearInterval(this.gameTimer);
2155
+ }
2156
+
2157
+ this.gameTimer = setInterval(() => {
2158
+ if (this.isLoading || this.isGameOver) {
2159
+ clearInterval(this.gameTimer);
2160
+ return;
2161
+ }
2162
+
2163
+ this.gameTime--;
2164
+ document.getElementById('time').textContent = `Time: ${this.gameTime}s`;
2165
+
2166
+ if (this.gameTime <= 0) {
2167
+ clearInterval(this.gameTimer);
2168
+ this.endGame(true); // ์Šน๋ฆฌ ์กฐ๊ฑด์œผ๋กœ endGame ํ˜ธ์ถœ
2169
+ }
2170
+ }, 1000);
2171
+ }
2172
+
2173
 
2174
  spawnEnemies() {
2175
  const spawnEnemy = () => {
 
2446
  // ์ด์ „ ์œ„์น˜ ์ €์žฅ
2447
  this.previousTankPosition.copy(this.tank.body.position);
2448
  }
2449
+ endGame(isVictory = false) {
2450
  if (this.isGameOver) return;
2451
+
2452
  this.isGameOver = true;
2453
+
2454
+ // ๋ชจ๋“  ์†Œ๋ฆฌ ์ •์ง€
2455
  if (this.bgm) {
2456
  this.bgm.pause();
2457
  this.bgm = null;
2458
  this.bgmPlaying = false;
2459
  }
2460
+ if (this.engineSound) {
2461
+ this.engineSound.pause();
2462
+ this.engineSound = null;
2463
+ }
2464
+ if (this.engineStopSound) {
2465
+ this.engineStopSound.pause();
2466
+ this.engineStopSound = null;
2467
+ }
2468
+
2469
+ // ์Šน๋ฆฌ/ํŒจ๋ฐฐ ์‚ฌ์šด๋“œ ์žฌ์ƒ
2470
+ if (isVictory) {
2471
+ const victoryAudio = new Audio('sounds/victory.ogg');
2472
+ victoryAudio.volume = 0.5;
2473
+ victoryAudio.play();
2474
+ } else {
2475
+ const deathSounds = ['sounds/death1.ogg', 'sounds/death2.ogg'];
2476
+ const randomDeathSound = deathSounds[Math.floor(Math.random() * deathSounds.length)];
2477
+ const deathAudio = new Audio(randomDeathSound);
2478
+ deathAudio.play();
2479
+ }
2480
+
2481
+ // ๊ฒŒ์ž„ ํƒ€์ด๋จธ ๋ฐ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ •์ง€
2482
  if (this.gameTimer) {
2483
  clearInterval(this.gameTimer);
2484
  }
 
2485
  if (this.animationFrameId) {
2486
  cancelAnimationFrame(this.animationFrameId);
2487
  }
2488
 
2489
  document.exitPointerLock();
2490
 
2491
+ // ๊ฒฐ๊ณผ ํ™”๋ฉด ํ‘œ์‹œ
2492
  const gameOverDiv = document.createElement('div');
2493
  gameOverDiv.style.position = 'absolute';
2494
  gameOverDiv.style.top = '50%';
 
2501
  gameOverDiv.style.borderRadius = '10px';
2502
  gameOverDiv.style.textAlign = 'center';
2503
  gameOverDiv.innerHTML = `
2504
+ ${isVictory ? 'Victory!' : 'Game Over'}<br>
2505
  Score: ${this.score}<br>
2506
  Time Survived: ${GAME_DURATION - this.gameTime}s<br>
2507
  <button onclick="location.reload()"
 
2514
  document.body.appendChild(gameOverDiv);
2515
  }
2516
 
2517
+
2518
  updateUI() {
2519
  if (!this.isGameOver) {
2520
  const healthBar = document.getElementById('health');