Spaces:
Running
Running
cutechicken
commited on
Commit
β’
20b339e
1
Parent(s):
8495bf4
Update game.js
Browse files
game.js
CHANGED
@@ -41,125 +41,118 @@ class TankPlayer {
|
|
41 |
}
|
42 |
// λ³λμ λ©μλλ‘ λΆλ¦¬
|
43 |
createExplosionEffect(scene, position) {
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
transparent: true,
|
49 |
opacity: 1
|
50 |
});
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
//
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
|
104 |
-
//
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
} else {
|
126 |
-
|
127 |
}
|
128 |
};
|
129 |
-
|
130 |
}
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
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 {
|
|
|
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 |
+
// λ€μν μμμ νν°ν΄
|
61 |
+
const colors = [0xff4500, 0xff8c00, 0xff0000, 0xffd700];
|
62 |
+
const material = new THREE.MeshBasicMaterial({
|
63 |
+
color: colors[Math.floor(Math.random() * colors.length)],
|
64 |
transparent: true,
|
65 |
opacity: 1
|
66 |
});
|
67 |
+
|
68 |
+
const particle = new THREE.Mesh(geometry, material);
|
69 |
+
particle.position.copy(position);
|
70 |
+
|
71 |
+
// νν°ν΄ μλμ λ°©ν₯ μ€μ
|
72 |
+
const speed = Math.random() * 0.5 + 0.3;
|
73 |
+
const angle = Math.random() * Math.PI * 2;
|
74 |
+
const elevation = Math.random() * Math.PI - Math.PI / 2;
|
75 |
+
|
76 |
+
particle.velocity = new THREE.Vector3(
|
77 |
+
Math.cos(angle) * Math.cos(elevation) * speed,
|
78 |
+
Math.sin(elevation) * speed,
|
79 |
+
Math.sin(angle) * Math.cos(elevation) * speed
|
80 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
+
particle.gravity = -0.015;
|
83 |
+
particle.life = Math.random() * 30 + 30;
|
84 |
+
particle.fadeRate = 0.97;
|
85 |
+
|
86 |
+
scene.add(particle);
|
87 |
+
window.gameInstance.particles.push({
|
88 |
+
mesh: particle,
|
89 |
+
velocity: particle.velocity,
|
90 |
+
gravity: particle.gravity,
|
91 |
+
life: particle.life,
|
92 |
+
fadeRate: particle.fadeRate
|
93 |
+
});
|
94 |
}
|
95 |
|
96 |
+
// νλ° λ§ μ΄ννΈ
|
97 |
+
const ringGeometry = new THREE.RingGeometry(0.1, 2, 32);
|
98 |
+
const ringMaterial = new THREE.MeshBasicMaterial({
|
99 |
+
color: 0xff8c00,
|
100 |
+
transparent: true,
|
101 |
+
opacity: 1,
|
102 |
+
side: THREE.DoubleSide
|
103 |
+
});
|
104 |
+
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
|
105 |
+
ring.position.copy(position);
|
106 |
+
ring.lookAt(new THREE.Vector3(0, 1, 0));
|
107 |
+
scene.add(ring);
|
108 |
+
|
109 |
+
// λ§ νμ₯ μ λλ©μ΄μ
|
110 |
+
const expandRing = () => {
|
111 |
+
ring.scale.x += 0.2;
|
112 |
+
ring.scale.y += 0.2;
|
113 |
+
ring.material.opacity *= 0.95;
|
114 |
+
|
115 |
+
if (ring.material.opacity > 0.01) {
|
116 |
+
requestAnimationFrame(expandRing);
|
117 |
+
} else {
|
118 |
+
scene.remove(ring);
|
119 |
+
}
|
120 |
+
};
|
121 |
+
expandRing();
|
122 |
+
|
123 |
+
// νλ°μ ν¨κ³Ό
|
124 |
+
const explosionSound = new Audio('sounds/explosion.ogg');
|
125 |
+
explosionSound.volume = 0.4;
|
126 |
+
explosionSound.play();
|
127 |
+
|
128 |
+
// μΉ΄λ©λΌ νλ€λ¦Ό ν¨κ³Ό
|
129 |
+
if (window.gameInstance && window.gameInstance.camera) {
|
130 |
+
const camera = window.gameInstance.camera;
|
131 |
+
const originalPosition = camera.position.clone();
|
132 |
+
let shakeTime = 0;
|
133 |
+
const shakeIntensity = 0.3;
|
134 |
+
const shakeDuration = 500;
|
135 |
+
|
136 |
+
const shakeCamera = () => {
|
137 |
+
if (shakeTime < shakeDuration) {
|
138 |
+
camera.position.x = originalPosition.x + (Math.random() - 0.5) * shakeIntensity;
|
139 |
+
camera.position.y = originalPosition.y + (Math.random() - 0.5) * shakeIntensity;
|
140 |
+
camera.position.z = originalPosition.z + (Math.random() - 0.5) * shakeIntensity;
|
141 |
+
|
142 |
+
shakeTime += 16;
|
143 |
+
requestAnimationFrame(shakeCamera);
|
144 |
} else {
|
145 |
+
camera.position.copy(originalPosition);
|
146 |
}
|
147 |
};
|
148 |
+
shakeCamera();
|
149 |
}
|
150 |
|
151 |
+
// μ€μ¬ νλμ μ κ±°
|
152 |
+
setTimeout(() => {
|
153 |
+
scene.remove(flash);
|
154 |
+
}, 100);
|
155 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
async initialize(scene, loader) {
|
158 |
try {
|