cutechicken commited on
Commit
4f3870f
ยท
verified ยท
1 Parent(s): 7aaeb16

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +45 -25
game.js CHANGED
@@ -152,66 +152,86 @@ class TankPlayer {
152
  createMuzzleFlash(scene) {
153
  const flashGroup = new THREE.Group();
154
 
155
- // ํ™”์—ผ ์ƒ์„ฑ
156
- const flameGeometry = new THREE.SphereGeometry(0.5, 8, 8);
157
  const flameMaterial = new THREE.MeshBasicMaterial({
158
  color: 0xffa500,
159
  transparent: true,
160
  opacity: 0.8
161
  });
162
  const flame = new THREE.Mesh(flameGeometry, flameMaterial);
163
- flame.scale.set(1.5, 1.5, 2);
164
  flashGroup.add(flame);
165
 
166
- // ์—ฐ๊ธฐ ์ƒ์„ฑ
167
- const smokeGeometry = new THREE.SphereGeometry(0.3, 8, 8);
168
  const smokeMaterial = new THREE.MeshBasicMaterial({
169
  color: 0x555555,
170
  transparent: true,
171
  opacity: 0.5
172
  });
173
- for (let i = 0; i < 3; i++) {
 
174
  const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
175
  smoke.position.set(
176
- Math.random() * 0.5 - 0.25,
177
- Math.random() * 0.5 - 0.25,
178
- -0.5 - Math.random() * 0.5
179
  );
 
180
  flashGroup.add(smoke);
181
  }
182
 
183
- // ํฌํƒ‘ ๋์˜ ์ „์—ญ ์ขŒํ‘œ ๊ณ„์‚ฐ
184
- const muzzlePosition = new THREE.Vector3(0, 0, 2); // ํฌํƒ‘ ๋์˜ ๋กœ์ปฌ ์ขŒํ‘œ (ํฌ์‹ ์˜ ๋)
185
- this.turret.localToWorld(muzzlePosition); // ๋กœ์ปฌ ์ขŒํ‘œ๋ฅผ ์ „์—ญ ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
 
 
 
 
 
 
 
186
 
187
  flashGroup.position.copy(muzzlePosition);
 
188
 
189
- // ์”ฌ์— ์ถ”๊ฐ€
190
  scene.add(flashGroup);
191
 
192
- // ์ผ์ • ์‹œ๊ฐ„ ํ›„ ์ œ๊ฑฐ
193
  setTimeout(() => {
194
  scene.remove(flashGroup);
195
- }, 300); // 300ms ์œ ์ง€
196
  }
197
 
198
 
199
 
200
-
201
  createBullet(scene) {
202
- const bulletGeometry = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
 
203
  const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0xffd700 });
204
  const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
205
 
206
- bullet.rotation.x = Math.PI / 2; // ์ˆ˜ํ‰์œผ๋กœ ํšŒ์ „
207
- const bulletOffset = new THREE.Vector3(0, 0.5, 2);
208
- bulletOffset.applyQuaternion(this.turretGroup.quaternion);
209
- bulletOffset.applyQuaternion(this.body.quaternion);
210
- bullet.position.copy(this.body.position).add(bulletOffset);
211
-
 
 
 
 
 
 
 
 
 
 
 
 
212
  const direction = new THREE.Vector3(0, 0, 1);
213
- direction.applyQuaternion(this.turretGroup.quaternion);
214
- direction.applyQuaternion(this.body.quaternion);
215
  bullet.velocity = direction.multiplyScalar(5);
216
 
217
  scene.add(bullet);
 
152
  createMuzzleFlash(scene) {
153
  const flashGroup = new THREE.Group();
154
 
155
+ // ํ™”์—ผ ํฌ๊ธฐ ์ฆ๊ฐ€
156
+ const flameGeometry = new THREE.SphereGeometry(1.0, 8, 8);
157
  const flameMaterial = new THREE.MeshBasicMaterial({
158
  color: 0xffa500,
159
  transparent: true,
160
  opacity: 0.8
161
  });
162
  const flame = new THREE.Mesh(flameGeometry, flameMaterial);
163
+ flame.scale.set(2, 2, 3);
164
  flashGroup.add(flame);
165
 
166
+ // ์—ฐ๊ธฐ ํšจ๊ณผ ํฌ๊ธฐ ์ฆ๊ฐ€
167
+ const smokeGeometry = new THREE.SphereGeometry(0.8, 8, 8);
168
  const smokeMaterial = new THREE.MeshBasicMaterial({
169
  color: 0x555555,
170
  transparent: true,
171
  opacity: 0.5
172
  });
173
+
174
+ for (let i = 0; i < 5; i++) { // ์—ฐ๊ธฐ ํŒŒํ‹ฐํด ์ˆ˜ ์ฆ๊ฐ€
175
  const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
176
  smoke.position.set(
177
+ Math.random() * 1 - 0.5,
178
+ Math.random() * 1 - 0.5,
179
+ -1 - Math.random()
180
  );
181
+ smoke.scale.set(1.5, 1.5, 1.5);
182
  flashGroup.add(smoke);
183
  }
184
 
185
+ // ํฌ๊ตฌ ์œ„์น˜ ๊ณ„์‚ฐ
186
+ const muzzleOffset = new THREE.Vector3(0, 0.5, 4);
187
+ const muzzlePosition = new THREE.Vector3();
188
+ const turretWorldQuaternion = new THREE.Quaternion();
189
+
190
+ this.turret.getWorldPosition(muzzlePosition);
191
+ this.turret.getWorldQuaternion(turretWorldQuaternion);
192
+
193
+ muzzleOffset.applyQuaternion(turretWorldQuaternion);
194
+ muzzlePosition.add(muzzleOffset);
195
 
196
  flashGroup.position.copy(muzzlePosition);
197
+ flashGroup.quaternion.copy(turretWorldQuaternion);
198
 
 
199
  scene.add(flashGroup);
200
 
201
+ // ์ดํŽ™ํŠธ ์ง€์† ์‹œ๊ฐ„ ์ฆ๊ฐ€
202
  setTimeout(() => {
203
  scene.remove(flashGroup);
204
+ }, 500);
205
  }
206
 
207
 
208
 
 
209
  createBullet(scene) {
210
+ // ํฌํƒ„ ํฌ๊ธฐ ์ฆ๊ฐ€
211
+ const bulletGeometry = new THREE.CylinderGeometry(0.2, 0.2, 2, 8);
212
  const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0xffd700 });
213
  const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
214
 
215
+ // ํฌํƒ‘์˜ ์›”๋“œ ์œ„์น˜์™€ ๋ฐฉํ–ฅ ๊ฐ€์ ธ์˜ค๊ธฐ
216
+ const muzzleOffset = new THREE.Vector3(0, 0.5, 4); // ํฌ๊ตฌ ์œ„์น˜ ์กฐ์ • (์•ž์ชฝ์œผ๋กœ ๋” ์ด๋™)
217
+ const muzzlePosition = new THREE.Vector3();
218
+ const turretWorldQuaternion = new THREE.Quaternion();
219
+
220
+ // ํฌํƒ‘์˜ ์›”๋“œ ๋ณ€ํ™˜ ํ–‰๋ ฌ ๊ฐ€์ ธ์˜ค๊ธฐ
221
+ this.turret.getWorldPosition(muzzlePosition);
222
+ this.turret.getWorldQuaternion(turretWorldQuaternion);
223
+
224
+ // ํฌ๊ตฌ ์˜คํ”„์…‹ ์ ์šฉ
225
+ muzzleOffset.applyQuaternion(turretWorldQuaternion);
226
+ muzzlePosition.add(muzzleOffset);
227
+
228
+ // ํฌํƒ„ ์œ„์น˜์™€ ํšŒ์ „ ์„ค์ •
229
+ bullet.position.copy(muzzlePosition);
230
+ bullet.quaternion.copy(turretWorldQuaternion);
231
+
232
+ // ๋ฐœ์‚ฌ ๋ฐฉํ–ฅ ์„ค์ •
233
  const direction = new THREE.Vector3(0, 0, 1);
234
+ direction.applyQuaternion(turretWorldQuaternion);
 
235
  bullet.velocity = direction.multiplyScalar(5);
236
 
237
  scene.add(bullet);