Added real-time tracking of fuel consumption from linear and angular thrust. **Modified: src/shipPhysics.ts** - Added GameStats import and _gameStats property - Added setGameStats() method to receive GameStats instance - Call gameStats.recordFuelConsumed() after each fuel consumption - Tracks both linear thrust (forward/backward) and angular thrust (rotation) - Records exact consumption amounts (0.005 max per frame for each) **Modified: src/ship.ts** - Wire up physics system with GameStats via setGameStats() - Called immediately after physics initialization The Fuel Consumed statistic now updates in real-time on the status screen, accumulating all fuel used for movement and rotation, displayed as a percentage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
739f140ea4
commit
688d002752
@ -178,6 +178,7 @@ export class Ship {
|
||||
// Initialize physics controller
|
||||
this._physics = new ShipPhysics();
|
||||
this._physics.setShipStatus(this._scoreboard.shipStatus);
|
||||
this._physics.setGameStats(this._gameStats);
|
||||
|
||||
// Setup physics update loop (every 10 frames)
|
||||
DefaultScene.MainScene.onAfterRenderObservable.add(() => {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { PhysicsBody, TransformNode, Vector2, Vector3 } from "@babylonjs/core";
|
||||
import { GameConfig } from "./gameConfig";
|
||||
import { ShipStatus } from "./shipStatus";
|
||||
import { GameStats } from "./gameStats";
|
||||
|
||||
export interface InputState {
|
||||
leftStick: Vector2;
|
||||
@ -18,6 +19,7 @@ export interface ForceApplicationResult {
|
||||
*/
|
||||
export class ShipPhysics {
|
||||
private _shipStatus: ShipStatus | null = null;
|
||||
private _gameStats: GameStats | null = null;
|
||||
|
||||
/**
|
||||
* Set the ship status instance for fuel consumption tracking
|
||||
@ -25,6 +27,13 @@ export class ShipPhysics {
|
||||
public setShipStatus(shipStatus: ShipStatus): void {
|
||||
this._shipStatus = shipStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the game stats instance for tracking fuel consumed
|
||||
*/
|
||||
public setGameStats(gameStats: GameStats): void {
|
||||
this._gameStats = gameStats;
|
||||
}
|
||||
/**
|
||||
* Apply forces to the ship based on input state
|
||||
* @param inputState - Current input state (stick positions)
|
||||
@ -79,9 +88,14 @@ export class ShipPhysics {
|
||||
|
||||
physicsBody.applyForce(force, thrustPoint);
|
||||
|
||||
// Consume fuel: normalized magnitude (0-1) * 0.01 = max consumption of 0.01 per frame
|
||||
// Consume fuel: normalized magnitude (0-1) * 0.005 per frame
|
||||
const fuelConsumption = linearMagnitude * 0.005;
|
||||
this._shipStatus.consumeFuel(fuelConsumption);
|
||||
|
||||
// Track fuel consumed for statistics
|
||||
if (this._gameStats) {
|
||||
this._gameStats.recordFuelConsumed(fuelConsumption);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,10 +129,15 @@ export class ShipPhysics {
|
||||
|
||||
physicsBody.applyAngularImpulse(worldTorque);
|
||||
|
||||
// Consume fuel: normalized magnitude (0-3 max) / 3 * 0.01 = max consumption of 0.01 per frame
|
||||
// Consume fuel: normalized magnitude (0-3 max) / 3 * 0.005 per frame
|
||||
const normalizedAngularMagnitude = Math.min(angularMagnitude / 3.0, 1.0);
|
||||
const fuelConsumption = normalizedAngularMagnitude * 0.005;
|
||||
this._shipStatus.consumeFuel(fuelConsumption);
|
||||
|
||||
// Track fuel consumed for statistics
|
||||
if (this._gameStats) {
|
||||
this._gameStats.recordFuelConsumed(fuelConsumption);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user