Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -55,11 +55,11 @@ class Fighter {
|
|
55 |
this.bullets = [];
|
56 |
this.lastShootTime = 0;
|
57 |
|
58 |
-
// ์นด๋ฉ๋ผ
|
59 |
-
this.cameraDistance =
|
60 |
-
this.cameraHeight =
|
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
|
370 |
-
|
371 |
-
|
372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
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 |
-
|
|
|
|
|
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 |
|