summaryrefslogtreecommitdiff
path: root/src/engine/components/GridSpawn.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-05 22:00:04 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-05 22:00:04 -0700
commitce06fa7c29ba4e3d6137f7aa74fbfe45af0e8b73 (patch)
treeef17306b0fe5f2f957d9c37638a6af76236c7881 /src/engine/components/GridSpawn.ts
parent110fe21a2340365b7b7cb72f6f44ad13ed39f4ea (diff)
downloadthe-abstraction-engine-ce06fa7c29ba4e3d6137f7aa74fbfe45af0e8b73.tar.gz
the-abstraction-engine-ce06fa7c29ba4e3d6137f7aa74fbfe45af0e8b73.zip
refactor spawners
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;
+ }
+}