feat: Add flashlight battery and manual controls, enable post-processing, dim ambient light, and remove debug code.
This commit is contained in:
@@ -77,15 +77,6 @@ export class Graphics {
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.renderCount) this.renderCount = 0;
|
||||
this.renderCount++;
|
||||
if (this.renderCount % 500 === 0) window.log(`Frame: ${this.renderCount}`);
|
||||
|
||||
// Diagnostic: Render 3D Scene directly to Screen
|
||||
this.renderer.setRenderTarget(null);
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
|
||||
/*
|
||||
// 1. Render 3D Scene to RenderTarget
|
||||
this.renderer.setRenderTarget(this.renderTarget);
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
@@ -93,6 +84,5 @@ export class Graphics {
|
||||
// 2. Render Post-Processing Quad to Screen
|
||||
this.renderer.setRenderTarget(null);
|
||||
this.renderer.render(this.postScene, this.postCamera);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,14 @@ export class Player {
|
||||
this.moveBackward = false;
|
||||
this.moveLeft = false;
|
||||
this.moveRight = false;
|
||||
this.adjustDim = false; // 'K' key
|
||||
this.adjustBright = false; // 'L' key
|
||||
this.velocity = new THREE.Vector3();
|
||||
this.direction = new THREE.Vector3();
|
||||
this.direction = new THREE.Vector3();
|
||||
this.flashlightOn = true; // Started as ON
|
||||
this.battery = 100.0;
|
||||
this.baseDrain = 0.5; // Drain per second at base intensity
|
||||
|
||||
this.setupInput();
|
||||
this.setupFlashlight();
|
||||
@@ -37,8 +42,8 @@ export class Player {
|
||||
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.flashlight.decay = 1.5; // Lower decay for further reach
|
||||
this.flashlight.distance = 60; // Significantly increased range
|
||||
|
||||
this.camera.add(this.flashlight);
|
||||
this.flashlight.position.set(0, 0, 0);
|
||||
@@ -54,6 +59,8 @@ export class Player {
|
||||
case 'KeyS': this.moveBackward = true; break;
|
||||
case 'KeyD': this.moveRight = true; break;
|
||||
case 'KeyF': this.toggleFlashlight(); break;
|
||||
case 'KeyK': this.adjustDim = true; break;
|
||||
case 'KeyL': this.adjustBright = true; break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -63,6 +70,8 @@ export class Player {
|
||||
case 'KeyA': this.moveLeft = false; break;
|
||||
case 'KeyS': this.moveBackward = false; break;
|
||||
case 'KeyD': this.moveRight = false; break;
|
||||
case 'KeyK': this.adjustDim = false; break;
|
||||
case 'KeyL': this.adjustBright = false; break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -76,6 +85,11 @@ export class Player {
|
||||
// Better to allow F only when locked to avoid confusion.
|
||||
if (!this.controls.isLocked) return;
|
||||
|
||||
if (this.battery <= 0 && this.flashlightOn === false) {
|
||||
window.log('Cannot turn on: Battery empty');
|
||||
return;
|
||||
}
|
||||
|
||||
this.flashlightOn = !this.flashlightOn;
|
||||
if (this.flashlight) {
|
||||
this.flashlight.visible = this.flashlightOn;
|
||||
@@ -147,9 +161,51 @@ export class Player {
|
||||
// Keep player on ground
|
||||
playerPos.y = this.height;
|
||||
|
||||
// Flashlight flicker effect (subtle)
|
||||
// Flashlight flicker effect (subtle) & Battery Logic
|
||||
if (this.flashlight && this.flashlightOn) {
|
||||
this.flashlight.intensity = 10 + Math.random() * 0.5;
|
||||
// Battery Drain
|
||||
// Base intensity is ~10. Drain proportional to intensity.
|
||||
const drainFactor = this.flashlight.intensity / 10.0;
|
||||
const drain = this.baseDrain * drainFactor * dt;
|
||||
this.battery = Math.max(0, this.battery - drain);
|
||||
|
||||
// Update UI
|
||||
const battEl = document.getElementById('battery-level');
|
||||
if (battEl) battEl.textContent = Math.floor(this.battery) + '%';
|
||||
if (this.battery <= 20) {
|
||||
if (battEl) battEl.style.color = 'red';
|
||||
} else {
|
||||
if (battEl) battEl.style.color = 'white';
|
||||
}
|
||||
|
||||
// Die if empty
|
||||
if (this.battery <= 0) {
|
||||
this.flashlightOn = false;
|
||||
this.flashlight.visible = false;
|
||||
window.log('Battery depleted!');
|
||||
}
|
||||
|
||||
// Handle manual adjustment
|
||||
if (this.adjustDim || this.adjustBright) {
|
||||
const speed = 2.0 * dt;
|
||||
const angleSpeed = 0.5 * dt;
|
||||
|
||||
if (this.adjustDim) {
|
||||
this.flashlight.intensity = Math.max(0, this.flashlight.intensity - speed * 10);
|
||||
this.flashlight.angle = Math.max(0.1, this.flashlight.angle - angleSpeed);
|
||||
}
|
||||
if (this.adjustBright) {
|
||||
this.flashlight.intensity = Math.min(50, this.flashlight.intensity + speed * 10);
|
||||
this.flashlight.angle = Math.min(Math.PI / 2, this.flashlight.angle + angleSpeed);
|
||||
}
|
||||
// Log occasionally for feedback
|
||||
if (Math.random() < 0.1) window.log(`Light: Int=${this.flashlight.intensity.toFixed(1)} Ang=${this.flashlight.angle.toFixed(2)}`);
|
||||
} else {
|
||||
// Only flicker if not adjusting? Or flicker on top of base intensity.
|
||||
// Let's modify base intensity and add flicker
|
||||
// Simplified: just flicker around the current value
|
||||
this.flashlight.intensity += (Math.random() - 0.5) * 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export class World {
|
||||
|
||||
load() {
|
||||
// Standard lighting for horror
|
||||
const ambientLight = new THREE.AmbientLight(0x404040, 1.0); // Full brightness ambient for testing
|
||||
const ambientLight = new THREE.AmbientLight(0x404040, 0.2); // Very dim ambient
|
||||
this.scene.add(ambientLight);
|
||||
|
||||
// Floor
|
||||
|
||||
@@ -8,17 +8,8 @@ window.log = (msg) => {
|
||||
logDiv.appendChild(span);
|
||||
logDiv.scrollTop = logDiv.scrollHeight;
|
||||
}
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
if (window.test2D) window.test2D();
|
||||
window.log(`Searching for WebGL...`);
|
||||
try {
|
||||
const canvas = document.createElement('canvas');
|
||||
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
||||
window.log(gl ? "WebGL Found" : "WebGL NOT Found");
|
||||
} catch (e) { window.log("WebGL Check Error: " + e.message); }
|
||||
|
||||
// Toggle debug log with 'P'
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.code === 'KeyP') {
|
||||
|
||||
Reference in New Issue
Block a user