cutechicken commited on
Commit
b36c34f
·
verified ·
1 Parent(s): 5229e80

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +58 -54
game.js CHANGED
@@ -280,22 +280,34 @@ class Fighter {
280
  }
281
 
282
  updateControls(keys, deltaTime) {
283
- // W/S: 스로틀만 제어 (가속/감속)
284
- if (keys.w) {
285
- this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.5); // 천천히 가속
286
- }
287
- if (keys.s) {
288
- this.throttle = Math.max(0.1, this.throttle - deltaTime * 0.5); // 천천히 감속
289
- }
290
-
291
- // A/D: 보조 요 제어 (러더) - 반응성 개선
292
- if (keys.a) {
293
- this.targetYaw -= deltaTime * 1.2; // 0.4에서 1.2로 증가 (3배)
294
- }
295
- if (keys.d) {
296
- this.targetYaw += deltaTime * 1.2; // 0.4에서 1.2로 증가 (3배)
297
- }
298
  }
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
  updatePhysics(deltaTime) {
301
  if (!this.mesh) return;
@@ -1689,37 +1701,31 @@ class Game {
1689
  }
1690
 
1691
  setupEventListeners() {
1692
- // 키보드 이벤트 - gameStarted 체크를 수정
1693
  document.addEventListener('keydown', (event) => {
1694
  if (this.isGameOver) return;
1695
 
1696
- // gameStarted 체크를 제거하거나, isStarted 변경
1697
  if (!this.isStarted) return;
1698
 
1699
  switch(event.code) {
1700
  case 'KeyW':
1701
  this.keys.w = true;
1702
- event.preventDefault();
1703
- console.log('W key pressed, throttle increasing');
1704
  break;
1705
  case 'KeyA':
1706
  this.keys.a = true;
1707
- event.preventDefault();
1708
- console.log('A key pressed, turning left');
1709
  break;
1710
  case 'KeyS':
1711
  this.keys.s = true;
1712
- event.preventDefault();
1713
- console.log('S key pressed, throttle decreasing');
1714
  break;
1715
  case 'KeyD':
1716
  this.keys.d = true;
1717
- event.preventDefault();
1718
- console.log('D key pressed, turning right');
1719
  break;
1720
  case 'KeyF':
1721
  this.keys.f = true;
1722
- event.preventDefault();
1723
  break;
1724
  }
1725
  });
@@ -1727,28 +1733,20 @@ class Game {
1727
  document.addEventListener('keyup', (event) => {
1728
  if (this.isGameOver) return;
1729
 
1730
- // gameStarted 체크를 제거하거나, isStarted 변경
1731
  if (!this.isStarted) return;
1732
 
1733
  switch(event.code) {
1734
- case 'KeyW':
1735
- this.keys.w = false;
1736
- break;
1737
- case 'KeyA':
1738
- this.keys.a = false;
1739
- break;
1740
- case 'KeyS':
1741
- this.keys.s = false;
1742
- break;
1743
- case 'KeyD':
1744
- this.keys.d = false;
1745
- break;
1746
- case 'KeyF':
1747
- this.keys.f = false;
1748
- break;
1749
  }
1750
  });
 
1751
  document.addEventListener('mousemove', (event) => {
 
1752
  if (!document.pointerLockElement || this.isGameOver || !this.isStarted) return;
1753
 
1754
  const deltaX = event.movementX || 0;
@@ -1758,6 +1756,7 @@ class Game {
1758
  });
1759
 
1760
  document.addEventListener('mousedown', (event) => {
 
1761
  if (!document.pointerLockElement || this.isGameOver || !this.isStarted) return;
1762
 
1763
  if (event.button === 0) {
@@ -2823,21 +2822,26 @@ class Game {
2823
  }
2824
 
2825
  animate() {
2826
- if (this.isGameOver) return;
 
 
 
 
 
 
 
 
 
 
2827
 
2828
- this.animationFrameId = requestAnimationFrame(() => this.animate());
 
 
 
2829
 
2830
- const currentTime = performance.now();
2831
- const deltaTime = Math.min((currentTime - this.lastTime) / 1000, 0.1);
2832
- this.lastTime = currentTime;
2833
 
2834
- if (this.isLoaded && this.fighter.isLoaded) {
2835
- // F키 상태를 Fighter에 전달
2836
- this.fighter.escapeKeyPressed = this.keys.f;
2837
-
2838
- this.fighter.updateControls(this.keys, deltaTime);
2839
- this.fighter.updatePhysics(deltaTime);
2840
- this.fighter.updateBullets(this.scene, deltaTime, this); // this 추가
2841
 
2842
  // 마우스 누름 상태일 때 연속 발사
2843
  if (this.fighter.isMouseDown && this.isStarted) {
 
280
  }
281
 
282
  updateControls(keys, deltaTime) {
283
+ // 디버깅을 위한 로그
284
+ if (keys.w || keys.s || keys.a || keys.d) {
285
+ console.log('Controls active:', {
286
+ w: keys.w,
287
+ a: keys.a,
288
+ s: keys.s,
289
+ d: keys.d,
290
+ throttle: this.throttle,
291
+ targetYaw: this.targetYaw
292
+ });
293
+ }
294
+
295
+ // W/S: 스로틀만 제어 (가속/감속)
296
+ if (keys.w) {
297
+ this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.5);
298
  }
299
+ if (keys.s) {
300
+ this.throttle = Math.max(0.1, this.throttle - deltaTime * 0.5);
301
+ }
302
+
303
+ // A/D: 보조 요 제어 (러더) - 반응성 개선
304
+ if (keys.a) {
305
+ this.targetYaw -= deltaTime * 1.2;
306
+ }
307
+ if (keys.d) {
308
+ this.targetYaw += deltaTime * 1.2;
309
+ }
310
+ }
311
 
312
  updatePhysics(deltaTime) {
313
  if (!this.mesh) return;
 
1701
  }
1702
 
1703
  setupEventListeners() {
 
1704
  document.addEventListener('keydown', (event) => {
1705
  if (this.isGameOver) return;
1706
 
1707
+ // gameStarted 대신 this.isStarted 사용
1708
  if (!this.isStarted) return;
1709
 
1710
  switch(event.code) {
1711
  case 'KeyW':
1712
  this.keys.w = true;
1713
+ console.log('W key pressed - Accelerating');
 
1714
  break;
1715
  case 'KeyA':
1716
  this.keys.a = true;
1717
+ console.log('A key pressed - Turning left');
 
1718
  break;
1719
  case 'KeyS':
1720
  this.keys.s = true;
1721
+ console.log('S key pressed - Decelerating');
 
1722
  break;
1723
  case 'KeyD':
1724
  this.keys.d = true;
1725
+ console.log('D key pressed - Turning right');
 
1726
  break;
1727
  case 'KeyF':
1728
  this.keys.f = true;
 
1729
  break;
1730
  }
1731
  });
 
1733
  document.addEventListener('keyup', (event) => {
1734
  if (this.isGameOver) return;
1735
 
1736
+ // gameStarted 대신 this.isStarted 사용
1737
  if (!this.isStarted) return;
1738
 
1739
  switch(event.code) {
1740
+ case 'KeyW': this.keys.w = false; break;
1741
+ case 'KeyA': this.keys.a = false; break;
1742
+ case 'KeyS': this.keys.s = false; break;
1743
+ case 'KeyD': this.keys.d = false; break;
1744
+ case 'KeyF': this.keys.f = false; break;
 
 
 
 
 
 
 
 
 
 
1745
  }
1746
  });
1747
+
1748
  document.addEventListener('mousemove', (event) => {
1749
+ // 여기도 gameStarted를 this.isStarted로 변경
1750
  if (!document.pointerLockElement || this.isGameOver || !this.isStarted) return;
1751
 
1752
  const deltaX = event.movementX || 0;
 
1756
  });
1757
 
1758
  document.addEventListener('mousedown', (event) => {
1759
+ // 여기도 gameStarted를 this.isStarted로 변경
1760
  if (!document.pointerLockElement || this.isGameOver || !this.isStarted) return;
1761
 
1762
  if (event.button === 0) {
 
2822
  }
2823
 
2824
  animate() {
2825
+ if (this.isGameOver) return;
2826
+
2827
+ this.animationFrameId = requestAnimationFrame(() => this.animate());
2828
+
2829
+ const currentTime = performance.now();
2830
+ const deltaTime = Math.min((currentTime - this.lastTime) / 1000, 0.1);
2831
+ this.lastTime = currentTime;
2832
+
2833
+ if (this.isLoaded && this.fighter.isLoaded) {
2834
+ // F키 상태를 Fighter에 전달
2835
+ this.fighter.escapeKeyPressed = this.keys.f;
2836
 
2837
+ // isStarted 확인 컨트롤 업데이트
2838
+ if (this.isStarted) {
2839
+ this.fighter.updateControls(this.keys, deltaTime);
2840
+ }
2841
 
2842
+ this.fighter.updatePhysics(deltaTime);
2843
+ this.fighter.updateBullets(this.scene, deltaTime, this);
 
2844
 
 
 
 
 
 
 
 
2845
 
2846
  // 마우스 누름 상태일 때 연속 발사
2847
  if (this.fighter.isMouseDown && this.isStarted) {