diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-07 20:45:47 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-07 20:45:47 -0700 |
commit | e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809 (patch) | |
tree | 5deaee322ff1a039dc44a3cb52ecc48a671fda2a /src/engine/systems/Grid.ts | |
parent | 823620b2a6ebb7ece619991e47a37ad46542b69f (diff) | |
download | the-abstraction-engine-e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809.tar.gz the-abstraction-engine-e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809.zip |
level one (applications prototype finished!)
Diffstat (limited to 'src/engine/systems/Grid.ts')
-rw-r--r-- | src/engine/systems/Grid.ts | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/engine/systems/Grid.ts b/src/engine/systems/Grid.ts index 1d4a623..9ab28e3 100644 --- a/src/engine/systems/Grid.ts +++ b/src/engine/systems/Grid.ts @@ -33,8 +33,8 @@ export class Grid extends System { this.rebuildGrid(game); this.highlightEntitiesLookedAt(game); - this.propogateEntityMovements(game); + this.propogateEntityMovements(game); this.updateMovingEntities(dt, game); } @@ -209,9 +209,11 @@ export class Grid extends System { ) { game.forEachEntityWithComponent(ComponentNames.Grid, (entity) => { const grid = entity.getComponent<GridComponent>(ComponentNames.Grid)!; + if (grid.movingDirection === Direction.NONE) { return; } + grid.previousDirection = grid.movingDirection; const boundingBox = entity.getComponent<BoundingBox>( ComponentNames.BoundingBox, @@ -270,7 +272,7 @@ export class Grid extends System { }); } - private getNewGridPosition(prev: Coord2D, direction: Direction) { + public getNewGridPosition(prev: Coord2D, direction: Direction) { let { x: newX, y: newY } = prev; switch (direction) { case Direction.LEFT: @@ -290,6 +292,25 @@ export class Grid extends System { return { x: newX, y: newY }; } + public oppositeDirection(direction: Direction) { + let opposite = Direction.NONE; + switch (direction) { + case Direction.LEFT: + opposite = Direction.RIGHT; + break; + case Direction.RIGHT: + opposite = Direction.LEFT; + break; + case Direction.UP: + opposite = Direction.DOWN; + break; + case Direction.DOWN: + opposite = Direction.UP; + break; + } + return opposite; + } + private isEntityPastCenterWhenMoving( direction: Direction, gridPosition: Coord2D, |