cutechicken commited on
Commit
a7148ee
โ€ข
1 Parent(s): 192b9c4

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +23 -19
game.js CHANGED
@@ -1444,21 +1444,23 @@ this.scene.add(ground);
1444
  // ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ๋ฐฐ์—ด ์ •์˜
1445
  const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
1446
 
1447
- // ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1448
- const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
1449
- this.obstacles.forEach(obstacle => {
1450
- const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
1451
- if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
1452
- const tankPosition = this.tank.getPosition();
1453
- //
1454
- }
 
1455
  }
1456
  });
 
1457
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1458
  this.enemies.forEach(enemy => {
1459
  if (!enemy.mesh || !enemy.isLoaded) return;
1460
 
1461
- enemy.bullets.forEach(bullet => {
1462
  const distance = bullet.position.distanceTo(tankPosition);
1463
  if (distance < 1) {
1464
  // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
@@ -1466,11 +1468,11 @@ this.scene.add(ground);
1466
  const beatAudio = new Audio(randomBeatSound);
1467
  beatAudio.play();
1468
 
1469
- if (this.tank.takeDamage(250)) { // ๋ฐ๋ฏธ์ง€๋ฅผ 250์œผ๋กœ ์ˆ˜์ •
1470
  this.endGame();
1471
  }
1472
  this.scene.remove(bullet);
1473
- enemy.bullets = enemy.bullets.filter(b => b !== bullet);
1474
 
1475
  this.createExplosion(bullet.position);
1476
  document.getElementById('health').style.width =
@@ -1480,9 +1482,11 @@ this.scene.add(ground);
1480
  });
1481
 
1482
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ
1483
- this.tank.bullets.forEach((bullet, bulletIndex) => {
1484
- this.enemies.forEach((enemy, enemyIndex) => {
1485
- if (!enemy.mesh || !enemy.isLoaded) return;
 
 
1486
 
1487
  const distance = bullet.position.distanceTo(enemy.mesh.position);
1488
  if (distance < 2) {
@@ -1493,19 +1497,19 @@ this.scene.add(ground);
1493
 
1494
  if (enemy.takeDamage(50)) {
1495
  enemy.destroy();
1496
- this.enemies.splice(enemyIndex, 1);
1497
  this.score += 100;
1498
  document.getElementById('score').textContent = `Score: ${this.score}`;
1499
  }
1500
  this.scene.remove(bullet);
1501
- this.tank.bullets.splice(bulletIndex, 1);
1502
  this.createExplosion(bullet.position);
 
1503
  }
1504
- });
1505
- });
1506
 
1507
  // ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ์™€ ์  ์ „์ฐจ ์ถฉ๋Œ ์ฒดํฌ
1508
- const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
1509
  this.enemies.forEach(enemy => {
1510
  if (!enemy.mesh || !enemy.isLoaded) return;
1511
 
 
1444
  // ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ๋ฐฐ์—ด ์ •์˜
1445
  const beatSounds = ['sounds/beat1.ogg', 'sounds/beat2.ogg', 'sounds/beat3.ogg'];
1446
 
1447
+ const tankPosition = this.tank.getPosition();
1448
+ const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
1449
+
1450
+ // ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ
1451
+ this.obstacles.forEach(obstacle => {
1452
+ const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
1453
+ if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
1454
+ // ์ถฉ๋Œ ์‹œ ์ด์ „ ์œ„์น˜๋กœ ๋˜๋Œ๋ฆฌ๊ธฐ
1455
+ this.tank.body.position.copy(this.previousTankPosition);
1456
  }
1457
  });
1458
+
1459
  // ์  ์ด์•Œ๊ณผ ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ ์ถฉ๋Œ ์ฒดํฌ
1460
  this.enemies.forEach(enemy => {
1461
  if (!enemy.mesh || !enemy.isLoaded) return;
1462
 
1463
+ enemy.bullets.forEach((bullet, bulletIndex) => {
1464
  const distance = bullet.position.distanceTo(tankPosition);
1465
  if (distance < 1) {
1466
  // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
 
1468
  const beatAudio = new Audio(randomBeatSound);
1469
  beatAudio.play();
1470
 
1471
+ if (this.tank.takeDamage(250)) {
1472
  this.endGame();
1473
  }
1474
  this.scene.remove(bullet);
1475
+ enemy.bullets.splice(bulletIndex, 1); // filter ๋Œ€์‹  splice ์‚ฌ์šฉ
1476
 
1477
  this.createExplosion(bullet.position);
1478
  document.getElementById('health').style.width =
 
1482
  });
1483
 
1484
  // ํ”Œ๋ ˆ์ด์–ด ์ด์•Œ๊ณผ ์  ์ถฉ๋Œ ์ฒดํฌ
1485
+ for (let i = this.tank.bullets.length - 1; i >= 0; i--) {
1486
+ const bullet = this.tank.bullets[i];
1487
+ for (let j = this.enemies.length - 1; j >= 0; j--) {
1488
+ const enemy = this.enemies[j];
1489
+ if (!enemy.mesh || !enemy.isLoaded) continue;
1490
 
1491
  const distance = bullet.position.distanceTo(enemy.mesh.position);
1492
  if (distance < 2) {
 
1497
 
1498
  if (enemy.takeDamage(50)) {
1499
  enemy.destroy();
1500
+ this.enemies.splice(j, 1);
1501
  this.score += 100;
1502
  document.getElementById('score').textContent = `Score: ${this.score}`;
1503
  }
1504
  this.scene.remove(bullet);
1505
+ this.tank.bullets.splice(i, 1);
1506
  this.createExplosion(bullet.position);
1507
+ break; // ํ•˜๋‚˜์˜ ์ด์•Œ์ด ์—ฌ๋Ÿฌ ์ ์„ ๊ด€ํ†ตํ•˜์ง€ ์•Š๋„๋ก
1508
  }
1509
+ }
1510
+ }
1511
 
1512
  // ํ”Œ๋ ˆ์ด์–ด ํƒฑํฌ์™€ ์  ์ „์ฐจ ์ถฉ๋Œ ์ฒดํฌ
 
1513
  this.enemies.forEach(enemy => {
1514
  if (!enemy.mesh || !enemy.isLoaded) return;
1515