diff options
Diffstat (limited to 'engine/systems/Physics.ts')
-rw-r--r-- | engine/systems/Physics.ts | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/engine/systems/Physics.ts b/engine/systems/Physics.ts index e324c97..35afb3f 100644 --- a/engine/systems/Physics.ts +++ b/engine/systems/Physics.ts @@ -1,4 +1,4 @@ -import { System, SystemNames } from "."; +import { System, SystemNames } from '.'; import { BoundingBox, ComponentNames, @@ -8,11 +8,11 @@ import { Mass, Jump, Moment, - Control, -} from "../components"; -import { PhysicsConstants } from "../config"; -import type { Force2D, Velocity2D } from "../interfaces"; -import { Game } from "../Game"; + Control +} from '../components'; +import { PhysicsConstants } from '../config'; +import type { Force2D, Velocity2D } from '../interfaces'; +import { Game } from '../Game'; export class Physics extends System { constructor() { @@ -24,10 +24,10 @@ export class Physics extends System { const mass = entity.getComponent<Mass>(ComponentNames.Mass).mass; const forces = entity.getComponent<Forces>(ComponentNames.Forces).forces; const velocity = entity.getComponent<Velocity>( - ComponentNames.Velocity, + ComponentNames.Velocity ).velocity; const inertia = entity.getComponent<Moment>( - ComponentNames.Moment, + ComponentNames.Moment ).inertia; // F_g = mg, applied only until terminal velocity is reached @@ -37,9 +37,9 @@ export class Physics extends System { forces.push({ fCartesian: { fy: mass * PhysicsConstants.GRAVITY, - fx: 0, + fx: 0 }, - torque: 0, + torque: 0 }); } } @@ -49,17 +49,17 @@ export class Physics extends System { (accum: Force2D, { fCartesian, torque }: Force2D) => ({ fCartesian: { fx: accum.fCartesian.fx + (fCartesian?.fx ?? 0), - fy: accum.fCartesian.fy + (fCartesian?.fy ?? 0), + fy: accum.fCartesian.fy + (fCartesian?.fy ?? 0) }, - torque: accum.torque + (torque ?? 0), + torque: accum.torque + (torque ?? 0) }), - { fCartesian: { fx: 0, fy: 0 }, torque: 0 }, + { fCartesian: { fx: 0, fy: 0 }, torque: 0 } ); // integrate accelerations const [ddy, ddx] = [ sumOfForces.fCartesian.fy, - sumOfForces.fCartesian.fx, + sumOfForces.fCartesian.fx ].map((x) => x / mass); velocity.dCartesian.dx += ddx * dt; velocity.dCartesian.dy += ddy * dt; @@ -79,14 +79,14 @@ export class Physics extends System { const control = entity.getComponent<Control>(ComponentNames.Control); velocityComponent.add( - entity.getComponent<Velocity>(ComponentNames.Velocity).velocity, + entity.getComponent<Velocity>(ComponentNames.Velocity).velocity ); if (control) { velocityComponent.add(control.controlVelocityComponent.velocity); } const boundingBox = entity.getComponent<BoundingBox>( - ComponentNames.BoundingBox, + ComponentNames.BoundingBox ); // integrate velocity |