Spaces:
Running
Running
gini1
commited on
Commit
โข
89db675
1
Parent(s):
c895158
Update game.js
Browse files
game.js
CHANGED
@@ -10,9 +10,9 @@ const ENEMY_SCALE = 3;
|
|
10 |
const MAX_HEALTH = 1000;
|
11 |
const ENEMY_MODELS = [
|
12 |
'./models/enemy1.glb',
|
13 |
-
'./models/
|
14 |
-
'./models/
|
15 |
-
'./models/
|
16 |
];
|
17 |
const ENEMY_CONFIG = {
|
18 |
ATTACK_RANGE: 100,
|
@@ -69,7 +69,7 @@ class SoundPool {
|
|
69 |
// ์ฌ์ด๋ ์ด๊ธฐํ
|
70 |
const sounds = {
|
71 |
bgm: new Audio('Music.wav'),
|
72 |
-
gunshot: new SoundPool('gun.wav', 20)
|
73 |
};
|
74 |
sounds.bgm.loop = true;
|
75 |
|
@@ -82,6 +82,9 @@ const moveState = {
|
|
82 |
};
|
83 |
|
84 |
function init() {
|
|
|
|
|
|
|
85 |
// Scene ์ด๊ธฐํ
|
86 |
scene = new THREE.Scene();
|
87 |
scene.background = new THREE.Color(0x87ceeb);
|
@@ -177,22 +180,22 @@ function loadEnemies() {
|
|
177 |
// ์์ ์ ์์ฑ
|
178 |
const tempEnemy = createTemporaryEnemy(position);
|
179 |
scene.add(tempEnemy);
|
180 |
-
|
181 |
-
|
182 |
-
health: 100,
|
183 |
-
speed: 0.3 + (currentStage * 0.1),
|
184 |
-
lastAttackTime: 0
|
185 |
-
});
|
186 |
-
|
187 |
-
// GLB ๋ชจ๋ธ ๋ก๋ ์๋
|
188 |
const modelPath = ENEMY_MODELS[i % ENEMY_MODELS.length];
|
189 |
-
|
|
|
|
|
|
|
190 |
(gltf) => {
|
191 |
-
console.log('
|
192 |
const enemy = gltf.scene;
|
193 |
enemy.scale.set(ENEMY_SCALE, ENEMY_SCALE, ENEMY_SCALE);
|
194 |
enemy.position.copy(position);
|
195 |
|
|
|
|
|
|
|
196 |
enemy.traverse((node) => {
|
197 |
if (node.isMesh) {
|
198 |
node.castShadow = true;
|
@@ -205,21 +208,47 @@ function loadEnemies() {
|
|
205 |
// ์์ ์ ์ ์ค์ ๋ชจ๋ธ๋ก ๊ต์ฒด
|
206 |
scene.remove(tempEnemy);
|
207 |
scene.add(enemy);
|
|
|
|
|
208 |
const index = enemies.findIndex(e => e.model === tempEnemy);
|
209 |
if (index !== -1) {
|
210 |
enemies[index].model = enemy;
|
|
|
|
|
|
|
211 |
}
|
212 |
},
|
213 |
(xhr) => {
|
214 |
-
console.log((xhr.loaded / xhr.total * 100)
|
215 |
},
|
216 |
(error) => {
|
217 |
-
console.error('Error loading enemy model:', error);
|
218 |
}
|
219 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
}
|
221 |
}
|
222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
function addObstacles() {
|
224 |
const rockGeometry = new THREE.DodecahedronGeometry(10);
|
225 |
const rockMaterial = new THREE.MeshStandardMaterial({
|
@@ -293,7 +322,11 @@ function shoot() {
|
|
293 |
|
294 |
function createBullet() {
|
295 |
const bulletGeometry = new THREE.SphereGeometry(0.5);
|
296 |
-
const bulletMaterial = new THREE.MeshBasicMaterial({
|
|
|
|
|
|
|
|
|
297 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
298 |
|
299 |
bullet.position.copy(camera.position);
|
@@ -307,10 +340,30 @@ function createBullet() {
|
|
307 |
|
308 |
function createEnemyBullet(enemy) {
|
309 |
const bulletGeometry = new THREE.SphereGeometry(0.5);
|
310 |
-
const bulletMaterial = new THREE.MeshBasicMaterial({
|
|
|
|
|
|
|
|
|
311 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
312 |
|
313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
const direction = new THREE.Vector3();
|
316 |
direction.subVectors(camera.position, enemy.model.position).normalize();
|
@@ -447,6 +500,17 @@ function updateEnemies() {
|
|
447 |
const distanceToPlayer = enemy.model.position.distanceTo(camera.position);
|
448 |
if (distanceToPlayer < ENEMY_CONFIG.ATTACK_RANGE &&
|
449 |
currentTime - enemy.lastAttackTime > ENEMY_CONFIG.ATTACK_INTERVAL) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
enemyBullets.push(createEnemyBullet(enemy));
|
451 |
enemy.lastAttackTime = currentTime;
|
452 |
}
|
|
|
10 |
const MAX_HEALTH = 1000;
|
11 |
const ENEMY_MODELS = [
|
12 |
'./models/enemy1.glb',
|
13 |
+
'./models/enemy12.glb',
|
14 |
+
'./models/enemy13.glb',
|
15 |
+
'./models/enemy14.glb'
|
16 |
];
|
17 |
const ENEMY_CONFIG = {
|
18 |
ATTACK_RANGE: 100,
|
|
|
69 |
// ์ฌ์ด๋ ์ด๊ธฐํ
|
70 |
const sounds = {
|
71 |
bgm: new Audio('Music.wav'),
|
72 |
+
gunshot: new SoundPool('gun.wav', 20) // ํ ํฌ๊ธฐ๋ฅผ 20์ผ๋ก ์ฆ๊ฐ
|
73 |
};
|
74 |
sounds.bgm.loop = true;
|
75 |
|
|
|
82 |
};
|
83 |
|
84 |
function init() {
|
85 |
+
console.log('Game initialized');
|
86 |
+
console.log('Available enemy models:', ENEMY_MODELS);
|
87 |
+
|
88 |
// Scene ์ด๊ธฐํ
|
89 |
scene = new THREE.Scene();
|
90 |
scene.background = new THREE.Color(0x87ceeb);
|
|
|
180 |
// ์์ ์ ์์ฑ
|
181 |
const tempEnemy = createTemporaryEnemy(position);
|
182 |
scene.add(tempEnemy);
|
183 |
+
|
184 |
+
// GLB ๋ชจ๋ธ ๋ก๋
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
const modelPath = ENEMY_MODELS[i % ENEMY_MODELS.length];
|
186 |
+
console.log('Loading enemy model:', modelPath);
|
187 |
+
|
188 |
+
loader.load(
|
189 |
+
modelPath,
|
190 |
(gltf) => {
|
191 |
+
console.log('Successfully loaded enemy model:', modelPath);
|
192 |
const enemy = gltf.scene;
|
193 |
enemy.scale.set(ENEMY_SCALE, ENEMY_SCALE, ENEMY_SCALE);
|
194 |
enemy.position.copy(position);
|
195 |
|
196 |
+
// ๋ชจ๋ธ ๋ฐฉํฅ ์ค์
|
197 |
+
enemy.rotation.y = Math.PI;
|
198 |
+
|
199 |
enemy.traverse((node) => {
|
200 |
if (node.isMesh) {
|
201 |
node.castShadow = true;
|
|
|
208 |
// ์์ ์ ์ ์ค์ ๋ชจ๋ธ๋ก ๊ต์ฒด
|
209 |
scene.remove(tempEnemy);
|
210 |
scene.add(enemy);
|
211 |
+
|
212 |
+
// enemies ๋ฐฐ์ด ์
๋ฐ์ดํธ
|
213 |
const index = enemies.findIndex(e => e.model === tempEnemy);
|
214 |
if (index !== -1) {
|
215 |
enemies[index].model = enemy;
|
216 |
+
// ์ ๊ณต๊ฒฉ ํจ๊ณผ ์ถ๊ฐ
|
217 |
+
enemies[index].muzzleFlash = createMuzzleFlash();
|
218 |
+
enemy.add(enemies[index].muzzleFlash);
|
219 |
}
|
220 |
},
|
221 |
(xhr) => {
|
222 |
+
console.log(`${modelPath}: ${(xhr.loaded / xhr.total * 100)}% loaded`);
|
223 |
},
|
224 |
(error) => {
|
225 |
+
console.error('Error loading enemy model:', modelPath, error);
|
226 |
}
|
227 |
);
|
228 |
+
|
229 |
+
// enemies ๋ฐฐ์ด์ ์ถ๊ฐ
|
230 |
+
enemies.push({
|
231 |
+
model: tempEnemy,
|
232 |
+
health: 100,
|
233 |
+
speed: 0.3 + (currentStage * 0.1),
|
234 |
+
lastAttackTime: 0
|
235 |
+
});
|
236 |
}
|
237 |
}
|
238 |
|
239 |
+
function createMuzzleFlash() {
|
240 |
+
const geometry = new THREE.PlaneGeometry(2, 2);
|
241 |
+
const material = new THREE.MeshBasicMaterial({
|
242 |
+
color: 0xff7700,
|
243 |
+
transparent: true,
|
244 |
+
opacity: 0,
|
245 |
+
blending: THREE.AdditiveBlending
|
246 |
+
});
|
247 |
+
const muzzleFlash = new THREE.Mesh(geometry, material);
|
248 |
+
muzzleFlash.visible = false;
|
249 |
+
return muzzleFlash;
|
250 |
+
}
|
251 |
+
|
252 |
function addObstacles() {
|
253 |
const rockGeometry = new THREE.DodecahedronGeometry(10);
|
254 |
const rockMaterial = new THREE.MeshStandardMaterial({
|
|
|
322 |
|
323 |
function createBullet() {
|
324 |
const bulletGeometry = new THREE.SphereGeometry(0.5);
|
325 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
326 |
+
color: 0xffff00,
|
327 |
+
emissive: 0xffff00,
|
328 |
+
emissiveIntensity: 1
|
329 |
+
});
|
330 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
331 |
|
332 |
bullet.position.copy(camera.position);
|
|
|
340 |
|
341 |
function createEnemyBullet(enemy) {
|
342 |
const bulletGeometry = new THREE.SphereGeometry(0.5);
|
343 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
344 |
+
color: 0xff0000,
|
345 |
+
emissive: 0xff0000,
|
346 |
+
emissiveIntensity: 1
|
347 |
+
});
|
348 |
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
349 |
|
350 |
+
// ์ด๊ตฌ ์์น ์กฐ์
|
351 |
+
const muzzleOffset = new THREE.Vector3(0, 2, 0);
|
352 |
+
bullet.position.copy(enemy.model.position).add(muzzleOffset);
|
353 |
+
|
354 |
+
// ์ด์ ๊ถค์ ํจ๊ณผ
|
355 |
+
const trail = new THREE.Points(
|
356 |
+
new THREE.BufferGeometry().setFromPoints([
|
357 |
+
new THREE.Vector3(0, 0, 0),
|
358 |
+
new THREE.Vector3(0, 0, -5)
|
359 |
+
]),
|
360 |
+
new THREE.PointsMaterial({
|
361 |
+
color: 0xff0000,
|
362 |
+
size: 0.5,
|
363 |
+
blending: THREE.AdditiveBlending
|
364 |
+
})
|
365 |
+
);
|
366 |
+
bullet.add(trail);
|
367 |
|
368 |
const direction = new THREE.Vector3();
|
369 |
direction.subVectors(camera.position, enemy.model.position).normalize();
|
|
|
500 |
const distanceToPlayer = enemy.model.position.distanceTo(camera.position);
|
501 |
if (distanceToPlayer < ENEMY_CONFIG.ATTACK_RANGE &&
|
502 |
currentTime - enemy.lastAttackTime > ENEMY_CONFIG.ATTACK_INTERVAL) {
|
503 |
+
|
504 |
+
// ์ด๊ตฌ ํ์ผ ํจ๊ณผ ํ์
|
505 |
+
if (enemy.muzzleFlash) {
|
506 |
+
enemy.muzzleFlash.material.opacity = 1;
|
507 |
+
enemy.muzzleFlash.visible = true;
|
508 |
+
setTimeout(() => {
|
509 |
+
enemy.muzzleFlash.visible = false;
|
510 |
+
enemy.muzzleFlash.material.opacity = 0;
|
511 |
+
}, 100);
|
512 |
+
}
|
513 |
+
|
514 |
enemyBullets.push(createEnemyBullet(enemy));
|
515 |
enemy.lastAttackTime = currentTime;
|
516 |
}
|