Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -62,6 +62,7 @@ class Fighter {
|
|
62 |
this.bullets = [];
|
63 |
this.lastShootTime = 0;
|
64 |
this.isMouseDown = false; // λ§μ°μ€ λλ¦ μν μΆμ
|
|
|
65 |
|
66 |
// μ€ν¨ νμΆμ μν Fν€ μν
|
67 |
this.escapeKeyPressed = false;
|
@@ -616,12 +617,13 @@ class Fighter {
|
|
616 |
scene.add(bullet);
|
617 |
this.bullets.push(bullet);
|
618 |
|
619 |
-
// m134.ogg μ리 μ¬μ
|
620 |
try {
|
621 |
-
|
622 |
-
if (
|
623 |
-
|
624 |
-
|
|
|
625 |
}
|
626 |
} catch (e) {}
|
627 |
}
|
@@ -1620,6 +1622,9 @@ class Game {
|
|
1620 |
this.scene.remove(bullet);
|
1621 |
this.fighter.bullets.splice(i, 1);
|
1622 |
|
|
|
|
|
|
|
1623 |
if (enemy.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE)) { // 25 λ°λ―Έμ§
|
1624 |
enemy.destroy();
|
1625 |
this.enemies.splice(j, 1);
|
@@ -1645,6 +1650,56 @@ class Game {
|
|
1645 |
});
|
1646 |
}
|
1647 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1648 |
animate() {
|
1649 |
if (this.isGameOver) return;
|
1650 |
|
@@ -1665,7 +1720,7 @@ class Game {
|
|
1665 |
// λ§μ°μ€ λλ¦ μνμΌ λ μ°μ λ°μ¬
|
1666 |
if (this.fighter.isMouseDown && this.isStarted) {
|
1667 |
const currentShootTime = Date.now();
|
1668 |
-
if (!this.lastShootTime || currentShootTime - this.lastShootTime >=
|
1669 |
this.fighter.shoot(this.scene);
|
1670 |
this.lastShootTime = currentShootTime;
|
1671 |
}
|
|
|
62 |
this.bullets = [];
|
63 |
this.lastShootTime = 0;
|
64 |
this.isMouseDown = false; // λ§μ°μ€ λλ¦ μν μΆμ
|
65 |
+
this.gunfireAudio = null; // κΈ°κ΄μ΄ μ리 μ¬μμ©
|
66 |
|
67 |
// μ€ν¨ νμΆμ μν Fν€ μν
|
68 |
this.escapeKeyPressed = false;
|
|
|
617 |
scene.add(bullet);
|
618 |
this.bullets.push(bullet);
|
619 |
|
620 |
+
// m134.ogg μ리 μ¬μ - μ€μ²© λ°©μ§
|
621 |
try {
|
622 |
+
// μ΄μ μλ¦¬κ° μ¬μ μ€μ΄ μλκ±°λ μμΌλ©΄ μλ‘ μ¬μ
|
623 |
+
if (!this.gunfireAudio || this.gunfireAudio.paused) {
|
624 |
+
this.gunfireAudio = new Audio('sounds/m134.ogg');
|
625 |
+
this.gunfireAudio.volume = 0.3;
|
626 |
+
this.gunfireAudio.play().catch(e => console.log('Gunfire sound failed to play'));
|
627 |
}
|
628 |
} catch (e) {}
|
629 |
}
|
|
|
1622 |
this.scene.remove(bullet);
|
1623 |
this.fighter.bullets.splice(i, 1);
|
1624 |
|
1625 |
+
// ννΈ νμ μΆκ°
|
1626 |
+
this.showHitMarker(enemy.position);
|
1627 |
+
|
1628 |
if (enemy.takeDamage(GAME_CONSTANTS.BULLET_DAMAGE)) { // 25 λ°λ―Έμ§
|
1629 |
enemy.destroy();
|
1630 |
this.enemies.splice(j, 1);
|
|
|
1650 |
});
|
1651 |
}
|
1652 |
|
1653 |
+
showHitMarker(position) {
|
1654 |
+
// ννΈ λ§μ»€ div μμ±
|
1655 |
+
const hitMarker = document.createElement('div');
|
1656 |
+
hitMarker.style.cssText = `
|
1657 |
+
position: fixed;
|
1658 |
+
color: #ff0000;
|
1659 |
+
font-size: 24px;
|
1660 |
+
font-weight: bold;
|
1661 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
|
1662 |
+
z-index: 1500;
|
1663 |
+
pointer-events: none;
|
1664 |
+
animation: hitFade 0.5s ease-out forwards;
|
1665 |
+
`;
|
1666 |
+
hitMarker.textContent = 'HIT';
|
1667 |
+
|
1668 |
+
// 3D μμΉλ₯Ό νλ©΄ μ’νλ‘ λ³ν
|
1669 |
+
const screenPos = this.getScreenPosition(position);
|
1670 |
+
if (screenPos) {
|
1671 |
+
hitMarker.style.left = `${screenPos.x}px`;
|
1672 |
+
hitMarker.style.top = `${screenPos.y}px`;
|
1673 |
+
hitMarker.style.transform = 'translate(-50%, -50%)';
|
1674 |
+
|
1675 |
+
document.body.appendChild(hitMarker);
|
1676 |
+
|
1677 |
+
// μ λλ©μ΄μ
μ€νμΌ μΆκ°
|
1678 |
+
if (!document.getElementById('hitAnimation')) {
|
1679 |
+
const style = document.createElement('style');
|
1680 |
+
style.id = 'hitAnimation';
|
1681 |
+
style.innerHTML = `
|
1682 |
+
@keyframes hitFade {
|
1683 |
+
0% {
|
1684 |
+
opacity: 1;
|
1685 |
+
transform: translate(-50%, -50%) scale(1);
|
1686 |
+
}
|
1687 |
+
100% {
|
1688 |
+
opacity: 0;
|
1689 |
+
transform: translate(-50%, -100%) scale(1.5);
|
1690 |
+
}
|
1691 |
+
}
|
1692 |
+
`;
|
1693 |
+
document.head.appendChild(style);
|
1694 |
+
}
|
1695 |
+
|
1696 |
+
// 0.5μ΄ ν μ κ±°
|
1697 |
+
setTimeout(() => {
|
1698 |
+
hitMarker.remove();
|
1699 |
+
}, 500);
|
1700 |
+
}
|
1701 |
+
}
|
1702 |
+
|
1703 |
animate() {
|
1704 |
if (this.isGameOver) return;
|
1705 |
|
|
|
1720 |
// λ§μ°μ€ λλ¦ μνμΌ λ μ°μ λ°μ¬
|
1721 |
if (this.fighter.isMouseDown && this.isStarted) {
|
1722 |
const currentShootTime = Date.now();
|
1723 |
+
if (!this.lastShootTime || currentShootTime - this.lastShootTime >= 100) { // 0.1μ΄λ§λ€
|
1724 |
this.fighter.shoot(this.scene);
|
1725 |
this.lastShootTime = currentShootTime;
|
1726 |
}
|