summaryrefslogtreecommitdiff
path: root/src/engine/levels/Tutorial.ts
blob: 895b5696a7a5c1cd3283593493921159057902b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Level, LevelNames } from ".";
import { Game } from "..";
import {
  Curry,
  FunctionApplication,
  Grass,
  LambdaFactory,
  LockedDoor,
  Player,
  Sign,
  Wall,
} from "../entities";
import { Grid, SystemNames } from "../systems";
import { normalRandom } from "../utils";

export class Tutorial extends Level {
  constructor() {
    super(LevelNames.Tutorial);
  }

  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 Sign(
        "<div>this is a Lambda Factory<br><br>modify the produced term by interacting from the top or bottom ↕️<br><br>then produce the term by pressing the button on the left or right ↔️<br><br></div>",
        { 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! 🔑",
        { x: 4, y: 6 },
      ),
      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 }, "// TODO: Remove line\n(λ (x) . x)", 3),
      new FunctionApplication({ x: 6, y: 6 }, "(_INPUT _KEY)"),
      new Player({ x: 2, y: 2 }),
    ];

    entities.forEach((entity) => game.addEntity(entity));
  }
}