diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-02 02:22:46 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-02 02:24:18 -0700 |
commit | 06bb4177202b432d5f42141975ec82b5a8837f0e (patch) | |
tree | 7a9cb1e4177684848a3fcca91eed2ec703c787fb /src/engine/entities/Wall.ts | |
parent | cd6a3a56b0a9f27dd7250c7641776fe1bd184888 (diff) | |
download | the-abstraction-engine-06bb4177202b432d5f42141975ec82b5a8837f0e.tar.gz the-abstraction-engine-06bb4177202b432d5f42141975ec82b5a8837f0e.zip |
slight refactor in collision behavior
Diffstat (limited to 'src/engine/entities/Wall.ts')
-rw-r--r-- | src/engine/entities/Wall.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/engine/entities/Wall.ts b/src/engine/entities/Wall.ts new file mode 100644 index 0000000..621a569 --- /dev/null +++ b/src/engine/entities/Wall.ts @@ -0,0 +1,45 @@ +import { Entity, EntityNames } from "."; +import { BoundingBox, Colliding, Grid, Sprite } from "../components"; +import { IMAGES, SPRITE_SPECS, SpriteSpec, Sprites } from "../config"; +import { Coord2D } from "../interfaces"; + +export class Wall extends Entity { + private static spriteSpec: SpriteSpec = SPRITE_SPECS.get( + Sprites.WALL, + ) as SpriteSpec; + + constructor(gridPosition: Coord2D) { + super(EntityNames.Wall); + + this.addComponent(new Grid(gridPosition)); + + this.addComponent(new Colliding()); + + this.addComponent( + new BoundingBox( + { + x: 0, + y: 0, + }, + { + width: Wall.spriteSpec.width, + height: Wall.spriteSpec.height, + }, + 0, + ), + ); + + this.addComponent( + new Sprite( + IMAGES.get(Wall.spriteSpec.sheet)!, + { x: 0, y: 0 }, + { + width: Wall.spriteSpec.width, + height: Wall.spriteSpec.height, + }, + Wall.spriteSpec.msPerFrame, + Wall.spriteSpec.frames, + ), + ); + } +} |