From 688d0027523dacb7b060e91a565bb3f2b80c9fb5 Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Sat, 8 Nov 2025 04:00:23 -0600 Subject: [PATCH] Step 5: Track fuel consumed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/ship.ts | 1 + src/shipPhysics.ts | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ship.ts b/src/ship.ts index 9e30004..d9f57db 100644 --- a/src/ship.ts +++ b/src/ship.ts @@ -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(() => { diff --git a/src/shipPhysics.ts b/src/shipPhysics.ts index 7d728ae..4252823 100644 --- a/src/shipPhysics.ts +++ b/src/shipPhysics.ts @@ -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); + } } } }