cutechicken commited on
Commit
d7b0f1e
โ€ข
1 Parent(s): 4a23b1d

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +14 -15
game.js CHANGED
@@ -83,19 +83,18 @@ class TankPlayer {
83
  return null;
84
  }
85
 
 
 
 
 
86
  const bulletGeometry = new THREE.SphereGeometry(0.2);
87
  const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
88
  const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
89
 
90
- const bulletOffset = new THREE.Vector3(0, 0.5, 2);
91
- bulletOffset.applyQuaternion(this.turretGroup.quaternion);
92
- bulletOffset.applyQuaternion(this.body.quaternion);
93
- bullet.position.copy(this.body.position).add(bulletOffset);
94
-
95
- const direction = new THREE.Vector3(0, 0, 1);
96
- direction.applyQuaternion(this.turretGroup.quaternion);
97
- direction.applyQuaternion(this.body.quaternion);
98
- bullet.velocity = direction.multiplyScalar(2);
99
 
100
  scene.add(bullet);
101
  this.bullets.push(bullet);
@@ -106,8 +105,8 @@ class TankPlayer {
106
  document.getElementById('ammo').textContent = `${this.ammo}/10`;
107
 
108
  // ์—ฐ๊ธฐ ๋ฐ ๋ถˆ๊ฝƒ ํšจ๊ณผ ์ƒ์„ฑ
109
- this.createSmokeEffect(scene, bulletOffset);
110
- this.createMuzzleFlashEffect(scene, bulletOffset);
111
 
112
  // ๋ฐœ์‚ฌ ์†Œ๋ฆฌ ์žฌ์ƒ
113
  this.playRandomFireSound();
@@ -115,18 +114,17 @@ class TankPlayer {
115
  return bullet;
116
  }
117
 
118
-
119
- createMuzzleFlashEffect(scene, position) {
120
  // ๋น› ํšจ๊ณผ
121
  const flashLight = new THREE.PointLight(0xffaa00, 2, 10);
122
- flashLight.position.copy(this.body.position.clone().add(position));
123
  scene.add(flashLight);
124
 
125
  // ๋ถˆ๊ฝƒ ๊ตฌ์ฒด
126
  const flashGeometry = new THREE.SphereGeometry(0.3, 16, 16);
127
  const flashMaterial = new THREE.MeshBasicMaterial({ color: 0xffaa00 });
128
  const flashMesh = new THREE.Mesh(flashGeometry, flashMaterial);
129
- flashMesh.position.copy(this.body.position.clone().add(position));
130
  scene.add(flashMesh);
131
 
132
  // ๋ถˆ๊ฝƒ ํšจ๊ณผ ์—…๋ฐ์ดํŠธ
@@ -146,6 +144,7 @@ class TankPlayer {
146
  }
147
 
148
 
 
149
  // ์—ฐ๊ธฐ ํšจ๊ณผ ์ƒ์„ฑ ๋ฉ”์„œ๋“œ
150
  createSmokeEffect(scene, position) {
151
  const particleCount = 10;
 
83
  return null;
84
  }
85
 
86
+ // ํฌ์‹  ๋ ์ขŒํ‘œ ๊ณ„์‚ฐ
87
+ const barrelEndOffset = new THREE.Vector3(0, 0, 2); // ํฌ์‹  ๋ ์˜คํ”„์…‹ (Z ์ถ•)
88
+ const barrelEndPosition = this.turret.localToWorld(barrelEndOffset.clone());
89
+
90
  const bulletGeometry = new THREE.SphereGeometry(0.2);
91
  const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
92
  const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
93
 
94
+ bullet.position.copy(barrelEndPosition); // ํฌ์‹  ๋์—์„œ ๋ฐœ์‚ฌ
95
+ bullet.velocity = new THREE.Vector3(0, 0, 1)
96
+ .applyQuaternion(this.turret.quaternion)
97
+ .multiplyScalar(2);
 
 
 
 
 
98
 
99
  scene.add(bullet);
100
  this.bullets.push(bullet);
 
105
  document.getElementById('ammo').textContent = `${this.ammo}/10`;
106
 
107
  // ์—ฐ๊ธฐ ๋ฐ ๋ถˆ๊ฝƒ ํšจ๊ณผ ์ƒ์„ฑ
108
+ this.createSmokeEffect(scene, barrelEndPosition);
109
+ this.createMuzzleFlashEffect(scene, barrelEndPosition);
110
 
111
  // ๋ฐœ์‚ฌ ์†Œ๋ฆฌ ์žฌ์ƒ
112
  this.playRandomFireSound();
 
114
  return bullet;
115
  }
116
 
117
+ createMuzzleFlashEffect(scene, position) {
 
118
  // ๋น› ํšจ๊ณผ
119
  const flashLight = new THREE.PointLight(0xffaa00, 2, 10);
120
+ flashLight.position.copy(position); // ํฌ์‹  ๋ ์œ„์น˜์—์„œ ๋ถˆ๊ฝƒ ์ƒ์„ฑ
121
  scene.add(flashLight);
122
 
123
  // ๋ถˆ๊ฝƒ ๊ตฌ์ฒด
124
  const flashGeometry = new THREE.SphereGeometry(0.3, 16, 16);
125
  const flashMaterial = new THREE.MeshBasicMaterial({ color: 0xffaa00 });
126
  const flashMesh = new THREE.Mesh(flashGeometry, flashMaterial);
127
+ flashMesh.position.copy(position);
128
  scene.add(flashMesh);
129
 
130
  // ๋ถˆ๊ฝƒ ํšจ๊ณผ ์—…๋ฐ์ดํŠธ
 
144
  }
145
 
146
 
147
+
148
  // ์—ฐ๊ธฐ ํšจ๊ณผ ์ƒ์„ฑ ๋ฉ”์„œ๋“œ
149
  createSmokeEffect(scene, position) {
150
  const particleCount = 10;