Spaces:
Running
Running
cutechicken
commited on
Commit
β’
ebc3901
1
Parent(s):
1bd8588
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 |
|