cutechicken commited on
Commit
57e9535
ยท
verified ยท
1 Parent(s): c82a71e

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +19 -20
game.js CHANGED
@@ -102,28 +102,27 @@ class TankPlayer {
102
  return bullet;
103
  }
104
 
105
- update(mouseX, mouseY) {
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
- // ๋งˆ์šฐ์Šค ์›€์ง์ž„์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ํšŒ์ „๊ฐ ๊ณ„์‚ฐ
122
- const rotationAngle = -Math.atan2(mouseX, mouseY); // ๋ถ€ํ˜ธ๋ฅผ ๋ฐ˜๋Œ€๋กœ ํ•˜์—ฌ ํšŒ์ „ ๋ฐฉํ–ฅ ๋ณ€๊ฒฝ
123
- this.turretRotation = rotationAngle;
124
- this.turretGroup.rotation.y = this.turretRotation;
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 => {