feat: Migrate to Vite build system, update dependencies, and refine graphics setup with debugging aids.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as THREE from 'three';
|
||||
import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';
|
||||
import { PointerLockControls } from 'three/examples/jsm/controls/PointerLockControls.js';
|
||||
|
||||
export class Player {
|
||||
constructor(camera, colliders) {
|
||||
@@ -20,8 +20,23 @@ export class Player {
|
||||
this.moveRight = false;
|
||||
this.velocity = new THREE.Vector3();
|
||||
this.direction = new THREE.Vector3();
|
||||
this.flashlightOn = true; // Started as ON
|
||||
|
||||
this.setupInput();
|
||||
this.setupFlashlight();
|
||||
}
|
||||
|
||||
setupFlashlight() {
|
||||
this.flashlight = new THREE.SpotLight(0xffffff, 10);
|
||||
this.flashlight.angle = Math.PI / 6;
|
||||
this.flashlight.penumbra = 0.3;
|
||||
this.flashlight.decay = 2;
|
||||
this.flashlight.distance = 15;
|
||||
|
||||
this.camera.add(this.flashlight);
|
||||
this.flashlight.position.set(0, 0, 0);
|
||||
this.flashlight.target.position.set(0, 0, -1);
|
||||
this.camera.add(this.flashlight.target);
|
||||
}
|
||||
|
||||
setupInput() {
|
||||
@@ -31,6 +46,7 @@ export class Player {
|
||||
case 'KeyA': this.moveLeft = true; break;
|
||||
case 'KeyS': this.moveBackward = true; break;
|
||||
case 'KeyD': this.moveRight = true; break;
|
||||
case 'KeyF': this.toggleFlashlight(); break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -47,6 +63,14 @@ export class Player {
|
||||
document.addEventListener('keyup', onKeyUp);
|
||||
}
|
||||
|
||||
toggleFlashlight() {
|
||||
if (!this.controls.isLocked) return; // Only toggle when game is active
|
||||
this.flashlightOn = !this.flashlightOn;
|
||||
if (this.flashlight) {
|
||||
this.flashlight.visible = this.flashlightOn;
|
||||
}
|
||||
}
|
||||
|
||||
lockControls() {
|
||||
this.controls.lock();
|
||||
}
|
||||
@@ -105,5 +129,10 @@ export class Player {
|
||||
|
||||
// Keep player on ground
|
||||
playerPos.y = this.height;
|
||||
|
||||
// Flashlight flicker effect (subtle)
|
||||
if (this.flashlight && this.flashlightOn) {
|
||||
this.flashlight.intensity = 10 + Math.random() * 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user