From e6e29440563e33bb67e0ad51f9fb6c5c2c3fe809 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Thu, 7 Mar 2024 20:45:47 -0700 Subject: level one (applications prototype finished!) --- src/engine/systems/Grid.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/engine/systems/Grid.ts') 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(ComponentNames.Grid)!; + if (grid.movingDirection === Direction.NONE) { return; } + grid.previousDirection = grid.movingDirection; const boundingBox = entity.getComponent( 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, -- cgit v1.2.3-70-g09d2