Update game.js
Browse files
game.js
CHANGED
|
@@ -106,10 +106,14 @@ class TankPlayer {
|
|
| 106 |
update(mouseX, mouseY, scene) {
|
| 107 |
if (!this.body || !this.turretGroup) return;
|
| 108 |
|
| 109 |
-
// ๋ง์ฐ์ค
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
// ํ๋ ์ด์ด ์ด์ ์
๋ฐ์ดํธ
|
| 115 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
|
@@ -127,6 +131,7 @@ update(mouseX, mouseY, scene) {
|
|
| 127 |
}
|
| 128 |
|
| 129 |
|
|
|
|
| 130 |
move(direction) {
|
| 131 |
if (!this.body) return;
|
| 132 |
|
|
@@ -525,6 +530,7 @@ async addDesertDecorations() {
|
|
| 525 |
|
| 526 |
const direction = new THREE.Vector3();
|
| 527 |
|
|
|
|
| 528 |
if (this.keys.forward) direction.z += 1;
|
| 529 |
if (this.keys.backward) direction.z -= 1;
|
| 530 |
if (this.keys.left) direction.x -= 1;
|
|
@@ -533,26 +539,28 @@ async addDesertDecorations() {
|
|
| 533 |
if (direction.length() > 0) {
|
| 534 |
direction.normalize();
|
| 535 |
|
|
|
|
| 536 |
if (this.keys.left) this.tank.rotate(-1);
|
| 537 |
if (this.keys.right) this.tank.rotate(1);
|
| 538 |
|
|
|
|
| 539 |
direction.applyEuler(this.tank.body.rotation);
|
| 540 |
this.tank.move(direction);
|
| 541 |
}
|
| 542 |
|
| 543 |
-
//
|
| 544 |
const tankPos = this.tank.getPosition();
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ
|
| 548 |
const cameraDistance = 30;
|
| 549 |
const cameraHeight = 15;
|
|
|
|
| 550 |
|
| 551 |
-
//
|
| 552 |
-
const cameraX = tankPos.x - Math.sin(
|
| 553 |
-
const cameraZ = tankPos.z - Math.cos(
|
| 554 |
|
| 555 |
-
// ์นด๋ฉ๋ผ ์์น ์ค์
|
| 556 |
this.camera.position.set(
|
| 557 |
cameraX,
|
| 558 |
tankPos.y + cameraHeight,
|
|
@@ -562,7 +570,7 @@ async addDesertDecorations() {
|
|
| 562 |
// ์นด๋ฉ๋ผ๊ฐ ํฑํฌ๋ฅผ ๋ฐ๋ผ๋ณด๋๋ก ์ค์
|
| 563 |
this.camera.lookAt(new THREE.Vector3(
|
| 564 |
tankPos.x,
|
| 565 |
-
tankPos.y + 2,
|
| 566 |
tankPos.z
|
| 567 |
));
|
| 568 |
}
|
|
|
|
| 106 |
update(mouseX, mouseY, scene) {
|
| 107 |
if (!this.body || !this.turretGroup) return;
|
| 108 |
|
| 109 |
+
// ๋ง์ฐ์ค ์ด๋์ ๋ฐ๋ฅธ ํฌํ ํ์ - 360๋ ํ์ ๊ฐ๋ฅํ๋๋ก ์์
|
| 110 |
+
let angle = Math.atan2(mouseX, mouseY);
|
| 111 |
+
// ๊ฐ๋๋ฅผ 0~2ฯ ๋ฒ์๋ก ์ ๊ทํ
|
| 112 |
+
if (angle < 0) angle += Math.PI * 2;
|
| 113 |
+
|
| 114 |
+
// ํฌํ ํ์ ์ 180๋(ฯ)๋ฅผ ๋ํด์ ํฌ์ ์ด ๋ฐ๋ ๋ฐฉํฅ์ ํฅํ๋๋ก ํจ
|
| 115 |
+
this.turretGroup.rotation.y = angle + Math.PI;
|
| 116 |
+
this.turretRotation = angle + Math.PI;
|
| 117 |
|
| 118 |
// ํ๋ ์ด์ด ์ด์ ์
๋ฐ์ดํธ
|
| 119 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
|
|
|
| 131 |
}
|
| 132 |
|
| 133 |
|
| 134 |
+
|
| 135 |
move(direction) {
|
| 136 |
if (!this.body) return;
|
| 137 |
|
|
|
|
| 530 |
|
| 531 |
const direction = new THREE.Vector3();
|
| 532 |
|
| 533 |
+
// ์ด๋ ๋ฐฉํฅ ๊ณ์ฐ
|
| 534 |
if (this.keys.forward) direction.z += 1;
|
| 535 |
if (this.keys.backward) direction.z -= 1;
|
| 536 |
if (this.keys.left) direction.x -= 1;
|
|
|
|
| 539 |
if (direction.length() > 0) {
|
| 540 |
direction.normalize();
|
| 541 |
|
| 542 |
+
// ํฑํฌ ํ์
|
| 543 |
if (this.keys.left) this.tank.rotate(-1);
|
| 544 |
if (this.keys.right) this.tank.rotate(1);
|
| 545 |
|
| 546 |
+
// ์ด๋ ๋ฐฉํฅ์ ํฑํฌ์ ํ์ ์ ๋ง์ถฐ ์กฐ์
|
| 547 |
direction.applyEuler(this.tank.body.rotation);
|
| 548 |
this.tank.move(direction);
|
| 549 |
}
|
| 550 |
|
| 551 |
+
// ํฑํฌ ์์น ๊ฐ์ ธ์ค๊ธฐ
|
| 552 |
const tankPos = this.tank.getPosition();
|
| 553 |
+
|
| 554 |
+
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ - ๊ณ ์ ๋ ๋ฐฉํฅ์ผ๋ก ์ค์
|
|
|
|
| 555 |
const cameraDistance = 30;
|
| 556 |
const cameraHeight = 15;
|
| 557 |
+
const fixedCameraAngle = Math.PI; // ์นด๋ฉ๋ผ๋ ํญ์ ๋จ์ชฝ(ฯ)์ ํฅํ๋๋ก ์ค์
|
| 558 |
|
| 559 |
+
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ (ํฑํฌ ํ์ ๊ณผ ๋
๋ฆฝ์ )
|
| 560 |
+
const cameraX = tankPos.x - Math.sin(fixedCameraAngle) * cameraDistance;
|
| 561 |
+
const cameraZ = tankPos.z - Math.cos(fixedCameraAngle) * cameraDistance;
|
| 562 |
|
| 563 |
+
// ์นด๋ฉ๋ผ ์์น ๋ฐ ์์ ์ค์
|
| 564 |
this.camera.position.set(
|
| 565 |
cameraX,
|
| 566 |
tankPos.y + cameraHeight,
|
|
|
|
| 570 |
// ์นด๋ฉ๋ผ๊ฐ ํฑํฌ๋ฅผ ๋ฐ๋ผ๋ณด๋๋ก ์ค์
|
| 571 |
this.camera.lookAt(new THREE.Vector3(
|
| 572 |
tankPos.x,
|
| 573 |
+
tankPos.y + 2,
|
| 574 |
tankPos.z
|
| 575 |
));
|
| 576 |
}
|