cutechicken commited on
Commit
280b38d
ยท
verified ยท
1 Parent(s): 258fcf8

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +36 -17
game.js CHANGED
@@ -55,11 +55,11 @@ class Fighter {
55
  this.bullets = [];
56
  this.lastShootTime = 0;
57
 
58
- // ์นด๋ฉ”๋ผ (ํƒฑํฌ์™€ ์œ ์‚ฌํ•œ ์‹œ์Šคํ…œ)
59
- this.cameraDistance = 35;
60
- this.cameraHeight = 8;
61
- this.cameraAngle = 0; // ๋งˆ์šฐ์Šค๋กœ ์ œ์–ด๋˜๋Š” ์นด๋ฉ”๋ผ ๊ฐ๋„
62
- this.cameraPitch = 0.1; // ์•ฝ๊ฐ„ ์œ„์—์„œ ๋‚ด๋ ค๋‹ค๋ณด๋Š” ๊ฐ๋„
63
  }
64
 
65
  async initialize(scene, loader) {
@@ -365,22 +365,34 @@ class Fighter {
365
 
366
  // ํƒฑํฌ ๊ฒŒ์ž„๊ณผ ์œ ์‚ฌํ•œ ์นด๋ฉ”๋ผ ์‹œ์Šคํ…œ
367
  getCameraPosition() {
368
- // ์ „ํˆฌ๊ธฐ ๋’ค์ชฝ์—์„œ ์ถ”์ ํ•˜๋Š” ์นด๋ฉ”๋ผ
369
- const offset = new THREE.Vector3(
370
- Math.sin(this.cameraAngle) * this.cameraDistance,
371
- this.cameraHeight,
372
- Math.cos(this.cameraAngle) * this.cameraDistance
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  );
374
 
375
- // ์ „ํˆฌ๊ธฐ์˜ ํšŒ์ „ ์ ์šฉ
376
- offset.applyEuler(new THREE.Euler(0, this.rotation.y, 0));
377
-
378
- return this.position.clone().add(offset);
379
  }
380
 
381
  getCameraTarget() {
382
- // ์ „ํˆฌ๊ธฐ๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ํ•œ ํƒ€๊ฒŸ
383
- return this.position.clone().add(new THREE.Vector3(0, 2, 0));
 
 
384
  }
385
  }
386
 
@@ -672,6 +684,11 @@ class Game {
672
  throw new Error('์ „ํˆฌ๊ธฐ ๋กœ๋”ฉ ์‹คํŒจ');
673
  }
674
 
 
 
 
 
 
675
  // ์  ์ƒ์„ฑ (์‚ฌ์ „ ๋กœ๋”ฉ)
676
  await this.preloadEnemies();
677
 
@@ -1005,7 +1022,9 @@ class Game {
1005
  // ์นด๋ฉ”๋ผ ์—…๋ฐ์ดํŠธ (ํƒฑํฌ ๊ฒŒ์ž„๊ณผ ์œ ์‚ฌ)
1006
  const cameraPos = this.fighter.getCameraPosition();
1007
  const cameraTarget = this.fighter.getCameraTarget();
1008
- this.camera.position.lerp(cameraPos, 0.15);
 
 
1009
  this.camera.lookAt(cameraTarget);
1010
  }
1011
 
 
55
  this.bullets = [];
56
  this.lastShootTime = 0;
57
 
58
+ // ์นด๋ฉ”๋ผ
59
+ this.cameraDistance = 50; // ๊ฑฐ๋ฆฌ ์ฆ๊ฐ€
60
+ this.cameraHeight = 15; // ๋†’์ด ์ฆ๊ฐ€
61
+ this.cameraAngle = 0; // ๋งˆ์šฐ์Šค๋กœ ์ œ์–ด๋˜๋Š” ์นด๋ฉ”๋ผ ๊ฐ๋„
62
+ this.cameraPitch = 0.1; // ์•ฝ๊ฐ„ ์œ„์—์„œ ๋‚ด๋ ค๋‹ค๋ณด๋Š” ๊ฐ๋„
63
  }
64
 
65
  async initialize(scene, loader) {
 
365
 
366
  // ํƒฑํฌ ๊ฒŒ์ž„๊ณผ ์œ ์‚ฌํ•œ ์นด๋ฉ”๋ผ ์‹œ์Šคํ…œ
367
  getCameraPosition() {
368
+ // ์ „ํˆฌ๊ธฐ ๋’ค์ชฝ์—์„œ ์ถ”์ ํ•˜๋Š” ์นด๋ฉ”๋ผ (๋” ๋ฉ€๋ฆฌ)
369
+ const cameraDistance = 50; // ๊ฑฐ๋ฆฌ ์ฆ๊ฐ€
370
+ const cameraHeight = 15; // ๋†’์ด ์ฆ๊ฐ€
371
+
372
+ // ์ „ํˆฌ๊ธฐ ๋’ค์ชฝ ๋ฐฉํ–ฅ ๊ณ„์‚ฐ
373
+ const backwardDirection = new THREE.Vector3(0, 0, -1); // ๋’ค์ชฝ
374
+ backwardDirection.applyEuler(this.rotation);
375
+
376
+ // ์นด๋ฉ”๋ผ ์œ„์น˜ = ์ „ํˆฌ๊ธฐ ์œ„์น˜ + (๋’ค์ชฝ ๋ฐฉํ–ฅ * ๊ฑฐ๋ฆฌ) + ๋†’์ด
377
+ const cameraPosition = this.position.clone()
378
+ .add(backwardDirection.multiplyScalar(cameraDistance))
379
+ .add(new THREE.Vector3(0, cameraHeight, 0));
380
+
381
+ // ๋งˆ์šฐ์Šค๋กœ ์นด๋ฉ”๋ผ ๊ฐ๋„ ์กฐ์ •
382
+ const mouseOffset = new THREE.Vector3(
383
+ Math.sin(this.cameraAngle) * 20,
384
+ 0,
385
+ Math.cos(this.cameraAngle) * 20
386
  );
387
 
388
+ return cameraPosition.add(mouseOffset);
 
 
 
389
  }
390
 
391
  getCameraTarget() {
392
+ // ์ „ํˆฌ๊ธฐ๋ฅผ ๋ฐ”๋ผ๋ณด๋Š” ํƒ€๊ฒŸ (์•ฝ๊ฐ„ ์•ž์ชฝ)
393
+ const targetOffset = new THREE.Vector3(0, 0, 10);
394
+ targetOffset.applyEuler(this.rotation);
395
+ return this.position.clone().add(targetOffset);
396
  }
397
  }
398
 
 
684
  throw new Error('์ „ํˆฌ๊ธฐ ๋กœ๋”ฉ ์‹คํŒจ');
685
  }
686
 
687
+ // ์ดˆ๊ธฐ ์นด๋ฉ”๋ผ ์œ„์น˜ ์„ค์ • (์ „ํˆฌ๊ธฐ ๋’ค์ชฝ)
688
+ const initialCameraPos = new THREE.Vector3(0, 2020, -60);
689
+ this.camera.position.copy(initialCameraPos);
690
+ this.camera.lookAt(this.fighter.position);
691
+
692
  // ์  ์ƒ์„ฑ (์‚ฌ์ „ ๋กœ๋”ฉ)
693
  await this.preloadEnemies();
694
 
 
1022
  // ์นด๋ฉ”๋ผ ์—…๋ฐ์ดํŠธ (ํƒฑํฌ ๊ฒŒ์ž„๊ณผ ์œ ์‚ฌ)
1023
  const cameraPos = this.fighter.getCameraPosition();
1024
  const cameraTarget = this.fighter.getCameraTarget();
1025
+
1026
+ // ๋ถ€๋“œ๋Ÿฌ์šด ์นด๋ฉ”๋ผ ์ด๋™
1027
+ this.camera.position.lerp(cameraPos, 0.1);
1028
  this.camera.lookAt(cameraTarget);
1029
  }
1030