From c568a8e49aaf64afa5799a9d6d55efafd529f451 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 24 Mar 2024 22:40:51 -0600 Subject: [PATCH] filter only colliding and pushable entities in collision test --- src/engine/systems/Grid.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/engine/systems/Grid.ts b/src/engine/systems/Grid.ts index 3c0e995..2eea704 100644 --- a/src/engine/systems/Grid.ts +++ b/src/engine/systems/Grid.ts @@ -139,11 +139,17 @@ export class Grid extends System { ); if (collidingEntities.length > 0) { - // i.e. key going into a door or function going into an application + // ensure everything that is a "pushable" or "colliding" which will collide with the entity + // can actually continue moving in the direction const allEntitiesInPreviousCellCanCollide = Array.from( this.grid[currentPosition.y][currentPosition.x], ) .map((id) => game.getEntity(id)!) + .filter( + (entity) => + entity.hasComponent(ComponentNames.Colliding) || + entity.hasComponent(ComponentNames.Pushable), + ) .every((entity) => collidingEntities.every((collidingEntity) => Collision.canCollide(entity.name, collidingEntity.name),