Update game.js
Browse files
game.js
CHANGED
|
@@ -39,6 +39,127 @@ class TankPlayer {
|
|
| 39 |
this.lastShootTime = 0;
|
| 40 |
this.bullets = [];
|
| 41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
async initialize(scene, loader) {
|
| 44 |
try {
|
|
@@ -48,6 +169,7 @@ class TankPlayer {
|
|
| 48 |
const turretResult = await loader.loadAsync('/models/abramsTurret.glb');
|
| 49 |
this.turret = turretResult.scene;
|
| 50 |
|
|
|
|
| 51 |
this.turretGroup.position.y = 0.2;
|
| 52 |
this.turretGroup.add(this.turret);
|
| 53 |
this.body.add(this.turretGroup);
|
|
|
|
| 39 |
this.lastShootTime = 0;
|
| 40 |
this.bullets = [];
|
| 41 |
}
|
| 42 |
+
// 별도의 메서드로 분리
|
| 43 |
+
createExplosionEffect(scene, position) {
|
| 44 |
+
// 폭발 중심 플래시
|
| 45 |
+
const flashGeometry = new THREE.SphereGeometry(3);
|
| 46 |
+
const flashMaterial = new THREE.MeshBasicMaterial({
|
| 47 |
+
color: 0xffff00,
|
| 48 |
+
transparent: true,
|
| 49 |
+
opacity: 1
|
| 50 |
+
});
|
| 51 |
+
const flash = new THREE.Mesh(flashGeometry, flashMaterial);
|
| 52 |
+
flash.position.copy(position);
|
| 53 |
+
scene.add(flash);
|
| 54 |
+
|
| 55 |
+
// 폭발 파티클
|
| 56 |
+
for (let i = 0; i < 30; i++) {
|
| 57 |
+
const size = Math.random() * 0.5 + 0.3;
|
| 58 |
+
const geometry = new THREE.SphereGeometry(size);
|
| 59 |
+
|
| 60 |
+
const colors = [0xff4500, 0xff8c00, 0xff0000, 0xffd700];
|
| 61 |
+
const material = new THREE.MeshBasicMaterial({
|
| 62 |
+
color: colors[Math.floor(Math.random() * colors.length)],
|
| 63 |
+
transparent: true,
|
| 64 |
+
opacity: 1
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
const particle = new THREE.Mesh(geometry, material);
|
| 68 |
+
particle.position.copy(position);
|
| 69 |
+
|
| 70 |
+
const speed = Math.random() * 0.5 + 0.3;
|
| 71 |
+
const angle = Math.random() * Math.PI * 2;
|
| 72 |
+
const elevation = Math.random() * Math.PI - Math.PI / 2;
|
| 73 |
+
|
| 74 |
+
particle.velocity = new THREE.Vector3(
|
| 75 |
+
Math.cos(angle) * Math.cos(elevation) * speed,
|
| 76 |
+
Math.sin(elevation) * speed,
|
| 77 |
+
Math.sin(angle) * Math.cos(elevation) * speed
|
| 78 |
+
);
|
| 79 |
+
|
| 80 |
+
particle.gravity = -0.015;
|
| 81 |
+
particle.life = Math.random() * 30 + 30;
|
| 82 |
+
particle.fadeRate = 0.97;
|
| 83 |
+
|
| 84 |
+
scene.add(particle);
|
| 85 |
+
window.gameInstance.particles.push({
|
| 86 |
+
mesh: particle,
|
| 87 |
+
velocity: particle.velocity,
|
| 88 |
+
gravity: particle.gravity,
|
| 89 |
+
life: particle.life,
|
| 90 |
+
fadeRate: particle.fadeRate
|
| 91 |
+
});
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// 폭발 링 이펙트
|
| 95 |
+
this.createExplosionRing(scene, position);
|
| 96 |
+
|
| 97 |
+
// 사운드 효과
|
| 98 |
+
this.playExplosionSound();
|
| 99 |
+
|
| 100 |
+
// 카메라 흔들림 효과
|
| 101 |
+
this.createCameraShake(scene);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// 보조 메서드들로 분리
|
| 105 |
+
createExplosionRing(scene, position) {
|
| 106 |
+
const ringGeometry = new THREE.RingGeometry(0.1, 2, 32);
|
| 107 |
+
const ringMaterial = new THREE.MeshBasicMaterial({
|
| 108 |
+
color: 0xff8c00,
|
| 109 |
+
transparent: true,
|
| 110 |
+
opacity: 1,
|
| 111 |
+
side: THREE.DoubleSide
|
| 112 |
+
});
|
| 113 |
+
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
|
| 114 |
+
ring.position.copy(position);
|
| 115 |
+
ring.lookAt(new THREE.Vector3(0, 1, 0));
|
| 116 |
+
scene.add(ring);
|
| 117 |
+
|
| 118 |
+
const expandRing = () => {
|
| 119 |
+
ring.scale.x += 0.2;
|
| 120 |
+
ring.scale.y += 0.2;
|
| 121 |
+
ring.material.opacity *= 0.95;
|
| 122 |
+
|
| 123 |
+
if (ring.material.opacity > 0.01) {
|
| 124 |
+
requestAnimationFrame(expandRing);
|
| 125 |
+
} else {
|
| 126 |
+
scene.remove(ring);
|
| 127 |
+
}
|
| 128 |
+
};
|
| 129 |
+
expandRing();
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
playExplosionSound() {
|
| 133 |
+
const explosionSounds = ['sounds/explosion.ogg'];
|
| 134 |
+
const randomSound = explosionSounds[Math.floor(Math.random() * explosionSounds.length)];
|
| 135 |
+
const audio = new Audio(randomSound);
|
| 136 |
+
audio.volume = 0.4;
|
| 137 |
+
audio.play();
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
createCameraShake(scene) {
|
| 141 |
+
if (window.gameInstance && window.gameInstance.camera) {
|
| 142 |
+
const camera = window.gameInstance.camera;
|
| 143 |
+
const originalPosition = camera.position.clone();
|
| 144 |
+
let shakeTime = 0;
|
| 145 |
+
const shakeIntensity = 0.3;
|
| 146 |
+
const shakeDuration = 500;
|
| 147 |
+
|
| 148 |
+
const shakeCamera = () => {
|
| 149 |
+
if (shakeTime < shakeDuration) {
|
| 150 |
+
camera.position.x = originalPosition.x + (Math.random() - 0.5) * shakeIntensity;
|
| 151 |
+
camera.position.y = originalPosition.y + (Math.random() - 0.5) * shakeIntensity;
|
| 152 |
+
camera.position.z = originalPosition.z + (Math.random() - 0.5) * shakeIntensity;
|
| 153 |
+
|
| 154 |
+
shakeTime += 16;
|
| 155 |
+
requestAnimationFrame(shakeCamera);
|
| 156 |
+
} else {
|
| 157 |
+
camera.position.copy(originalPosition);
|
| 158 |
+
}
|
| 159 |
+
};
|
| 160 |
+
shakeCamera();
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
|
| 164 |
async initialize(scene, loader) {
|
| 165 |
try {
|
|
|
|
| 169 |
const turretResult = await loader.loadAsync('/models/abramsTurret.glb');
|
| 170 |
this.turret = turretResult.scene;
|
| 171 |
|
| 172 |
+
|
| 173 |
this.turretGroup.position.y = 0.2;
|
| 174 |
this.turretGroup.add(this.turret);
|
| 175 |
this.body.add(this.turretGroup);
|