49 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2023-08-25 16:48:17 -06:00
import { IMAGES, SPRITE_SPECS, Sprites, type SpriteSpec } from '../config';
2023-08-26 17:55:27 -06:00
import { BoundingBox, ComponentNames, Sprite } from '../components';
2023-08-25 16:48:17 -06:00
import { TopCollidable } from '../components/TopCollidable';
import { Entity, EntityNames } from '../entities';
2023-07-19 20:38:24 -07:00
export class Floor extends Entity {
2023-08-12 13:49:16 -06:00
private static spriteSpec: SpriteSpec = SPRITE_SPECS.get(
2023-08-25 16:48:17 -06:00
Sprites.FLOOR
2023-08-12 13:49:16 -06:00
) as SpriteSpec;
2023-07-19 20:38:24 -07:00
2023-08-26 17:55:27 -06:00
private width: number;
2023-07-19 20:38:24 -07:00
constructor(width: number) {
2023-08-23 19:44:59 -06:00
super(EntityNames.Floor);
2023-07-19 20:38:24 -07:00
2023-08-26 17:55:27 -06:00
this.width = width;
2023-07-19 20:38:24 -07:00
this.addComponent(
new Sprite(
IMAGES.get(Floor.spriteSpec!.states!.get(width)!.sheet!)!,
2023-07-19 20:38:24 -07:00
{ x: 0, y: 0 },
{ width, height: Floor.spriteSpec.height },
Floor.spriteSpec.msPerFrame,
2023-08-25 16:48:17 -06:00
Floor.spriteSpec.frames
)
2023-07-19 20:38:24 -07:00
);
this.addComponent(new TopCollidable());
}
2023-08-26 17:55:27 -06:00
public serialize() {
return {
floorWidth: this.width,
boundingBox: this.getComponent<BoundingBox>(ComponentNames.BoundingBox)
};
}
public setFrom(args: any) {
const { boundingBox } = args;
this.addComponent(
new BoundingBox(
boundingBox.center,
boundingBox.dimension,
boundingBox.rotation
)
);
}
2023-07-19 20:38:24 -07:00
}