cutechicken commited on
Commit
12284be
ยท
verified ยท
1 Parent(s): b36c34f

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +83 -77
game.js CHANGED
@@ -282,30 +282,35 @@ class Fighter {
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
 
@@ -2830,92 +2835,93 @@ class Game {
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) {
2848
- const currentShootTime = Date.now();
2849
- if (!this.lastShootTime || currentShootTime - this.lastShootTime >= 100) { // 0.1์ดˆ๋งˆ๋‹ค
2850
- this.fighter.shoot(this.scene);
2851
- this.lastShootTime = currentShootTime;
2852
- }
2853
  }
2854
-
2855
- if (this.isStarted) {
2856
- // ์ ๊ธฐ๋“ค์—๊ฒŒ ์„œ๋กœ์˜ ์ฐธ์กฐ ์ „๋‹ฌ (์ถฉ๋Œ ํšŒํ”ผ์šฉ)
2857
- this.enemies.forEach(enemy => {
2858
- enemy.nearbyEnemies = this.enemies;
2859
- });
2860
-
2861
- this.enemies.forEach(enemy => {
2862
- enemy.update(this.fighter.position, deltaTime);
2863
- });
2864
-
2865
- this.checkCollisions();
2866
-
2867
- if (this.fighter.health <= 0) {
2868
-
2869
- if (this.fighter.position.y <= 0) {
2870
- this.endGame(false, "GROUND COLLISION");
2871
- } else {
2872
- this.endGame(false);
2873
- }
2874
- return;
2875
- }
2876
-
2877
- this.updateUI();
2878
- this.updateRadar();
2879
-
2880
- if (this.enemies.length === 0) {
2881
- this.endGame(true);
2882
- }
2883
- }
2884
-
2885
- // ๊ตฌ๋ฆ„ ์• ๋‹ˆ๋ฉ”์ด์…˜
2886
- if (this.clouds) {
2887
- this.clouds.forEach(cloud => {
2888
- cloud.userData.time += deltaTime;
2889
- // ์ขŒ์šฐ ๋“œ๋ฆฌํ”„ํŠธ
2890
- cloud.position.x += cloud.userData.driftSpeed;
2891
- // ์ƒํ•˜ ๋ถ€์œ 
2892
- cloud.position.y = cloud.userData.initialY +
2893
- Math.sin(cloud.userData.time * cloud.userData.floatSpeed) * 20;
2894
-
2895
- // ๋งต ๊ฒฝ๊ณ„ ์ฒ˜๋ฆฌ
2896
- const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
2897
- if (cloud.position.x > mapLimit) cloud.position.x = -mapLimit;
2898
- if (cloud.position.x < -mapLimit) cloud.position.x = mapLimit;
2899
- });
2900
- }
2901
-
2902
- const targetCameraPos = this.fighter.getCameraPosition();
2903
- const targetCameraTarget = this.fighter.getCameraTarget();
2904
-
2905
- this.camera.position.lerp(targetCameraPos, this.fighter.cameraLag);
2906
-
2907
- this.camera.lookAt(targetCameraTarget);
2908
- } else {
2909
- if (this.fighter.isLoaded) {
2910
- const initialCameraPos = this.fighter.getCameraPosition();
2911
- const initialTarget = this.fighter.getCameraTarget();
2912
- this.camera.position.copy(initialCameraPos);
2913
- this.camera.lookAt(initialTarget);
2914
  }
 
 
 
 
 
 
 
 
 
 
2915
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2916
 
2917
- this.renderer.render(this.scene, this.camera);
 
2918
  }
 
 
 
2919
 
2920
  endGame(victory = false, reason = "") {
2921
  this.isGameOver = true;
 
282
  updateControls(keys, deltaTime) {
283
  // ๋””๋ฒ„๊น…์„ ์œ„ํ•œ ๋กœ๊ทธ
284
  if (keys.w || keys.s || keys.a || keys.d) {
285
+ console.log('updateControls called:', {
286
  w: keys.w,
287
  a: keys.a,
288
  s: keys.s,
289
  d: keys.d,
290
+ throttle_before: this.throttle,
291
+ targetYaw_before: this.targetYaw,
292
+ deltaTime: deltaTime
293
  });
294
  }
295
 
296
  // W/S: ์Šค๋กœํ‹€๋งŒ ์ œ์–ด (๊ฐ€์†/๊ฐ์†)
297
  if (keys.w) {
298
  this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.5);
299
+ console.log('W pressed - New throttle:', this.throttle);
300
  }
301
  if (keys.s) {
302
  this.throttle = Math.max(0.1, this.throttle - deltaTime * 0.5);
303
+ console.log('S pressed - New throttle:', this.throttle);
304
  }
305
 
306
  // A/D: ๋ณด์กฐ ์š” ์ œ์–ด (๋Ÿฌ๋”) - ๋ฐ˜์‘์„ฑ ๊ฐœ์„ 
307
  if (keys.a) {
308
  this.targetYaw -= deltaTime * 1.2;
309
+ console.log('A pressed - New targetYaw:', this.targetYaw);
310
  }
311
  if (keys.d) {
312
  this.targetYaw += deltaTime * 1.2;
313
+ console.log('D pressed - New targetYaw:', this.targetYaw);
314
  }
315
  }
316
 
 
2835
  const deltaTime = Math.min((currentTime - this.lastTime) / 1000, 0.1);
2836
  this.lastTime = currentTime;
2837
 
2838
+ if (this.isLoaded && this.fighter.isLoaded && this.isStarted) {
2839
+ // ํ‚ค ์ƒํƒœ ๋””๋ฒ„๊น…
2840
+ if (this.keys.w || this.keys.s || this.keys.a || this.keys.d) {
2841
+ console.log('animate() - Keys state:', this.keys);
2842
+ }
2843
+
2844
  // Fํ‚ค ์ƒํƒœ๋ฅผ Fighter์— ์ „๋‹ฌ
2845
  this.fighter.escapeKeyPressed = this.keys.f;
2846
 
2847
+ // ์ปจํŠธ๋กค ์—…๋ฐ์ดํŠธ - ๋ฐ˜๋“œ์‹œ ๋ฌผ๋ฆฌ ์—…๋ฐ์ดํŠธ ์ „์— ํ˜ธ์ถœ
2848
+ this.fighter.updateControls(this.keys, deltaTime);
 
 
2849
 
2850
+ // ๋ฌผ๋ฆฌ ์—…๋ฐ์ดํŠธ
2851
  this.fighter.updatePhysics(deltaTime);
2852
+
2853
+ // ํƒ„ํ™˜ ์—…๋ฐ์ดํŠธ
2854
  this.fighter.updateBullets(this.scene, deltaTime, this);
2855
 
2856
+ // ๋งˆ์šฐ์Šค ๋ˆ„๋ฆ„ ์ƒํƒœ์ผ ๋•Œ ์—ฐ์† ๋ฐœ์‚ฌ
2857
+ if (this.fighter.isMouseDown) {
2858
+ const currentShootTime = Date.now();
2859
+ if (!this.lastShootTime || currentShootTime - this.lastShootTime >= 100) {
2860
+ this.fighter.shoot(this.scene);
2861
+ this.lastShootTime = currentShootTime;
 
 
2862
  }
2863
+ }
2864
+
2865
+ // ์ ๊ธฐ ์—…๋ฐ์ดํŠธ
2866
+ this.enemies.forEach(enemy => {
2867
+ enemy.nearbyEnemies = this.enemies;
2868
+ });
2869
+
2870
+ this.enemies.forEach(enemy => {
2871
+ enemy.update(this.fighter.position, deltaTime);
2872
+ });
2873
+
2874
+ // ์ถฉ๋Œ ์ฒดํฌ
2875
+ this.checkCollisions();
2876
+
2877
+ // ๊ฒŒ์ž„ ์ข…๋ฃŒ ์กฐ๊ฑด ์ฒดํฌ
2878
+ if (this.fighter.health <= 0) {
2879
+ if (this.fighter.position.y <= 0) {
2880
+ this.endGame(false, "GROUND COLLISION");
2881
+ } else {
2882
+ this.endGame(false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2883
  }
2884
+ return;
2885
+ }
2886
+
2887
+ // UI ์—…๋ฐ์ดํŠธ
2888
+ this.updateUI();
2889
+ this.updateRadar();
2890
+
2891
+ // ์ ์ด ๋ชจ๋‘ ์ œ๊ฑฐ๋˜์—ˆ๋Š”์ง€ ์ฒดํฌ
2892
+ if (this.enemies.length === 0) {
2893
+ this.endGame(true);
2894
  }
2895
+ } else if (this.isLoaded && this.fighter.isLoaded) {
2896
+ // ๊ฒŒ์ž„์ด ์‹œ์ž‘๋˜์ง€ ์•Š์•˜์„ ๋•Œ๋„ ๋ฌผ๋ฆฌ๋Š” ์—…๋ฐ์ดํŠธ (์นด๋ฉ”๋ผ ์›€์ง์ž„์„ ์œ„ํ•ด)
2897
+ this.fighter.updatePhysics(deltaTime);
2898
+ }
2899
+
2900
+ // ๊ตฌ๋ฆ„ ์• ๋‹ˆ๋ฉ”์ด์…˜
2901
+ if (this.clouds) {
2902
+ this.clouds.forEach(cloud => {
2903
+ cloud.userData.time += deltaTime;
2904
+ cloud.position.x += cloud.userData.driftSpeed;
2905
+ cloud.position.y = cloud.userData.initialY +
2906
+ Math.sin(cloud.userData.time * cloud.userData.floatSpeed) * 20;
2907
+
2908
+ const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
2909
+ if (cloud.position.x > mapLimit) cloud.position.x = -mapLimit;
2910
+ if (cloud.position.x < -mapLimit) cloud.position.x = mapLimit;
2911
+ });
2912
+ }
2913
+
2914
+ // ์นด๋ฉ”๋ผ ์—…๋ฐ์ดํŠธ
2915
+ if (this.fighter.isLoaded) {
2916
+ const targetCameraPos = this.fighter.getCameraPosition();
2917
+ const targetCameraTarget = this.fighter.getCameraTarget();
2918
 
2919
+ this.camera.position.lerp(targetCameraPos, this.fighter.cameraLag);
2920
+ this.camera.lookAt(targetCameraTarget);
2921
  }
2922
+
2923
+ this.renderer.render(this.scene, this.camera);
2924
+ }
2925
 
2926
  endGame(victory = false, reason = "") {
2927
  this.isGameOver = true;