summaryrefslogtreecommitdiff
path: root/src/engine/levels
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-07 22:49:43 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-07 22:49:43 -0700
commitebae24f5a3a251654a1e41be58f52ba2a777d9d7 (patch)
tree6641c3e5a5ec5d812c54be2bb38196f85f4e36c2 /src/engine/levels
parent808a44e8542ebc7542d833e5a30b51b7fb8f80d5 (diff)
downloadthe-abstraction-engine-ebae24f5a3a251654a1e41be58f52ba2a777d9d7.tar.gz
the-abstraction-engine-ebae24f5a3a251654a1e41be58f52ba2a777d9d7.zip
level system!
Diffstat (limited to 'src/engine/levels')
-rw-r--r--src/engine/levels/Level.ts11
-rw-r--r--src/engine/levels/LevelNames.ts4
-rw-r--r--src/engine/levels/LevelSelection.ts33
-rw-r--r--src/engine/levels/Tutorial.ts32
-rw-r--r--src/engine/levels/index.ts12
-rw-r--r--src/engine/levels/utils.ts6
6 files changed, 98 insertions, 0 deletions
diff --git a/src/engine/levels/Level.ts b/src/engine/levels/Level.ts
new file mode 100644
index 0000000..c5dc23e
--- /dev/null
+++ b/src/engine/levels/Level.ts
@@ -0,0 +1,11 @@
+import { Game } from "..";
+
+export abstract class Level {
+ public readonly name: string;
+
+ constructor(name: string) {
+ this.name = name;
+ }
+
+ abstract init(game: Game): void;
+}
diff --git a/src/engine/levels/LevelNames.ts b/src/engine/levels/LevelNames.ts
new file mode 100644
index 0000000..e90b29a
--- /dev/null
+++ b/src/engine/levels/LevelNames.ts
@@ -0,0 +1,4 @@
+export namespace LevelNames {
+ export const Tutorial = "0";
+ export const LevelSelection = "LevelSelection";
+}
diff --git a/src/engine/levels/LevelSelection.ts b/src/engine/levels/LevelSelection.ts
new file mode 100644
index 0000000..a970d9c
--- /dev/null
+++ b/src/engine/levels/LevelSelection.ts
@@ -0,0 +1,33 @@
+import { LEVELS, Level, LevelNames } from ".";
+import { Game } from "..";
+import { Player, Portal } from "../entities";
+import { Grid, Level as LevelSystem, SystemNames } from "../systems";
+
+export class LevelSelection extends Level {
+ constructor() {
+ super(LevelNames.LevelSelection);
+ }
+
+ public init(game: Game): void {
+ const gridSystem = game.getSystem<Grid>(SystemNames.Grid);
+ const center = gridSystem.getCenterGrid();
+
+ const levelSystem = game.getSystem<LevelSystem>(SystemNames.Level);
+ const unlocked = levelSystem.getUnlockedLevels();
+
+ LEVELS.forEach((level, i) => {
+ if (
+ !unlocked.has(level.name) ||
+ level.name === LevelNames.LevelSelection
+ ) {
+ return;
+ }
+
+ const portal = new Portal(level.name, { x: i, y: 7 });
+ game.addEntity(portal);
+ });
+
+ const player = new Player(center);
+ game.addEntity(player);
+ }
+}
diff --git a/src/engine/levels/Tutorial.ts b/src/engine/levels/Tutorial.ts
new file mode 100644
index 0000000..165b10f
--- /dev/null
+++ b/src/engine/levels/Tutorial.ts
@@ -0,0 +1,32 @@
+import { Level, LevelNames } from ".";
+import { Game } from "..";
+import {
+ Curry,
+ FunctionApplication,
+ LambdaFactory,
+ LockedDoor,
+ Player,
+ Wall,
+} from "../entities";
+
+export class Tutorial extends Level {
+ constructor() {
+ super(LevelNames.Tutorial);
+ }
+
+ public init(game: Game): void {
+ const entities = [
+ new Player({ x: 2, y: 2 }),
+ new Wall({ x: 10, y: 9 }),
+ new Wall({ x: 10, y: 11 }),
+ new Wall({ x: 11, y: 10 }),
+ new Curry({ x: 10, y: 10 }),
+ new LockedDoor({ x: 9, y: 10 }),
+ new LambdaFactory({ x: 6, y: 3 }, "(λ (x) . x)", 3),
+
+ new FunctionApplication({ x: 6, y: 6 }, "(_INPUT key)"),
+ ];
+
+ entities.forEach((entity) => game.addEntity(entity));
+ }
+}
diff --git a/src/engine/levels/index.ts b/src/engine/levels/index.ts
new file mode 100644
index 0000000..36291aa
--- /dev/null
+++ b/src/engine/levels/index.ts
@@ -0,0 +1,12 @@
+export * from "./LevelNames";
+export * from "./Level";
+export * from "./LevelSelection";
+export * from "./Tutorial";
+
+import { LevelNames } from ".";
+import { LevelSelection, Tutorial, Level } from ".";
+
+export const LEVELS: Level[] = [new LevelSelection(), new Tutorial()];
+export const LEVEL_PROGRESSION = {
+ [LevelNames.LevelSelection]: [LevelNames.Tutorial],
+};
diff --git a/src/engine/levels/utils.ts b/src/engine/levels/utils.ts
new file mode 100644
index 0000000..7228f2b
--- /dev/null
+++ b/src/engine/levels/utils.ts
@@ -0,0 +1,6 @@
+import { Entity } from "../entities";
+
+// TODO
+//export const levelFormatToEntityList = (lines: string[]): Entity[] => {
+//
+//}