cutechicken commited on
Commit
c4e294f
ยท
verified ยท
1 Parent(s): eddc1b1

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +41 -106
game.js CHANGED
@@ -2518,22 +2518,32 @@ class Game {
2518
 
2519
  const distance = bullet.position.distanceTo(enemy.position);
2520
  if (distance < 90) {
 
 
 
2521
  // ํžˆํŠธ ํ‘œ์‹œ ์ถ”๊ฐ€
2522
- this.showHitMarker(enemy.position);
2523
  // ํ”ผ๊ฒฉ ์ดํŽ™ํŠธ ์ถ”๊ฐ€
2524
- this.createHitEffect(enemy.position);
2525
 
2526
- // ํƒ„ํ™˜ ์ œ๊ฑฐ๋Š” ์ดํŽ™ํŠธ ์ƒ์„ฑ ํ›„์—
2527
  this.scene.remove(bullet);
2528
  this.fighter.bullets.splice(i, 1);
2529
 
2530
  if (enemy.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE)) {
2531
- // ์ ๊ธฐ ํŒŒ๊ดด ์‹œ ํญ๋ฐœ ํšจ๊ณผ ์ถ”๊ฐ€ - ์œ„์น˜ ํ™•์ธ
2532
- this.createExplosionEffect(enemy.position);
 
 
 
2533
 
 
2534
  enemy.destroy();
2535
  this.enemies.splice(j, 1);
2536
  this.score += 100;
 
 
 
2537
  }
2538
  break;
2539
  }
@@ -2546,16 +2556,20 @@ class Game {
2546
  const bullet = enemy.bullets[index];
2547
  const distance = bullet.position.distanceTo(this.fighter.position);
2548
  if (distance < 100) {
 
 
 
2549
  // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์ดํŽ™ํŠธ
2550
- this.createHitEffect(this.fighter.position);
2551
 
2552
  // ํƒ„ํ™˜ ์ œ๊ฑฐ
2553
  this.scene.remove(bullet);
2554
  enemy.bullets.splice(index, 1);
2555
 
2556
  if (this.fighter.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE)) {
 
2557
  // ํ”Œ๋ ˆ์ด์–ด ํŒŒ๊ดด ์‹œ ํญ๋ฐœ ํšจ๊ณผ ์ถ”๊ฐ€
2558
- this.createExplosionEffect(this.fighter.position);
2559
 
2560
  this.endGame(false);
2561
  }
@@ -2564,105 +2578,16 @@ class Game {
2564
  });
2565
  }
2566
 
2567
- createHitEffect(position) {
2568
- // ํ”ผ๊ฒฉ ํŒŒํ‹ฐํด ํšจ๊ณผ ์ƒ์„ฑ
2569
- const particleCount = 15;
2570
- const particles = [];
2571
-
2572
- for (let i = 0; i < particleCount; i++) {
2573
- const particleGeometry = new THREE.SphereGeometry(0.5, 4, 4);
2574
- const particleMaterial = new THREE.MeshBasicMaterial({
2575
- color: Math.random() > 0.5 ? 0xffaa00 : 0xff6600, // ์ฃผํ™ฉ์ƒ‰๊ณผ ๋ถ‰์€์ƒ‰ ํ˜ผํ•ฉ
2576
- emissive: 0xffaa00,
2577
- emissiveIntensity: 1.0,
2578
- transparent: true,
2579
- opacity: 1.0
2580
- });
2581
-
2582
- const particle = new THREE.Mesh(particleGeometry, particleMaterial);
2583
- particle.position.copy(position);
2584
-
2585
- // ๋žœ๋ค ์†๋„ ์„ค์ •
2586
- particle.velocity = new THREE.Vector3(
2587
- (Math.random() - 0.5) * 100,
2588
- (Math.random() - 0.5) * 100,
2589
- (Math.random() - 0.5) * 100
2590
- );
2591
-
2592
- particle.life = 1.0; // 1์ดˆ ๋™์•ˆ ์ง€์†
2593
-
2594
- this.scene.add(particle);
2595
- particles.push(particle);
2596
- }
2597
-
2598
- // ์ค‘์•™ ํญ๋ฐœ ํ”Œ๋ž˜์‹œ
2599
- const flashGeometry = new THREE.SphereGeometry(5, 8, 8);
2600
- const flashMaterial = new THREE.MeshBasicMaterial({
2601
- color: 0xffff00,
2602
- emissive: 0xffff00,
2603
- emissiveIntensity: 2.0,
2604
- transparent: true,
2605
- opacity: 0.8
2606
- });
2607
-
2608
- const flash = new THREE.Mesh(flashGeometry, flashMaterial);
2609
- flash.position.copy(position);
2610
- this.scene.add(flash);
2611
-
2612
- // ํŒŒํ‹ฐํด ์• ๋‹ˆ๋ฉ”์ด์…˜
2613
- const animateParticles = () => {
2614
- let allDead = true;
2615
-
2616
- particles.forEach(particle => {
2617
- if (particle.life > 0) {
2618
- allDead = false;
2619
- particle.life -= 0.02;
2620
-
2621
- // ์œ„์น˜ ์—…๋ฐ์ดํŠธ
2622
- particle.position.add(particle.velocity.clone().multiplyScalar(0.02));
2623
-
2624
- // ์ค‘๋ ฅ ํšจ๊ณผ
2625
- particle.velocity.y -= 2;
2626
-
2627
- // ํŽ˜์ด๋“œ ์•„์›ƒ
2628
- particle.material.opacity = particle.life;
2629
-
2630
- // ํฌ๊ธฐ ๊ฐ์†Œ
2631
- const scale = particle.life;
2632
- particle.scale.set(scale, scale, scale);
2633
- } else if (particle.parent) {
2634
- this.scene.remove(particle);
2635
- }
2636
- });
2637
-
2638
- // ํ”Œ๋ž˜์‹œ ํšจ๊ณผ
2639
- if (flash.material.opacity > 0) {
2640
- flash.material.opacity -= 0.05;
2641
- flash.scale.multiplyScalar(1.1);
2642
- } else if (flash.parent) {
2643
- this.scene.remove(flash);
2644
- }
2645
-
2646
- if (!allDead || flash.material.opacity > 0) {
2647
- requestAnimationFrame(animateParticles);
2648
- }
2649
- };
2650
-
2651
- animateParticles();
2652
-
2653
- // ํ”ผ๊ฒฉ ์‚ฌ์šด๋“œ ์žฌ์ƒ
2654
- try {
2655
- const hitSound = new Audio('sounds/hit.ogg');
2656
- hitSound.volume = 0.3;
2657
- hitSound.play().catch(e => {
2658
- console.log('Hit sound not found or failed to play');
2659
- });
2660
- } catch (e) {
2661
- console.log('Hit sound error:', e);
2662
- }
2663
  }
2664
 
2665
- createExplosionEffect(position) {
 
2666
  // ํญ๋ฐœ์Œ์„ ๊ฐ€์žฅ ๋จผ์ € ์žฌ์ƒ (์‹œ๊ฐํšจ๊ณผ๋ณด๋‹ค ์šฐ์„ )
2667
  try {
2668
  const explosionSound = new Audio('sounds/bang.ogg');
@@ -2671,10 +2596,18 @@ class Game {
2671
  // ์ฆ‰์‹œ ์žฌ์ƒ ์‹œ๋„
2672
  const playPromise = explosionSound.play();
2673
  if (playPromise !== undefined) {
2674
- playPromise.catch(e => console.log('Explosion sound failed:', e));
 
 
 
 
 
 
 
 
2675
  }
2676
  } catch (e) {
2677
- console.log('Explosion sound error:', e);
2678
  }
2679
 
2680
  // ๋ฉ”์ธ ํญ๋ฐœ ํ”Œ๋ž˜์‹œ
@@ -2758,6 +2691,8 @@ class Game {
2758
  smoke.push(smokePuff);
2759
  }
2760
 
 
 
2761
  // ์• ๋‹ˆ๋ฉ”์ด์…˜
2762
  const animateExplosion = () => {
2763
  let allDead = true;
 
2518
 
2519
  const distance = bullet.position.distanceTo(enemy.position);
2520
  if (distance < 90) {
2521
+ // ์ ๊ธฐ ์œ„์น˜๋ฅผ ๋ฏธ๋ฆฌ ์ €์žฅ (์ค‘์š”!)
2522
+ const explosionPosition = enemy.position.clone();
2523
+
2524
  // ํžˆํŠธ ํ‘œ์‹œ ์ถ”๊ฐ€
2525
+ this.showHitMarker(explosionPosition);
2526
  // ํ”ผ๊ฒฉ ์ดํŽ™ํŠธ ์ถ”๊ฐ€
2527
+ this.createHitEffect(explosionPosition);
2528
 
2529
+ // ํƒ„ํ™˜ ์ œ๊ฑฐ
2530
  this.scene.remove(bullet);
2531
  this.fighter.bullets.splice(i, 1);
2532
 
2533
  if (enemy.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE)) {
2534
+ // ๋””๋ฒ„๊น…์šฉ ๋กœ๊ทธ ์ถ”๊ฐ€
2535
+ console.log('Enemy destroyed! Creating explosion at:', explosionPosition);
2536
+
2537
+ // ์ ๊ธฐ ํŒŒ๊ดด ์‹œ ํญ๋ฐœ ํšจ๊ณผ ์ถ”๊ฐ€ - ์ €์žฅ๋œ ์œ„์น˜ ์‚ฌ์šฉ
2538
+ this.createExplosionEffect(explosionPosition);
2539
 
2540
+ // ์ ๊ธฐ ์ œ๊ฑฐ
2541
  enemy.destroy();
2542
  this.enemies.splice(j, 1);
2543
  this.score += 100;
2544
+
2545
+ // ์ถ”๊ฐ€ ๋””๋ฒ„๊น…
2546
+ console.log('Enemies remaining:', this.enemies.length);
2547
  }
2548
  break;
2549
  }
 
2556
  const bullet = enemy.bullets[index];
2557
  const distance = bullet.position.distanceTo(this.fighter.position);
2558
  if (distance < 100) {
2559
+ // ํ”Œ๋ ˆ์ด์–ด ์œ„์น˜ ์ €์žฅ
2560
+ const playerPosition = this.fighter.position.clone();
2561
+
2562
  // ํ”Œ๋ ˆ์ด์–ด ํ”ผ๊ฒฉ ์ดํŽ™ํŠธ
2563
+ this.createHitEffect(playerPosition);
2564
 
2565
  // ํƒ„ํ™˜ ์ œ๊ฑฐ
2566
  this.scene.remove(bullet);
2567
  enemy.bullets.splice(index, 1);
2568
 
2569
  if (this.fighter.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE)) {
2570
+ console.log('Player destroyed! Creating explosion');
2571
  // ํ”Œ๋ ˆ์ด์–ด ํŒŒ๊ดด ์‹œ ํญ๋ฐœ ํšจ๊ณผ ์ถ”๊ฐ€
2572
+ this.createExplosionEffect(playerPosition);
2573
 
2574
  this.endGame(false);
2575
  }
 
2578
  });
2579
  }
2580
 
2581
+ // createExplosionEffect ๋ฉ”์„œ๋“œ ๊ฐœ์„ 
2582
+ createExplosionEffect(position) {
2583
+ // ์œ„์น˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
2584
+ if (!position || !position.x === undefined) {
2585
+ console.error('Invalid position for explosion effect');
2586
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2587
  }
2588
 
2589
+ console.log('Creating explosion effect at position:', position);
2590
+
2591
  // ํญ๋ฐœ์Œ์„ ๊ฐ€์žฅ ๋จผ์ € ์žฌ์ƒ (์‹œ๊ฐํšจ๊ณผ๋ณด๋‹ค ์šฐ์„ )
2592
  try {
2593
  const explosionSound = new Audio('sounds/bang.ogg');
 
2596
  // ์ฆ‰์‹œ ์žฌ์ƒ ์‹œ๋„
2597
  const playPromise = explosionSound.play();
2598
  if (playPromise !== undefined) {
2599
+ playPromise.then(() => {
2600
+ console.log('Explosion sound played successfully');
2601
+ }).catch(e => {
2602
+ console.error('Explosion sound failed:', e);
2603
+ // ์˜ค๋””์˜ค ์ปจํ…์ŠคํŠธ ๋ฌธ์ œ์ผ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ ํ›„ ์žฌ์‹œ๋„
2604
+ document.addEventListener('click', () => {
2605
+ explosionSound.play().catch(err => console.error('Retry failed:', err));
2606
+ }, { once: true });
2607
+ });
2608
  }
2609
  } catch (e) {
2610
+ console.error('Explosion sound error:', e);
2611
  }
2612
 
2613
  // ๋ฉ”์ธ ํญ๋ฐœ ํ”Œ๋ž˜์‹œ
 
2691
  smoke.push(smokePuff);
2692
  }
2693
 
2694
+ console.log('Explosion visual effects created');
2695
+
2696
  // ์• ๋‹ˆ๋ฉ”์ด์…˜
2697
  const animateExplosion = () => {
2698
  let allDead = true;