jumpstorm/engine/entities/Floor.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-08-25 18:48:17 -04:00
import { IMAGES, SPRITE_SPECS, Sprites, type SpriteSpec } from '../config';
2023-08-26 19:55:27 -04:00
import { BoundingBox, ComponentNames, Sprite } from '../components';
2023-08-25 18:48:17 -04:00
import { TopCollidable } from '../components/TopCollidable';
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(
2023-08-25 18:48:17 -04:00
Sprites.FLOOR
2023-08-12 15:49:16 -04:00
) as SpriteSpec;
2023-07-19 23:38:24 -04:00
2023-08-26 19:55:27 -04:00
private width: number;
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
2023-08-26 19:55:27 -04:00
this.width = width;
2023-07-19 23:38:24 -04:00
this.addComponent(
new Sprite(
IMAGES.get(Floor.spriteSpec!.states!.get(width)!.sheet!)!,
2023-07-19 23:38:24 -04:00
{ x: 0, y: 0 },
{ width, height: Floor.spriteSpec.height },
Floor.spriteSpec.msPerFrame,
2023-08-25 18:48:17 -04:00
Floor.spriteSpec.frames
)
2023-07-19 23:38:24 -04:00
);
this.addComponent(new TopCollidable());
}
2023-08-26 19:55:27 -04: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 23:38:24 -04:00
}