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);
|