cutechicken commited on
Commit
2fc874a
Β·
verified Β·
1 Parent(s): f6cb1f0

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +61 -6
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
- const audio = new Audio('sounds/m134.ogg');
622
- if (audio) {
623
- audio.volume = 0.3;
624
- audio.play().catch(e => console.log('Gunfire sound failed to play'));
 
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 >= 200) { // 0.2μ΄ˆλ§ˆλ‹€
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
  }