cutechicken commited on
Commit
0c1c5d6
ยท
verified ยท
1 Parent(s): 5ad4224

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +71 -0
game.js CHANGED
@@ -735,12 +735,17 @@ class Particle {
735
  // Game ํด๋ž˜์Šค
736
  class Game {
737
  constructor() {
 
 
 
 
738
  this.scene = new THREE.Scene();
739
  this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
740
  this.renderer = new THREE.WebGLRenderer({ antialias: true });
741
  this.renderer.setSize(window.innerWidth, window.innerHeight);
742
  this.renderer.shadowMap.enabled = true;
743
  document.getElementById('gameContainer').appendChild(this.renderer.domElement);
 
744
 
745
  // ๋ ˆ์ด๋” ๊ด€๋ จ ์†์„ฑ ์ถ”๊ฐ€
746
  this.radarUpdateInterval = 100; // 100ms๋งˆ๋‹ค ๋ ˆ์ด๋” ์—…๋ฐ์ดํŠธ
@@ -777,6 +782,12 @@ class Game {
777
 
778
  async initialize() {
779
  try {
 
 
 
 
 
 
780
  // ์•ˆ๊ฐœ ํšจ๊ณผ ์ œ๊ฑฐ
781
  this.scene.fog = null;
782
  this.scene.background = new THREE.Color(0x87CEEB);
@@ -1186,6 +1197,45 @@ class Game {
1186
  if (!this.tank.isLoaded || this.isGameOver) return;
1187
 
1188
  const direction = new THREE.Vector3();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1189
 
1190
  // ์ฐจ์ฒด ์ด๋™๊ณผ ํšŒ์ „์€ ์œ ์ง€
1191
  if (this.keys.forward) direction.z += 1;
@@ -1414,6 +1464,17 @@ class Game {
1414
  checkCollisions() {
1415
  if (this.isLoading || !this.tank.isLoaded) return;
1416
 
 
 
 
 
 
 
 
 
 
 
 
1417
  const tankPosition = this.tank.getPosition();
1418
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1419
  this.enemies.forEach(enemy => {
@@ -1422,6 +1483,11 @@ class Game {
1422
  enemy.bullets.forEach(bullet => {
1423
  const distance = bullet.position.distanceTo(tankPosition);
1424
  if (distance < 1) {
 
 
 
 
 
1425
  if (this.tank.takeDamage(250)) { // ๋ฐ๋ฏธ์ง€๋ฅผ 250์œผ๋กœ ์ˆ˜์ •
1426
  this.endGame();
1427
  }
@@ -1442,6 +1508,11 @@ class Game {
1442
 
1443
  const distance = bullet.position.distanceTo(enemy.mesh.position);
1444
  if (distance < 2) {
 
 
 
 
 
1445
  if (enemy.takeDamage(50)) {
1446
  enemy.destroy();
1447
  this.enemies.splice(enemyIndex, 1);
 
735
  // Game ํด๋ž˜์Šค
736
  class Game {
737
  constructor() {
738
+ // ์˜ค๋””์˜ค ๊ด€๋ จ ์†์„ฑ ์ถ”๊ฐ€
739
+ this.engineSound = null;
740
+ this.engineStopSound = null;
741
+ this.isEngineRunning = false;
742
  this.scene = new THREE.Scene();
743
  this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
744
  this.renderer = new THREE.WebGLRenderer({ antialias: true });
745
  this.renderer.setSize(window.innerWidth, window.innerHeight);
746
  this.renderer.shadowMap.enabled = true;
747
  document.getElementById('gameContainer').appendChild(this.renderer.domElement);
748
+
749
 
750
  // ๋ ˆ์ด๋” ๊ด€๋ จ ์†์„ฑ ์ถ”๊ฐ€
751
  this.radarUpdateInterval = 100; // 100ms๋งˆ๋‹ค ๋ ˆ์ด๋” ์—…๋ฐ์ดํŠธ
 
782
 
783
  async initialize() {
784
  try {
785
+ // ์‹œ์ž‘ ์‚ฌ์šด๋“œ ์žฌ์ƒ
786
+ const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
787
+ const randomStartSound = startSounds[Math.floor(Math.random() * startSounds.length)];
788
+ const startAudio = new Audio(randomStartSound);
789
+ startAudio.volume = 0.5;
790
+ startAudio.play();
791
  // ์•ˆ๊ฐœ ํšจ๊ณผ ์ œ๊ฑฐ
792
  this.scene.fog = null;
793
  this.scene.background = new THREE.Color(0x87CEEB);
 
1197
  if (!this.tank.isLoaded || this.isGameOver) return;
1198
 
1199
  const direction = new THREE.Vector3();
1200
+ const isMoving = this.keys.forward || this.keys.backward;
1201
+ // ์ด๋™ ์‹œ์ž‘ํ•  ๋•Œ ์‚ฌ์šด๋“œ ์ฒ˜๋ฆฌ
1202
+ if (isMoving && !this.isEngineRunning) {
1203
+ this.isEngineRunning = true;
1204
+
1205
+ // ์ด์ „ ์‚ฌ์šด๋“œ ์ •์ง€
1206
+ if (this.engineStopSound) {
1207
+ this.engineStopSound.pause();
1208
+ }
1209
+ if (this.engineSound) {
1210
+ this.engineSound.pause();
1211
+ }
1212
+
1213
+ // ์—”์ง„ ์ •์ง€ ์‚ฌ์šด๋“œ ์žฌ์ƒ
1214
+ this.engineStopSound = new Audio('sounds/enginestop.ogg');
1215
+ this.engineStopSound.play();
1216
+
1217
+ // ์—”์ง„ ์ •์ง€ ์‚ฌ์šด๋“œ ์ข…๋ฃŒ ํ›„ ์—”์ง„ ์‚ฌ์šด๋“œ ์‹œ์ž‘
1218
+ this.engineStopSound.onended = () => {
1219
+ this.engineSound = new Audio('sounds/engine.ogg');
1220
+ this.engineSound.loop = true;
1221
+ this.engineSound.play();
1222
+ };
1223
+ }
1224
+ // ์ด๋™ ๋ฉˆ์ถœ ๋•Œ ์‚ฌ์šด๋“œ ์ฒ˜๋ฆฌ
1225
+ else if (!isMoving && this.isEngineRunning) {
1226
+ this.isEngineRunning = false;
1227
+ if (this.engineSound) {
1228
+ this.engineSound.pause();
1229
+ this.engineSound = null;
1230
+ }
1231
+ if (this.engineStopSound) {
1232
+ this.engineStopSound.pause();
1233
+ this.engineStopSound = null;
1234
+ }
1235
+ const stopSound = new Audio('sounds/enginestop.ogg');
1236
+ stopSound.play();
1237
+ }
1238
+
1239
 
1240
  // ์ฐจ์ฒด ์ด๋™๊ณผ ํšŒ์ „์€ ์œ ์ง€
1241
  if (this.keys.forward) direction.z += 1;
 
1464
  checkCollisions() {
1465
  if (this.isLoading || !this.tank.isLoaded) return;
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
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1480
  this.enemies.forEach(enemy => {
 
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();
1493
  }
 
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();
1515
+
1516
  if (enemy.takeDamage(50)) {
1517
  enemy.destroy();
1518
  this.enemies.splice(enemyIndex, 1);