summaryrefslogtreecommitdiff
path: root/src/engine/systems/Life.ts
blob: f4544379262bc1cce9ba9ef5554bf0cca55857e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { System, SystemNames } from ".";
import { Game } from "..";
import { Life as LifeComponent, ComponentNames } from "../components";

export class Life extends System {
  constructor() {
    super(SystemNames.Life);
  }

  public update(_dt: number, game: Game) {
    game.forEachEntityWithComponent(ComponentNames.Life, (entity) => {
      const life = entity.getComponent<LifeComponent>(ComponentNames.Life);
      if (!life.alive) {
        game.removeEntity(entity.id);
      }
    });
  }
}