cutechicken commited on
Commit
79d8666
β€’
1 Parent(s): 15a66ff

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +25 -19
game.js CHANGED
@@ -104,25 +104,31 @@ class TankPlayer {
104
 
105
  // TankPlayer 클래슀 λ‚΄λΆ€
106
  update(mouseX, mouseY, scene) {
107
- if (!this.body || !this.turretGroup) return;
108
-
109
- // ν¬νƒ‘μ˜ μ ˆλŒ€ νšŒμ „ (차체 νšŒμ „κ³Ό 독립적)
110
- this.turretGroup.rotation.y = mouseX;
111
- this.turretRotation = mouseX; // 차체 νšŒμ „μ„ λ”ν•˜μ§€ μ•ŠμŒ
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);
117
-
118
- if (
119
- Math.abs(bullet.position.x) > MAP_SIZE / 2 ||
120
- Math.abs(bullet.position.z) > MAP_SIZE / 2
121
- ) {
122
- scene.remove(bullet);
123
- this.bullets.splice(i, 1);
124
- }
125
- }
 
 
 
 
 
 
126
  }
127
 
128
 
 
104
 
105
  // TankPlayer 클래슀 λ‚΄λΆ€
106
  update(mouseX, mouseY, scene) {
107
+ if (!this.body || !this.turretGroup) return;
108
+
109
+ // 포탑이 λ°”λΌλ³΄λŠ” μ ˆλŒ€ λ°©ν–₯ 계산
110
+ const absoluteTurretRotation = mouseX;
111
+
112
+ // 차체 νšŒμ „μ„ μƒμ‡„ν•˜λŠ” 포탑 νšŒμ „ 계산
113
+ // 차체가 νšŒμ „ν•˜λ©΄ 그만큼 λ°˜λŒ€λ‘œ νšŒμ „ν•˜μ—¬ μ ˆλŒ€ λ°©ν–₯ μœ μ§€
114
+ this.turretGroup.rotation.y = absoluteTurretRotation - this.body.rotation.y;
115
+
116
+ // 전체 νšŒμ „κ°μ€ μ ˆλŒ€ λ°©ν–₯ κ·ΈλŒ€λ‘œ μœ μ§€
117
+ this.turretRotation = absoluteTurretRotation;
118
+
119
+ // ν”Œλ ˆμ΄μ–΄ μ΄μ•Œ μ—…λ°μ΄νŠΈ
120
+ for (let i = this.bullets.length - 1; i >= 0; i--) {
121
+ const bullet = this.bullets[i];
122
+ bullet.position.add(bullet.velocity);
123
+
124
+ if (
125
+ Math.abs(bullet.position.x) > MAP_SIZE / 2 ||
126
+ Math.abs(bullet.position.z) > MAP_SIZE / 2
127
+ ) {
128
+ scene.remove(bullet);
129
+ this.bullets.splice(i, 1);
130
+ }
131
+ }
132
  }
133
 
134