cutechicken commited on
Commit
e9310dc
β€’
1 Parent(s): ef6acf7

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +68 -15
game.js CHANGED
@@ -136,6 +136,10 @@ class TankPlayer {
136
  audio.volume = 0.5;
137
  audio.play();
138
 
 
 
 
 
139
  const bullet = this.createBullet(scene);
140
  if (bullet) {
141
  this.ammo--;
@@ -145,27 +149,76 @@ class TankPlayer {
145
  return bullet;
146
  }
147
 
148
- createBullet(scene) {
149
- const bulletGeometry = new THREE.SphereGeometry(0.2);
150
- const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
151
- const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
152
 
153
- const bulletOffset = new THREE.Vector3(0, 0.5, 2);
154
- bulletOffset.applyQuaternion(this.turretGroup.quaternion);
155
- bulletOffset.applyQuaternion(this.body.quaternion);
156
- bullet.position.copy(this.body.position).add(bulletOffset);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
- const direction = new THREE.Vector3(0, 0, 1);
159
- direction.applyQuaternion(this.turretGroup.quaternion);
160
- direction.applyQuaternion(this.body.quaternion);
161
- bullet.velocity = direction.multiplyScalar(2);
 
162
 
163
- scene.add(bullet);
164
- this.bullets.push(bullet);
165
 
166
- return bullet;
 
 
 
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  update(mouseX, mouseY, scene) {
170
  if (!this.body || !this.turretGroup) return;
171
 
 
136
  audio.volume = 0.5;
137
  audio.play();
138
 
139
+ // λ°œμ‚¬ μ΄νŽ™νŠΈ μΆ”κ°€
140
+ this.createMuzzleFlash(scene);
141
+
142
+ // 포탄 생성
143
  const bullet = this.createBullet(scene);
144
  if (bullet) {
145
  this.ammo--;
 
149
  return bullet;
150
  }
151
 
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.5, 2);
185
+ muzzlePosition.applyQuaternion(this.turretGroup.quaternion);
186
+ muzzlePosition.applyQuaternion(this.body.quaternion);
187
+ flashGroup.position.copy(this.body.position).add(muzzlePosition);
188
 
189
+ // 씬에 μΆ”κ°€
190
+ scene.add(flashGroup);
191
 
192
+ // 일정 μ‹œκ°„ ν›„ 제거
193
+ setTimeout(() => {
194
+ scene.remove(flashGroup);
195
+ }, 300); // 300ms μœ μ§€
196
  }
197
 
198
+
199
+ createBullet(scene) {
200
+ const bulletGeometry = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
201
+ const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0xffd700 });
202
+ const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
203
+
204
+ bullet.rotation.x = Math.PI / 2; // μˆ˜ν‰μœΌλ‘œ νšŒμ „
205
+ const bulletOffset = new THREE.Vector3(0, 0.5, 2);
206
+ bulletOffset.applyQuaternion(this.turretGroup.quaternion);
207
+ bulletOffset.applyQuaternion(this.body.quaternion);
208
+ bullet.position.copy(this.body.position).add(bulletOffset);
209
+
210
+ const direction = new THREE.Vector3(0, 0, 1);
211
+ direction.applyQuaternion(this.turretGroup.quaternion);
212
+ direction.applyQuaternion(this.body.quaternion);
213
+ bullet.velocity = direction.multiplyScalar(5);
214
+
215
+ scene.add(bullet);
216
+ this.bullets.push(bullet);
217
+
218
+ return bullet;
219
+ }
220
+
221
+
222
  update(mouseX, mouseY, scene) {
223
  if (!this.body || !this.turretGroup) return;
224