summaryrefslogtreecommitdiff
path: root/src/engine/components/GridSpawn.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/components/GridSpawn.ts')
-rw-r--r--src/engine/components/GridSpawn.ts30
1 files changed, 30 insertions, 0 deletions
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;
+ }
+}