jumpstorm/engine/entities/Floor.ts

37 lines
945 B
TypeScript
Raw Normal View History

2023-07-19 23:38:24 -04:00
import { IMAGES, SPRITE_SPECS, Sprites, type SpriteSpec } from "../config";
import { BoundingBox, Sprite } from "../components";
import { TopCollidable } from "../components/TopCollidable";
2023-08-23 21:44:59 -04:00
import { Entity, EntityNames } from "../entities";
2023-07-19 23:38:24 -04:00
export class Floor extends Entity {
2023-08-12 15:49:16 -04:00
private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
Sprites.FLOOR,
) as SpriteSpec;
2023-07-19 23:38:24 -04:00
constructor(width: number) {
2023-08-23 21:44:59 -04:00
super(EntityNames.Floor);
2023-07-19 23:38:24 -04:00
this.addComponent(
new Sprite(
2023-08-12 15:49:16 -04:00
IMAGES.get((Floor.spriteSpec?.states?.get(width) as SpriteSpec).sheet),
2023-07-19 23:38:24 -04:00
{ x: 0, y: 0 },
{ width, height: Floor.spriteSpec.height },
Floor.spriteSpec.msPerFrame,
2023-08-12 15:49:16 -04:00
Floor.spriteSpec.frames,
),
2023-07-19 23:38:24 -04:00
);
this.addComponent(
new BoundingBox(
{
x: 300,
y: 300,
},
2023-08-12 15:49:16 -04:00
{ width, height: Floor.spriteSpec.height },
),
2023-07-19 23:38:24 -04:00
);
this.addComponent(new TopCollidable());
}
}