Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -102,28 +102,27 @@ class TankPlayer {
|
|
102 |
return bullet;
|
103 |
}
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
116 |
}
|
117 |
-
}
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
}
|
126 |
-
}
|
127 |
|
128 |
move(direction) {
|
129 |
if (!this.body) return;
|
@@ -873,7 +872,7 @@ async addDesertDecorations() {
|
|
873 |
|
874 |
if (!this.isLoading) {
|
875 |
this.handleMovement();
|
876 |
-
this.tank.update(this.mouse.x, this.mouse.y);
|
877 |
|
878 |
const tankPosition = this.tank.getPosition();
|
879 |
this.enemies.forEach(enemy => {
|
|
|
102 |
return bullet;
|
103 |
}
|
104 |
|
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);
|
111 |
+
|
112 |
+
if (Math.abs(bullet.position.x) > MAP_SIZE/2 ||
|
113 |
+
Math.abs(bullet.position.z) > MAP_SIZE/2) {
|
114 |
+
scene.remove(bullet);
|
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) {
|
128 |
if (!this.body) return;
|
|
|
872 |
|
873 |
if (!this.isLoading) {
|
874 |
this.handleMovement();
|
875 |
+
this.tank.update(this.mouse.x, this.mouse.y, this.scene); // scene ๊ฐ์ฒด ์ ๋ฌ
|
876 |
|
877 |
const tankPosition = this.tank.getPosition();
|
878 |
this.enemies.forEach(enemy => {
|