aboutsummaryrefslogtreecommitdiff
path: root/static/src/engine/trailing_position.ts
blob: 1ea22d369cb8714c12bbe86df77dea49d766c757 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { ComponentType, TrailingPositionComponent } from "./component";
import { Game } from "./game";
import { System, SystemType } from "./system";

export class TrailingPositionSystem extends System {
  constructor(
    private readonly point_filter: (
      trail_point: {
        x: number;
        y: number;
        time: number;
      }[],
    ) => {
      x: number;
      y: number;
      time: number;
    }[],
  ) {
    super(SystemType.TRAILING_POSITION);
  }

  public update(_dt: number, game: Game) {
    game.for_each_entity_with_component(
      ComponentType.TRAILING_POSITION,
      (entity) => {
        const trailing_position = entity.components[
          ComponentType.TRAILING_POSITION
        ] as TrailingPositionComponent;
        trailing_position.trails = this.point_filter(trailing_position.trails);
      },
    );
  }
}