summaryrefslogtreecommitdiff
path: root/src/engine/levels/CarCadr.ts
blob: e3d1eb95af835bd63cd3c61dfa63531635106403 (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
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));
  }
}