Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -160,6 +160,15 @@ class TankPlayer {
|
|
| 160 |
|
| 161 |
async initialize(scene, loader) {
|
| 162 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
const bodyResult = await loader.loadAsync('/models/abramsBody.glb');
|
| 164 |
this.body = bodyResult.scene;
|
| 165 |
|
|
@@ -169,13 +178,15 @@ class TankPlayer {
|
|
| 169 |
this.turretGroup.position.y = 0.2;
|
| 170 |
this.turretGroup.add(this.turret);
|
| 171 |
this.body.add(this.turretGroup);
|
|
|
|
| 172 |
// 탱크 위치 높이 조정
|
| 173 |
-
this.body.position.y = 1.5;
|
| 174 |
|
| 175 |
-
// 그림자 평면
|
| 176 |
this.shadowPlane.position.y = -1.0;
|
|
|
|
| 177 |
|
| 178 |
-
// 그림자
|
| 179 |
this.body.traverse((child) => {
|
| 180 |
if (child.isMesh) {
|
| 181 |
child.castShadow = true;
|
|
@@ -194,68 +205,15 @@ class TankPlayer {
|
|
| 194 |
}
|
| 195 |
});
|
| 196 |
|
| 197 |
-
//
|
| 198 |
-
const shadowPlaneGeometry = new THREE.PlaneGeometry(8, 8);
|
| 199 |
-
const shadowPlaneMaterial = new THREE.ShadowMaterial({
|
| 200 |
-
opacity: 0.3
|
| 201 |
-
});
|
| 202 |
-
this.shadowPlane = new THREE.Mesh(shadowPlaneGeometry, shadowPlaneMaterial);
|
| 203 |
-
this.shadowPlane.receiveShadow = true;
|
| 204 |
-
this.shadowPlane.rotation.x = -Math.PI / 2;
|
| 205 |
-
this.shadowPlane.position.y = 0.1;
|
| 206 |
-
this.body.add(this.shadowPlane);
|
| 207 |
-
|
| 208 |
-
// 간단한 스폰 위치 설정
|
| 209 |
const spawnPosition = new THREE.Vector3(
|
| 210 |
-
(Math.random() - 0.5) * (MAP_SIZE * 0.8),
|
| 211 |
-
TANK_HEIGHT,
|
| 212 |
(Math.random() - 0.5) * (MAP_SIZE * 0.8)
|
| 213 |
);
|
| 214 |
|
| 215 |
this.body.position.copy(spawnPosition);
|
| 216 |
|
| 217 |
-
// 폭발 이펙트 메서드 추가
|
| 218 |
-
this.createExplosionEffect = (scene, position) => {
|
| 219 |
-
// 폭발 파티클
|
| 220 |
-
for (let i = 0; i < 15; i++) {
|
| 221 |
-
const size = Math.random() * 0.2 + 0.1;
|
| 222 |
-
const geometry = new THREE.SphereGeometry(size);
|
| 223 |
-
const material = new THREE.MeshBasicMaterial({
|
| 224 |
-
color: Math.random() < 0.5 ? 0xff4500 : 0xff8c00
|
| 225 |
-
});
|
| 226 |
-
const particle = new THREE.Mesh(geometry, material);
|
| 227 |
-
particle.position.copy(position);
|
| 228 |
-
|
| 229 |
-
const speed = Math.random() * 0.3 + 0.2;
|
| 230 |
-
const angle = Math.random() * Math.PI * 2;
|
| 231 |
-
const elevation = Math.random() * Math.PI - Math.PI / 2;
|
| 232 |
-
|
| 233 |
-
particle.velocity = new THREE.Vector3(
|
| 234 |
-
Math.cos(angle) * Math.cos(elevation) * speed,
|
| 235 |
-
Math.sin(elevation) * speed,
|
| 236 |
-
Math.sin(angle) * Math.cos(elevation) * speed
|
| 237 |
-
);
|
| 238 |
-
|
| 239 |
-
particle.gravity = -0.01;
|
| 240 |
-
particle.life = Math.random() * 20 + 20;
|
| 241 |
-
particle.fadeRate = 1 / particle.life;
|
| 242 |
-
|
| 243 |
-
scene.add(particle);
|
| 244 |
-
window.gameInstance.particles.push({
|
| 245 |
-
mesh: particle,
|
| 246 |
-
velocity: particle.velocity,
|
| 247 |
-
gravity: particle.gravity,
|
| 248 |
-
life: particle.life,
|
| 249 |
-
fadeRate: particle.fadeRate
|
| 250 |
-
});
|
| 251 |
-
}
|
| 252 |
-
|
| 253 |
-
// 충돌 사운드 재생
|
| 254 |
-
const explosionSound = new Audio('sounds/explosion.ogg');
|
| 255 |
-
explosionSound.volume = 0.3;
|
| 256 |
-
explosionSound.play();
|
| 257 |
-
};
|
| 258 |
-
|
| 259 |
scene.add(this.body);
|
| 260 |
this.isLoaded = true;
|
| 261 |
this.updateAmmoDisplay();
|
|
|
|
| 160 |
|
| 161 |
async initialize(scene, loader) {
|
| 162 |
try {
|
| 163 |
+
// 그림자 평면 먼저 생성
|
| 164 |
+
const shadowPlaneGeometry = new THREE.PlaneGeometry(8, 8);
|
| 165 |
+
const shadowPlaneMaterial = new THREE.ShadowMaterial({
|
| 166 |
+
opacity: 0.3
|
| 167 |
+
});
|
| 168 |
+
this.shadowPlane = new THREE.Mesh(shadowPlaneGeometry, shadowPlaneMaterial);
|
| 169 |
+
this.shadowPlane.receiveShadow = true;
|
| 170 |
+
this.shadowPlane.rotation.x = -Math.PI / 2;
|
| 171 |
+
|
| 172 |
const bodyResult = await loader.loadAsync('/models/abramsBody.glb');
|
| 173 |
this.body = bodyResult.scene;
|
| 174 |
|
|
|
|
| 178 |
this.turretGroup.position.y = 0.2;
|
| 179 |
this.turretGroup.add(this.turret);
|
| 180 |
this.body.add(this.turretGroup);
|
| 181 |
+
|
| 182 |
// 탱크 위치 높이 조정
|
| 183 |
+
this.body.position.y = 1.5;
|
| 184 |
|
| 185 |
+
// 그림자 평면 위치 조정 (body가 생성된 후에)
|
| 186 |
this.shadowPlane.position.y = -1.0;
|
| 187 |
+
this.body.add(this.shadowPlane);
|
| 188 |
|
| 189 |
+
// 그림자 설정
|
| 190 |
this.body.traverse((child) => {
|
| 191 |
if (child.isMesh) {
|
| 192 |
child.castShadow = true;
|
|
|
|
| 205 |
}
|
| 206 |
});
|
| 207 |
|
| 208 |
+
// 스폰 위치 설정
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
const spawnPosition = new THREE.Vector3(
|
| 210 |
+
(Math.random() - 0.5) * (MAP_SIZE * 0.8),
|
| 211 |
+
TANK_HEIGHT,
|
| 212 |
(Math.random() - 0.5) * (MAP_SIZE * 0.8)
|
| 213 |
);
|
| 214 |
|
| 215 |
this.body.position.copy(spawnPosition);
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
scene.add(this.body);
|
| 218 |
this.isLoaded = true;
|
| 219 |
this.updateAmmoDisplay();
|