From ce06fa7c29ba4e3d6137f7aa74fbfe45af0e8b73 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Tue, 5 Mar 2024 22:00:04 -0700 Subject: refactor spawners --- src/engine/components/GridSpawn.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/engine/components/GridSpawn.ts (limited to 'src/engine/components/GridSpawn.ts') diff --git a/src/engine/components/GridSpawn.ts b/src/engine/components/GridSpawn.ts new file mode 100644 index 0000000..d2ec898 --- /dev/null +++ b/src/engine/components/GridSpawn.ts @@ -0,0 +1,30 @@ +import { Component, ComponentNames } from "."; +import { Entity } from "../entities"; +import { Direction } from "../interfaces"; + +export class GridSpawn extends Component { + public direction: Direction; + public spawnsLeft: number; + public spawner: () => Entity; + + constructor( + spawnsLeft: number, + spawner: () => Entity, + direction = Direction.NONE, + ) { + super(ComponentNames.GridSpawn); + + this.spawnsLeft = spawnsLeft; + this.direction = direction; + this.spawner = spawner; + } + + public spawnEntity(direction: Direction): Entity | undefined { + if (this.spawnsLeft === 0) { + return; + } + + this.direction = direction; + this.spawnsLeft -= 1; + } +} -- cgit v1.2.3-70-g09d2