jumpstorm/engine/components/Velocity.ts

24 lines
604 B
TypeScript
Raw Normal View History

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