From c6e9baa0009f7cce0f6ff156a3957ef04a8cb684 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sat, 12 Aug 2023 13:49:16 -0600 Subject: the great engine refactor --- engine/components/Velocity.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engine/components/Velocity.ts') diff --git a/engine/components/Velocity.ts b/engine/components/Velocity.ts index 119427d..068d8cd 100644 --- a/engine/components/Velocity.ts +++ b/engine/components/Velocity.ts @@ -6,10 +6,18 @@ export class Velocity extends Component { public dCartesian: Velocity2D; public dTheta: number; - constructor(dCartesian: Velocity2D, dTheta: number) { + constructor(dCartesian: Velocity2D = { dx: 0, dy: 0 }, dTheta: number = 0) { super(ComponentNames.Velocity); this.dCartesian = dCartesian; this.dTheta = dTheta; } + + public add(velocity?: Velocity) { + if (velocity) { + this.dCartesian.dx += velocity.dCartesian.dx; + this.dCartesian.dy += velocity.dCartesian.dy; + this.dTheta += velocity.dTheta; + } + } } -- cgit v1.2.3-70-g09d2