Add main menu, ghost enemy, and sword slash trail

This commit is contained in:
2026-08-17 13:03:19 +02:00
parent 0b19c3d26b
commit 4751d428a7
8 changed files with 796 additions and 164 deletions
+17 -10
View File
@@ -3,6 +3,7 @@ import { Weapon } from './Weapon';
import { Player } from './Player';
import { loadGLB } from './MeshLoader';
import { playSound } from './SoundManager';
import { SlashEffect, isInSlashArc } from './SwordTrail';
export class Sword extends Weapon {
private mixer: THREE.AnimationMixer | null = null;
@@ -97,18 +98,24 @@ export class Sword extends Weapon {
const { game } = player;
// Aim direction: where the blob actually faces (toward the mouse point)
const aim = new THREE.Vector3()
.subVectors(game.groundPoint, player.body.position);
aim.y = 0;
if (aim.lengthSq() < 0.001) {
aim.set(0, 0, -1).applyQuaternion(player.body.quaternion);
aim.y = 0;
}
aim.normalize();
// Slash trail feedback
const slash = new SlashEffect(player.body.position, aim, game.scene);
game.slashEffects.push(slash);
for (const enemy of game.enemies) {
if (enemy.dead) continue;
const dist = enemy.body.position.distanceTo(player.body.position);
if (dist < 3) {
const toEnemy = new THREE.Vector3()
.subVectors(enemy.body.position, player.body.position).normalize();
const playerFwd = new THREE.Vector3(0, 0, 1);
playerFwd.applyQuaternion(player.body.quaternion);
const dot = playerFwd.dot(toEnemy);
if (dot > 0.3) {
enemy.takeDamage(50, game);
}
if (isInSlashArc(player.body.position, aim, enemy.body.position)) {
enemy.takeDamage(50, game);
}
}
}