summaryrefslogtreecommitdiff
path: root/engine/entities/Floor.ts
blob: 44587e6909c77732b2fb64b51fbb21a3663332a1 (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
import { IMAGES, SPRITE_SPECS, Sprites, type SpriteSpec } from "../config";
import { BoundingBox, Sprite } from "../components";
import { TopCollidable } from "../components/TopCollidable";
import { Entity } from "../entities";

export class Floor extends Entity {
  private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
    Sprites.FLOOR,
  ) as SpriteSpec;

  constructor(width: number) {
    super();

    this.addComponent(
      new Sprite(
        IMAGES.get((Floor.spriteSpec?.states?.get(width) as SpriteSpec).sheet),
        { x: 0, y: 0 },
        { width, height: Floor.spriteSpec.height },
        Floor.spriteSpec.msPerFrame,
        Floor.spriteSpec.frames,
      ),
    );

    this.addComponent(
      new BoundingBox(
        { x: 300, y: 300 },
        { width, height: Floor.spriteSpec.height },
      ),
    );

    this.addComponent(new TopCollidable());
  }
}