cutechicken commited on
Commit
0c1c5d6
β€’
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);