Spaces:
Running
Running
Update game.js
Browse files
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(
|
| 2523 |
// ํผ๊ฒฉ ์ดํํธ ์ถ๊ฐ
|
| 2524 |
-
this.createHitEffect(
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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(
|
| 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(
|
| 2559 |
|
| 2560 |
this.endGame(false);
|
| 2561 |
}
|
|
@@ -2564,105 +2578,16 @@ class Game {
|
|
| 2564 |
});
|
| 2565 |
}
|
| 2566 |
|
| 2567 |
-
|
| 2568 |
-
|
| 2569 |
-
|
| 2570 |
-
|
| 2571 |
-
|
| 2572 |
-
|
| 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 |
-
|
|
|
|
| 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2675 |
}
|
| 2676 |
} catch (e) {
|
| 2677 |
-
console.
|
| 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;
|