jumpstorm/engine/components/Velocity.ts

24 lines
619 B
TypeScript
Raw Normal View History

2023-07-19 23:38:24 -04:00
import type { Velocity2D } from "../interfaces";
import { Component } from "./Component";
import { ComponentNames } from ".";
export class Velocity extends Component {
public dCartesian: Velocity2D;
public dTheta: number;
2023-08-12 15:49:16 -04:00
constructor(dCartesian: Velocity2D = { dx: 0, dy: 0 }, dTheta: number = 0) {
2023-07-19 23:38:24 -04:00
super(ComponentNames.Velocity);
this.dCartesian = dCartesian;
this.dTheta = dTheta;
}
2023-08-12 15:49:16 -04:00
public add(velocity?: Velocity) {
if (velocity) {
this.dCartesian.dx += velocity.dCartesian.dx;
this.dCartesian.dy += velocity.dCartesian.dy;
this.dTheta += velocity.dTheta;
}
}
2023-07-19 23:38:24 -04:00
}