cutechicken commited on
Commit
f1d4463
ยท
verified ยท
1 Parent(s): 1e0cdac

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +37 -0
game.js CHANGED
@@ -2504,6 +2504,43 @@ class Game {
2504
  }
2505
  }
2506
  checkCollisions() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2507
  // ํ”Œ๋ ˆ์ด์–ด ํƒ„ํ™˜ vs ์ ๊ธฐ ์ถฉ๋Œ
2508
  for (let i = this.fighter.bullets.length - 1; i >= 0; i--) {
2509
  const bullet = this.fighter.bullets[i];
 
2504
  }
2505
  }
2506
  checkCollisions() {
2507
+ // ํ”Œ๋ ˆ์ด์–ด์™€ ์ ๊ธฐ์˜ ์ง์ ‘ ์ถฉ๋Œ ์ฒดํฌ (์ตœ์šฐ์„ )
2508
+ for (let i = this.enemies.length - 1; i >= 0; i--) {
2509
+ const enemy = this.enemies[i];
2510
+ if (!enemy.mesh || !enemy.isLoaded) continue;
2511
+
2512
+ const distance = this.fighter.position.distanceTo(enemy.position);
2513
+ // ์ง์ ‘ ์ถฉ๋Œ ํŒ์ • (100m ์ด๋‚ด)
2514
+ if (distance < 100) {
2515
+ console.log('Direct collision detected! Distance:', distance);
2516
+
2517
+ // ์–‘์ชฝ ๋ชจ๋‘์˜ ์œ„์น˜ ์ €์žฅ
2518
+ const playerExplosionPos = this.fighter.position.clone();
2519
+ const enemyExplosionPos = enemy.position.clone();
2520
+
2521
+ // ์–‘์ชฝ ๋ชจ๋‘ ์ฆ‰์‹œ ํŒŒ๊ดด
2522
+ // 1. ์ ๊ธฐ ํŒŒ๊ดด
2523
+ this.createExplosionEffect(enemyExplosionPos);
2524
+ enemy.destroy();
2525
+ this.enemies.splice(i, 1);
2526
+ this.score += 100;
2527
+
2528
+ // 2. ํ”Œ๋ ˆ์ด์–ด ํŒŒ๊ดด
2529
+ this.createExplosionEffect(playerExplosionPos);
2530
+ this.fighter.health = 0;
2531
+
2532
+ // ์ถฉ๋Œ์Œ ์žฌ์ƒ
2533
+ try {
2534
+ const collisionSound = new Audio('sounds/bang.ogg');
2535
+ collisionSound.volume = 1.0;
2536
+ collisionSound.play().catch(e => {});
2537
+ } catch (e) {}
2538
+
2539
+ this.endGame(false, "COLLISION WITH ENEMY");
2540
+ return; // ์ถฉ๋Œ ์ฒ˜๋ฆฌ ํ›„ ์ฆ‰์‹œ ์ข…๋ฃŒ
2541
+ }
2542
+ }
2543
+
2544
  // ํ”Œ๋ ˆ์ด์–ด ํƒ„ํ™˜ vs ์ ๊ธฐ ์ถฉ๋Œ
2545
  for (let i = this.fighter.bullets.length - 1; i >= 0; i--) {
2546
  const bullet = this.fighter.bullets[i];