Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -105,10 +105,13 @@ class TankPlayer {
|
|
105 |
update(mouseX, mouseY, scene) {
|
106 |
if (!this.body || !this.turretGroup) return;
|
107 |
|
108 |
-
// ํฌํ ํ์ - ๋ง์ฐ์ค
|
109 |
-
|
|
|
|
|
|
|
110 |
|
111 |
-
// ํ๋ ์ด์ด ์ด์
|
112 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
113 |
const bullet = this.bullets[i];
|
114 |
bullet.position.add(bullet.velocity);
|
@@ -481,9 +484,14 @@ async addDesertDecorations() {
|
|
481 |
document.addEventListener('mousemove', (event) => {
|
482 |
if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
|
483 |
|
484 |
-
//
|
485 |
-
|
486 |
-
|
|
|
|
|
|
|
|
|
|
|
487 |
});
|
488 |
|
489 |
|
@@ -532,26 +540,26 @@ async addDesertDecorations() {
|
|
532 |
this.tank.move(direction);
|
533 |
}
|
534 |
|
535 |
-
// ์นด๋ฉ๋ผ ์์น ์
๋ฐ์ดํธ -
|
536 |
const tankPos = this.tank.getPosition();
|
537 |
-
const
|
538 |
const cameraDistance = 30;
|
539 |
const cameraHeight = 15;
|
540 |
|
541 |
-
//
|
542 |
this.camera.position.set(
|
543 |
-
tankPos.x - Math.sin(
|
544 |
tankPos.y + cameraHeight,
|
545 |
-
tankPos.z - Math.cos(
|
546 |
-
);
|
547 |
-
|
548 |
-
// ์นด๋ฉ๋ผ๊ฐ ํญ์ ํฌํ์ ๋ฐ๋ผ๋ณด๋๋ก ์ค์
|
549 |
-
const lookAtPoint = new THREE.Vector3(
|
550 |
-
tankPos.x + Math.sin(turretRotation) * 10,
|
551 |
-
tankPos.y + 5,
|
552 |
-
tankPos.z + Math.cos(turretRotation) * 10
|
553 |
);
|
554 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
this.camera.lookAt(lookAtPoint);
|
556 |
}
|
557 |
|
|
|
105 |
update(mouseX, mouseY, scene) {
|
106 |
if (!this.body || !this.turretGroup) return;
|
107 |
|
108 |
+
// ํฌํ ํ์ - ๋ง์ฐ์ค ์์น์ ๋ฐ๋ผ ํ์
|
109 |
+
const screenCenter = new THREE.Vector2(0, 0);
|
110 |
+
const mousePosition = new THREE.Vector2(mouseX, mouseY);
|
111 |
+
const angle = Math.atan2(mousePosition.x - screenCenter.x, mousePosition.y - screenCenter.y);
|
112 |
+
this.turretGroup.rotation.y = angle;
|
113 |
|
114 |
+
// ํ๋ ์ด์ด ์ด์ ์
๋ฐ์ดํธ
|
115 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
116 |
const bullet = this.bullets[i];
|
117 |
bullet.position.add(bullet.velocity);
|
|
|
484 |
document.addEventListener('mousemove', (event) => {
|
485 |
if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
|
486 |
|
487 |
+
// ๋ง์ฐ์ค ์์ง์์ ํ๋ฉด ์ค์ ๊ธฐ์ค์ผ๋ก ์ ๊ทํ
|
488 |
+
const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
489 |
+
const movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
490 |
+
|
491 |
+
this.mouse.x += movementX * 0.002;
|
492 |
+
this.mouse.y += movementY * 0.002;
|
493 |
+
|
494 |
+
// ๋ง์ฐ์ค ์ด๋
|
495 |
});
|
496 |
|
497 |
|
|
|
540 |
this.tank.move(direction);
|
541 |
}
|
542 |
|
543 |
+
// ์นด๋ฉ๋ผ ์์น ์
๋ฐ์ดํธ - ํญ์ ํฑํฌ ๋ค์์ ๋ฐ๋ผ๋ณด๋๋ก ์ค์
|
544 |
const tankPos = this.tank.getPosition();
|
545 |
+
const tankRotation = this.tank.body.rotation.y;
|
546 |
const cameraDistance = 30;
|
547 |
const cameraHeight = 15;
|
548 |
|
549 |
+
// ํฑํฌ์ ๋ค์ชฝ ์์น์ ์นด๋ฉ๋ผ ๋ฐฐ์น
|
550 |
this.camera.position.set(
|
551 |
+
tankPos.x - Math.sin(tankRotation) * cameraDistance,
|
552 |
tankPos.y + cameraHeight,
|
553 |
+
tankPos.z - Math.cos(tankRotation) * cameraDistance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
554 |
);
|
555 |
|
556 |
+
// ์นด๋ฉ๋ผ๊ฐ ํญ์ ํฑํฌ๋ฅผ ๋ฐ๋ผ๋ณด๋๋ก ์ค์
|
557 |
+
this.camera.lookAt(new THREE.Vector3(
|
558 |
+
tankPos.x,
|
559 |
+
tankPos.y,
|
560 |
+
tankPos.z
|
561 |
+
));
|
562 |
+
//}
|
563 |
this.camera.lookAt(lookAtPoint);
|
564 |
}
|
565 |
|