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 {
|
2023-08-13 19:09:12 -04:00
|
|
|
public velocity: Velocity2D;
|
2023-07-19 23:38:24 -04:00
|
|
|
|
2023-08-13 19:09:12 -04:00
|
|
|
constructor(
|
2023-08-25 18:48:17 -04:00
|
|
|
velocity: Velocity2D = { dCartesian: { dx: 0, dy: 0 }, dTheta: 0 }
|
2023-08-13 19:09:12 -04:00
|
|
|
) {
|
2023-07-19 23:38:24 -04:00
|
|
|
super(ComponentNames.Velocity);
|
|
|
|
|
2023-08-13 19:09:12 -04:00
|
|
|
this.velocity = velocity;
|
2023-07-19 23:38:24 -04:00
|
|
|
}
|
2023-08-12 15:49:16 -04:00
|
|
|
|
2023-08-13 19:09:12 -04:00
|
|
|
public add(velocity?: Velocity2D) {
|
2023-08-12 15:49:16 -04:00
|
|
|
if (velocity) {
|
2023-08-13 19:09:12 -04:00
|
|
|
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
|
|
|
}
|