Implemented collision detection on the ship to automatically reduce hull integrity when colliding with objects. **Modified: src/ship.ts** - Added collision observable handler after physics aggregate creation - Subscribed to getCollisionObservable() on ship physics body - Collision handler calls shipStatus.damageHull(0.01) on any collision event - Hull damage automatically triggers gauge update via observable pattern This completes the full resource management system: - **Fuel**: Consumed by linear thrust (0.005/frame) and angular thrust (0.005/frame) - **Ammo**: Consumed by weapon firing (0.01 per shot) - **Hull**: Damaged by collisions (0.01 per collision) - **Gauges**: All three update automatically with color-coded feedback - **Prevention**: Thrust disabled when fuel depleted, weapons disabled when ammo depleted The hull gauge will now show damage in real-time as the ship collides with asteroids or other objects in the game world. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
eea82da395
commit
8605946fab
@ -94,6 +94,15 @@ export class Ship {
|
|||||||
agg.body.setAngularDamping(0.4);
|
agg.body.setAngularDamping(0.4);
|
||||||
agg.body.setAngularVelocity(new Vector3(0, 0, 0));
|
agg.body.setAngularVelocity(new Vector3(0, 0, 0));
|
||||||
agg.body.setCollisionCallbackEnabled(true);
|
agg.body.setCollisionCallbackEnabled(true);
|
||||||
|
|
||||||
|
// Register collision handler for hull damage
|
||||||
|
const observable = agg.body.getCollisionObservable();
|
||||||
|
observable.add((collisionEvent) => {
|
||||||
|
// Damage hull on any collision
|
||||||
|
if (this._scoreboard?.shipStatus) {
|
||||||
|
this._scoreboard.shipStatus.damageHull(0.01);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.warn("No geometry mesh found, cannot create physics");
|
console.warn("No geometry mesh found, cannot create physics");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user