Spaces:
Running
Running
gunship999
commited on
Commit
β’
b80f0fc
1
Parent(s):
e142f0b
Update game.js
Browse files
game.js
CHANGED
@@ -449,4 +449,168 @@ function updateRadar() {
|
|
449 |
radarTargets.appendChild(dot);
|
450 |
}
|
451 |
});
|
452 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
radarTargets.appendChild(dot);
|
450 |
}
|
451 |
});
|
452 |
+
}
|
453 |
+
|
454 |
+
function updateMovement() {
|
455 |
+
if (controls.isLocked) {
|
456 |
+
const speed = 2.0;
|
457 |
+
if (moveState.forward) controls.moveForward(speed);
|
458 |
+
if (moveState.backward) controls.moveForward(-speed);
|
459 |
+
if (moveState.left) controls.moveRight(-speed);
|
460 |
+
if (moveState.right) controls.moveRight(speed);
|
461 |
+
|
462 |
+
// μ΅μ κ³ λ μ μ§
|
463 |
+
if (camera.position.y < HELICOPTER_HEIGHT) {
|
464 |
+
camera.position.y = HELICOPTER_HEIGHT;
|
465 |
+
}
|
466 |
+
}
|
467 |
+
}
|
468 |
+
|
469 |
+
function updateBullets() {
|
470 |
+
for (let i = bullets.length - 1; i >= 0; i--) {
|
471 |
+
if (!bullets[i]) continue;
|
472 |
+
|
473 |
+
bullets[i].position.add(bullets[i].velocity);
|
474 |
+
|
475 |
+
enemies.forEach(enemy => {
|
476 |
+
if (!enemy || !enemy.model) return;
|
477 |
+
|
478 |
+
if (bullets[i] && bullets[i].position.distanceTo(enemy.model.position) < 5) {
|
479 |
+
scene.remove(bullets[i]);
|
480 |
+
bullets.splice(i, 1);
|
481 |
+
enemy.health -= 25;
|
482 |
+
|
483 |
+
// νΌκ²© ν¨κ³Ό
|
484 |
+
createExplosion(enemy.model.position.clone());
|
485 |
+
|
486 |
+
if (enemy.health <= 0) {
|
487 |
+
// νκ΄΄ ν¨κ³Ό
|
488 |
+
createExplosion(enemy.model.position.clone());
|
489 |
+
createExplosion(enemy.model.position.clone().add(new THREE.Vector3(2, 0, 2)));
|
490 |
+
createExplosion(enemy.model.position.clone().add(new THREE.Vector3(-2, 0, -2)));
|
491 |
+
scene.remove(enemy.model);
|
492 |
+
enemies = enemies.filter(e => e !== enemy);
|
493 |
+
console.log('Enemy destroyed, remaining enemies:', enemies.length);
|
494 |
+
}
|
495 |
+
}
|
496 |
+
});
|
497 |
+
|
498 |
+
if (bullets[i] && bullets[i].position.distanceTo(camera.position) > 1000) {
|
499 |
+
scene.remove(bullets[i]);
|
500 |
+
bullets.splice(i, 1);
|
501 |
+
}
|
502 |
+
}
|
503 |
+
}
|
504 |
+
|
505 |
+
function updateEnemyBullets() {
|
506 |
+
for (let i = enemyBullets.length - 1; i >= 0; i--) {
|
507 |
+
if (!enemyBullets[i]) continue;
|
508 |
+
|
509 |
+
enemyBullets[i].position.add(enemyBullets[i].velocity);
|
510 |
+
|
511 |
+
if (enemyBullets[i].position.distanceTo(camera.position) < 3) {
|
512 |
+
playerHealth -= 10;
|
513 |
+
updateHealthBar();
|
514 |
+
scene.remove(enemyBullets[i]);
|
515 |
+
enemyBullets.splice(i, 1);
|
516 |
+
|
517 |
+
if (playerHealth <= 0) {
|
518 |
+
gameOver(false);
|
519 |
+
}
|
520 |
+
continue;
|
521 |
+
}
|
522 |
+
|
523 |
+
if (enemyBullets[i].position.distanceTo(camera.position) > 1000) {
|
524 |
+
scene.remove(enemyBullets[i]);
|
525 |
+
enemyBullets.splice(i, 1);
|
526 |
+
}
|
527 |
+
}
|
528 |
+
}
|
529 |
+
|
530 |
+
function updateEnemies() {
|
531 |
+
const currentTime = Date.now();
|
532 |
+
|
533 |
+
enemies.forEach(enemy => {
|
534 |
+
if (!enemy || !enemy.model) return;
|
535 |
+
|
536 |
+
// μ μ νμ¬ μμΉμμ νλ μ΄μ΄ λ°©ν₯μΌλ‘ ν₯νλ λ²‘ν° κ³μ°
|
537 |
+
const direction = new THREE.Vector3();
|
538 |
+
direction.subVectors(camera.position, enemy.model.position);
|
539 |
+
direction.y = 0; // yμΆ μ΄λ μ ν
|
540 |
+
direction.normalize();
|
541 |
+
|
542 |
+
// μλ‘μ΄ μμΉ κ³μ°
|
543 |
+
const newPosition = enemy.model.position.clone()
|
544 |
+
.add(direction.multiplyScalar(enemy.speed));
|
545 |
+
newPosition.y = ENEMY_GROUND_HEIGHT;
|
546 |
+
enemy.model.position.copy(newPosition);
|
547 |
+
|
548 |
+
// μ μ΄ νλ μ΄μ΄λ₯Ό λ°λΌλ³΄λλ‘ μ€μ
|
549 |
+
enemy.model.lookAt(new THREE.Vector3(
|
550 |
+
camera.position.x,
|
551 |
+
enemy.model.position.y,
|
552 |
+
camera.position.z
|
553 |
+
));
|
554 |
+
|
555 |
+
// 곡격 λ‘μ§
|
556 |
+
const distanceToPlayer = enemy.model.position.distanceTo(camera.position);
|
557 |
+
if (distanceToPlayer < ENEMY_CONFIG.ATTACK_RANGE &&
|
558 |
+
currentTime - enemy.lastAttackTime > ENEMY_CONFIG.ATTACK_INTERVAL) {
|
559 |
+
|
560 |
+
console.log('Enemy attacking!');
|
561 |
+
enemyBullets.push(createEnemyBullet(enemy));
|
562 |
+
enemy.lastAttackTime = currentTime;
|
563 |
+
}
|
564 |
+
});
|
565 |
+
}
|
566 |
+
|
567 |
+
function checkGameStatus() {
|
568 |
+
if (enemies.length === 0 && currentStage < 5) {
|
569 |
+
currentStage++;
|
570 |
+
document.getElementById('stage').style.display = 'block';
|
571 |
+
document.getElementById('stage').textContent = `Stage ${currentStage}`;
|
572 |
+
setTimeout(() => {
|
573 |
+
document.getElementById('stage').style.display = 'none';
|
574 |
+
loadEnemies();
|
575 |
+
}, 2000);
|
576 |
+
}
|
577 |
+
}
|
578 |
+
|
579 |
+
function gameOver(won) {
|
580 |
+
isGameOver = true;
|
581 |
+
controls.unlock();
|
582 |
+
sounds.bgm.pause();
|
583 |
+
alert(won ? 'Mission Complete!' : 'Game Over!');
|
584 |
+
location.reload();
|
585 |
+
}
|
586 |
+
|
587 |
+
function gameLoop() {
|
588 |
+
requestAnimationFrame(gameLoop);
|
589 |
+
|
590 |
+
const time = performance.now();
|
591 |
+
const delta = (time - lastTime) / 1000;
|
592 |
+
lastTime = time;
|
593 |
+
|
594 |
+
if (controls.isLocked && !isGameOver) {
|
595 |
+
updateMovement();
|
596 |
+
updateBullets();
|
597 |
+
updateEnemies();
|
598 |
+
updateEnemyBullets();
|
599 |
+
updateHelicopterHUD();
|
600 |
+
checkGameStatus();
|
601 |
+
}
|
602 |
+
|
603 |
+
renderer.render(scene, camera);
|
604 |
+
}
|
605 |
+
|
606 |
+
// κ²μ μμ
|
607 |
+
window.addEventListener('load', async () => {
|
608 |
+
try {
|
609 |
+
await init();
|
610 |
+
console.log('Game started');
|
611 |
+
console.log('Active enemies:', enemies.length);
|
612 |
+
gameLoop();
|
613 |
+
} catch (error) {
|
614 |
+
console.error('Game initialization error:', error);
|
615 |
+
}
|
616 |
+
});
|