Spaces:
Running
Running
cutechicken
commited on
Commit
โข
dbfb9bd
1
Parent(s):
e239318
Update game.js
Browse files
game.js
CHANGED
@@ -105,6 +105,12 @@ class TankPlayer {
|
|
105 |
update(mouseX, mouseY, scene) {
|
106 |
if (!this.body || !this.turretGroup) return;
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
109 |
const bullet = this.bullets[i];
|
110 |
bullet.position.add(bullet.velocity);
|
@@ -115,13 +121,6 @@ class TankPlayer {
|
|
115 |
this.bullets.splice(i, 1);
|
116 |
}
|
117 |
}
|
118 |
-
|
119 |
-
// ํฌํ ํ์ ๋ฐฉํฅ ์์
|
120 |
-
if (this.turretGroup) {
|
121 |
-
const rotationAngle = -Math.atan2(mouseX, mouseY); // ๋ถํธ๋ฅผ ๋ฐ๋๋ก ํ์ฌ ํ์ ๋ฐฉํฅ ๋ณ๊ฒฝ
|
122 |
-
this.turretRotation = rotationAngle;
|
123 |
-
this.turretGroup.rotation.y = this.turretRotation;
|
124 |
-
}
|
125 |
}
|
126 |
|
127 |
move(direction) {
|
@@ -510,53 +509,54 @@ async addDesertDecorations() {
|
|
510 |
}
|
511 |
|
512 |
handleMovement() {
|
513 |
-
|
514 |
-
|
515 |
-
const direction = new THREE.Vector3();
|
516 |
-
|
517 |
-
if (this.keys.forward) direction.z += 1;
|
518 |
-
if (this.keys.backward) direction.z -= 1;
|
519 |
-
if (this.keys.left) direction.x -= 1;
|
520 |
-
if (this.keys.right) direction.x += 1;
|
521 |
-
|
522 |
-
if (direction.length() > 0) {
|
523 |
-
direction.normalize();
|
524 |
|
525 |
-
|
526 |
-
if (this.keys.right) this.tank.rotate(1);
|
527 |
|
528 |
-
|
529 |
-
this.
|
530 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
531 |
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
this.tank.turretGroup
|
538 |
-
|
|
|
539 |
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
}
|
561 |
|
562 |
createBuildings() {
|
|
|
105 |
update(mouseX, mouseY, scene) {
|
106 |
if (!this.body || !this.turretGroup) return;
|
107 |
|
108 |
+
// ํฌํ ํ์ ๊ณ์ฐ ์์
|
109 |
+
const rotationAngle = Math.atan2(mouseX, mouseY);
|
110 |
+
this.turretRotation = rotationAngle;
|
111 |
+
this.turretGroup.rotation.y = this.turretRotation;
|
112 |
+
|
113 |
+
// ์ด์ ์
๋ฐ์ดํธ ๋ก์ง
|
114 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
115 |
const bullet = this.bullets[i];
|
116 |
bullet.position.add(bullet.velocity);
|
|
|
121 |
this.bullets.splice(i, 1);
|
122 |
}
|
123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
}
|
125 |
|
126 |
move(direction) {
|
|
|
509 |
}
|
510 |
|
511 |
handleMovement() {
|
512 |
+
if (!this.tank.isLoaded || this.isGameOver) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
513 |
|
514 |
+
const direction = new THREE.Vector3();
|
|
|
515 |
|
516 |
+
if (this.keys.forward) direction.z += 1;
|
517 |
+
if (this.keys.backward) direction.z -= 1;
|
518 |
+
if (this.keys.left) direction.x -= 1;
|
519 |
+
if (this.keys.right) direction.x += 1;
|
520 |
+
|
521 |
+
if (direction.length() > 0) {
|
522 |
+
direction.normalize();
|
523 |
+
|
524 |
+
if (this.keys.left) this.tank.rotate(-1);
|
525 |
+
if (this.keys.right) this.tank.rotate(1);
|
526 |
+
|
527 |
+
direction.applyEuler(this.tank.body.rotation);
|
528 |
+
this.tank.move(direction);
|
529 |
+
}
|
530 |
|
531 |
+
// ๋ง์ฐ์ค ์์ง์์ ๋ฐ๋ฅธ ํฌํ ํ์ ์ฒ๋ฆฌ
|
532 |
+
const tankRotation = this.tank.body.rotation.y;
|
533 |
+
const mouseAngle = Math.atan2(this.mouse.x, -this.mouse.y);
|
534 |
+
const finalRotation = mouseAngle + tankRotation;
|
535 |
+
|
536 |
+
if (this.tank.turretGroup) {
|
537 |
+
this.tank.turretGroup.rotation.y = finalRotation;
|
538 |
+
}
|
539 |
|
540 |
+
// ์นด๋ฉ๋ผ ์์น ์
๋ฐ์ดํธ
|
541 |
+
const tankPos = this.tank.getPosition();
|
542 |
+
const cameraDistance = 30;
|
543 |
+
const cameraHeight = 15;
|
544 |
+
const lookAtHeight = 5;
|
545 |
+
|
546 |
+
this.camera.position.set(
|
547 |
+
tankPos.x - Math.sin(finalRotation) * cameraDistance,
|
548 |
+
tankPos.y + cameraHeight,
|
549 |
+
tankPos.z - Math.cos(finalRotation) * cameraDistance
|
550 |
+
);
|
551 |
+
|
552 |
+
const lookAtPoint = new THREE.Vector3(
|
553 |
+
tankPos.x + Math.sin(finalRotation) * 10,
|
554 |
+
tankPos.y + lookAtHeight,
|
555 |
+
tankPos.z + Math.cos(finalRotation) * 10
|
556 |
+
);
|
557 |
+
|
558 |
+
this.camera.lookAt(lookAtPoint);
|
559 |
+
}
|
560 |
}
|
561 |
|
562 |
createBuildings() {
|