summaryrefslogtreecommitdiff
path: root/src/engine/levels
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/levels')
-rw-r--r--src/engine/levels/CarCadr.ts60
-rw-r--r--src/engine/levels/LevelNames.ts1
-rw-r--r--src/engine/levels/LevelSelection.ts47
-rw-r--r--src/engine/levels/Tutorial.ts2
-rw-r--r--src/engine/levels/index.ts10
5 files changed, 105 insertions, 15 deletions
diff --git a/src/engine/levels/CarCadr.ts b/src/engine/levels/CarCadr.ts
new file mode 100644
index 0000000..e3d1eb9
--- /dev/null
+++ b/src/engine/levels/CarCadr.ts
@@ -0,0 +1,60 @@
+import { Level, LevelNames } from ".";
+import { Game } from "..";
+import {
+ Curry,
+ FunctionApplication,
+ Grass,
+ LambdaFactory,
+ LockedDoor,
+ Player,
+ Wall,
+} from "../entities";
+import { Grid, SystemNames } from "../systems";
+import { normalRandom } from "../utils";
+
+export class CarCadr extends Level {
+ constructor() {
+ super(LevelNames.CarCadr);
+ }
+
+ public init(game: Game) {
+ const grid = game.getSystem<Grid>(SystemNames.Grid);
+ const dimensions = grid.getGridDimensions();
+
+ const grasses = Array.from({ length: dimensions.width })
+ .fill(0)
+ .map(() => {
+ // random grass
+ return new Grass({
+ x: Math.floor(
+ normalRandom(dimensions.width / 2, dimensions.width / 4, 1.5),
+ ),
+ y: Math.floor(
+ normalRandom(dimensions.height / 2, dimensions.height / 4, 1.5),
+ ),
+ });
+ });
+
+ const entities = [
+ ...grasses,
+ new Player({ x: 9, y: 5 }),
+ new Wall({ x: 4, y: 3 }),
+ new Wall({ x: 4, y: 4 }),
+ new LambdaFactory({ x: 6, y: 4 }, "(\\ (x) . x)", 1),
+ new FunctionApplication({ x: 5, y: 5 }, "(_INPUT _KEY)"),
+ new Wall({ x: 4, y: 5 }),
+ new Wall({ x: 6, y: 5 }),
+ new FunctionApplication({ x: 4, y: 6 }, "(_INPUT _NULL)"),
+ new Wall({ x: 6, y: 7 }),
+ new Wall({ x: 5, y: 7 }),
+ new Wall({ x: 4, y: 7 }),
+ new LockedDoor({ x: 3, y: 8 }),
+ new Curry({ x: 3, y: 9 }),
+ new Wall({ x: 2, y: 9 }),
+ new Wall({ x: 4, y: 9 }),
+ new Wall({ x: 3, y: 10 }),
+ ];
+
+ entities.forEach((entity) => game.addEntity(entity));
+ }
+} \ No newline at end of file
diff --git a/src/engine/levels/LevelNames.ts b/src/engine/levels/LevelNames.ts
index e90b29a..7f3c4f1 100644
--- a/src/engine/levels/LevelNames.ts
+++ b/src/engine/levels/LevelNames.ts
@@ -1,4 +1,5 @@
export namespace LevelNames {
export const Tutorial = "0";
+ export const CarCadr = "1";
export const LevelSelection = "LevelSelection";
}
diff --git a/src/engine/levels/LevelSelection.ts b/src/engine/levels/LevelSelection.ts
index a970d9c..9e46274 100644
--- a/src/engine/levels/LevelSelection.ts
+++ b/src/engine/levels/LevelSelection.ts
@@ -1,9 +1,12 @@
import { LEVELS, Level, LevelNames } from ".";
import { Game } from "..";
-import { Player, Portal } from "../entities";
+import { Grass, Player, Portal } from "../entities";
import { Grid, Level as LevelSystem, SystemNames } from "../systems";
+import { normalRandom } from "../utils";
export class LevelSelection extends Level {
+ public static RADIUS = 5;
+
constructor() {
super(LevelNames.LevelSelection);
}
@@ -11,23 +14,43 @@ export class LevelSelection extends Level {
public init(game: Game): void {
const gridSystem = game.getSystem<Grid>(SystemNames.Grid);
const center = gridSystem.getCenterGrid();
+ const dimensions = gridSystem.getGridDimensions();
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 renderableLevels = LEVELS.filter(
+ ({ name }) => name !== LevelNames.LevelSelection
+ );
+ const radiansPerLevel = (2 * Math.PI) / renderableLevels.length;
+ renderableLevels
+ .filter(({ name }) => unlocked.has(name))
+ .map((level, i) => {
+ const radians = i * radiansPerLevel;
+ const coords = {
+ x: Math.floor(Math.cos(radians) * LevelSelection.RADIUS + center.x),
+ y: Math.floor(Math.sin(radians) * LevelSelection.RADIUS + center.y),
+ };
+ return new Portal(level.name, coords);
+ })
+ .forEach((e) => game.addEntity(e));
const player = new Player(center);
game.addEntity(player);
+
+ Array.from({ length: dimensions.width })
+ .fill(0)
+ .map(() => {
+ // random grass
+ return new Grass({
+ x: Math.floor(
+ normalRandom(dimensions.width / 2, dimensions.width / 4, 1.5)
+ ),
+ y: Math.floor(
+ normalRandom(dimensions.height / 2, dimensions.height / 4, 1.5)
+ ),
+ });
+ })
+ .forEach((e) => game.addEntity(e));
}
}
diff --git a/src/engine/levels/Tutorial.ts b/src/engine/levels/Tutorial.ts
index 895b569..97a6826 100644
--- a/src/engine/levels/Tutorial.ts
+++ b/src/engine/levels/Tutorial.ts
@@ -43,7 +43,7 @@ export class Tutorial extends Level {
{ x: 4, y: 3 },
),
new Sign(
- "this is a Term Application; interact to view its code<br><br>push the term ➡️ created by the factory any direction into the Application to produce a new one 💭<br><br>note that:<br><br>+ _INPUT is the term replaced by the pushed term<br><br>+ in this case _KEY is applied to the function to make a new KEY! 🔑",
+ "<div>this is a Term Application; interact to view its code<br><br>push the term ➡️ created by the factory any direction into the Application to produce a new one 💭<br><br>note that:<br><br>+ _INPUT is the term replaced by the pushed term<br><br>+ in this case _KEY is applied to the function to make a new KEY! 🔑</div>",
{ x: 4, y: 6 },
),
new Wall({ x: 10, y: 9 }),
diff --git a/src/engine/levels/index.ts b/src/engine/levels/index.ts
index bae7fea..216453c 100644
--- a/src/engine/levels/index.ts
+++ b/src/engine/levels/index.ts
@@ -2,11 +2,17 @@ export * from "./LevelNames";
export * from "./Level";
export * from "./LevelSelection";
export * from "./Tutorial";
+export * from "./CarCadr";
import { LevelNames } from ".";
-import { LevelSelection, Tutorial, Level } from ".";
+import { CarCadr, LevelSelection, Tutorial, Level } from ".";
-export const LEVELS: Level[] = [new LevelSelection(), new Tutorial()];
+export const LEVELS: Level[] = [
+ new LevelSelection(),
+ new Tutorial(),
+ new CarCadr(),
+];
export const LEVEL_PROGRESSION: Record<string, string[]> = {
[LevelNames.LevelSelection]: [LevelNames.Tutorial],
+ [LevelNames.Tutorial]: [LevelNames.CarCadr],
};