Spaces:
Running
Running
cutechicken
commited on
Commit
β’
4f3870f
1
Parent(s):
7aaeb16
Update game.js
Browse files
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
|
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(
|
164 |
flashGroup.add(flame);
|
165 |
|
166 |
-
// μ°κΈ°
|
167 |
-
const smokeGeometry = new THREE.SphereGeometry(0.
|
168 |
const smokeMaterial = new THREE.MeshBasicMaterial({
|
169 |
color: 0x555555,
|
170 |
transparent: true,
|
171 |
opacity: 0.5
|
172 |
});
|
173 |
-
|
|
|
174 |
const smoke = new THREE.Mesh(smokeGeometry, smokeMaterial);
|
175 |
smoke.position.set(
|
176 |
-
Math.random() *
|
177 |
-
Math.random() *
|
178 |
-
-
|
179 |
);
|
|
|
180 |
flashGroup.add(smoke);
|
181 |
}
|
182 |
|
183 |
-
//
|
184 |
-
const
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
flashGroup.position.copy(muzzlePosition);
|
|
|
188 |
|
189 |
-
// μ¬μ μΆκ°
|
190 |
scene.add(flashGroup);
|
191 |
|
192 |
-
//
|
193 |
setTimeout(() => {
|
194 |
scene.remove(flashGroup);
|
195 |
-
},
|
196 |
}
|
197 |
|
198 |
|
199 |
|
200 |
-
|
201 |
createBullet(scene) {
|
202 |
-
|
|
|
203 |
const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0xffd700 });
|
204 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
205 |
|
206 |
-
|
207 |
-
const
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
const direction = new THREE.Vector3(0, 0, 1);
|
213 |
-
direction.applyQuaternion(
|
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);
|