diff options
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, |