Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -106,21 +106,18 @@ class TankPlayer {
|
|
106 |
update(mouseX, mouseY, scene) {
|
107 |
if (!this.body || !this.turretGroup) return;
|
108 |
|
109 |
-
//
|
110 |
-
|
111 |
-
let targetAngle = Math.atan2(mouseX, mouseY);
|
112 |
-
if (targetAngle < 0) targetAngle += Math.PI * 2;
|
113 |
-
|
114 |
-
// 차체μ νμ¬ νμ κ°μ κ³ λ €νμ¬ ν¬νμ μλ νμ κ³μ°
|
115 |
-
let relativeAngle = targetAngle - this.body.rotation.y;
|
116 |
|
117 |
-
//
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
124 |
|
125 |
// νλ μ΄μ΄ μ΄μ μ
λ°μ΄νΈ
|
126 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
@@ -493,17 +490,16 @@ async addDesertDecorations() {
|
|
493 |
}
|
494 |
});
|
495 |
|
496 |
-
|
497 |
if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
|
498 |
|
499 |
-
// λ§μ°μ€ μμ§μμ νλ©΄ μ€μ κΈ°μ€μΌλ‘ μ κ·ν
|
500 |
const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
501 |
-
|
502 |
-
|
503 |
-
this.mouse.x += movementX * 0.002;
|
504 |
-
this.mouse.y += movementY * 0.002;
|
505 |
|
506 |
-
//
|
|
|
|
|
507 |
});
|
508 |
|
509 |
|
@@ -555,14 +551,25 @@ async addDesertDecorations() {
|
|
555 |
const cameraDistance = 30;
|
556 |
const cameraHeight = 15;
|
557 |
|
558 |
-
//
|
559 |
-
const
|
560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
561 |
|
562 |
-
const cameraX = tankPos.x + Math.sin(
|
563 |
-
const cameraZ = tankPos.z + Math.cos(
|
564 |
|
565 |
-
// μΉ΄λ©λΌ μμΉ λ° μμ μ€μ
|
566 |
this.camera.position.set(
|
567 |
cameraX,
|
568 |
tankPos.y + cameraHeight,
|
|
|
106 |
update(mouseX, mouseY, scene) {
|
107 |
if (!this.body || !this.turretGroup) return;
|
108 |
|
109 |
+
// ν¬νμ νμ¬ νμ κ°λ
|
110 |
+
const currentRotation = this.turretGroup.rotation.y;
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
+
// λͺ©ν νμ κ°λ (차체 νμ κ³ λ €)
|
113 |
+
const targetRotation = mouseX;
|
114 |
+
|
115 |
+
// λΆλλ¬μ΄ νμ μ μν 보κ°
|
116 |
+
const rotationSpeed = 0.1;
|
117 |
+
const newRotation = currentRotation + (targetRotation - currentRotation) * rotationSpeed;
|
118 |
+
|
119 |
+
this.turretGroup.rotation.y = newRotation;
|
120 |
+
this.turretRotation = newRotation + this.body.rotation.y; // μ 체 νμ κ° μ μ₯
|
121 |
|
122 |
// νλ μ΄μ΄ μ΄μ μ
λ°μ΄νΈ
|
123 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
|
|
490 |
}
|
491 |
});
|
492 |
|
493 |
+
ddocument.addEventListener('mousemove', (event) => {
|
494 |
if (this.isLoading || this.isGameOver || !document.pointerLockElement) return;
|
495 |
|
|
|
496 |
const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
497 |
+
this.mouse.x += movementX * 0.002; // λμ νμ λμΌλ‘ λ³κ²½
|
498 |
+
this.mouse.y = 0; // YμΆμ μ¬μ©νμ§ μμ
|
|
|
|
|
499 |
|
500 |
+
// κ°λ μ κ·ν (-Ο ~ Ο)
|
501 |
+
while (this.mouse.x > Math.PI) this.mouse.x -= Math.PI * 2;
|
502 |
+
while (this.mouse.x < -Math.PI) this.mouse.x += Math.PI * 2;
|
503 |
});
|
504 |
|
505 |
|
|
|
551 |
const cameraDistance = 30;
|
552 |
const cameraHeight = 15;
|
553 |
|
554 |
+
// ν¬νμ νμ κ° μ¬μ©
|
555 |
+
const targetAngle = this.tank.turretRotation;
|
556 |
+
|
557 |
+
// νμ¬ μΉ΄λ©λΌ κ°λμ λͺ©ν κ°λ μ¬μ΄μ λΆλλ¬μ΄ μ ν
|
558 |
+
const currentCameraAngle = Math.atan2(
|
559 |
+
this.camera.position.x - tankPos.x,
|
560 |
+
this.camera.position.z - tankPos.z
|
561 |
+
);
|
562 |
+
|
563 |
+
let angleDiff = targetAngle + Math.PI - currentCameraAngle;
|
564 |
+
while (angleDiff > Math.PI) angleDiff -= Math.PI * 2;
|
565 |
+
while (angleDiff < -Math.PI) angleDiff += Math.PI * 2;
|
566 |
+
|
567 |
+
const smoothing = 0.1;
|
568 |
+
const newCameraAngle = currentCameraAngle + angleDiff * smoothing;
|
569 |
|
570 |
+
const cameraX = tankPos.x + Math.sin(newCameraAngle) * cameraDistance;
|
571 |
+
const cameraZ = tankPos.z + Math.cos(newCameraAngle) * cameraDistance;
|
572 |
|
|
|
573 |
this.camera.position.set(
|
574 |
cameraX,
|
575 |
tankPos.y + cameraHeight,
|