public static Entity PushableItemAt(this Pool pool, TilePos position, TilePos moveDirection) { var newPosition = position + moveDirection; var entitiesAtPosition = pool.GetEntitiesAt(position, x => x.isBox).ToList(); var openSpaceAtNextPosition = pool.OpenTileAt(newPosition); var stillInsidePuzzle = pool.IsStillInsideSamePuzzle(position, newPosition); return(openSpaceAtNextPosition && stillInsidePuzzle?entitiesAtPosition.SingleOrDefault() : null); }
public static Entity GetEntityAt(this Pool pool, TilePos position, Func <Entity, bool> entityMatcher = null) { var entitiesAtPosition = pool .GetEntitiesAt(position, entityMatcher) .ToList(); if (entitiesAtPosition.Count() > 1) { throw new MoreThanOneMatchException(entitiesAtPosition); } return(entitiesAtPosition.SingleOrDefault()); }
public void Execute(List <Entity> entities) { foreach (var box in entities) { var pushedToPosition = box.position.Value + box.knocked.FromDirection; var entitiesInFront = _pool.GetEntitiesAt(pushedToPosition).ToList(); var blockingAtNewPosition = !entitiesInFront.Any() || entitiesInFront.Any(x => x.isBlockingTile || x.isHero); if (!blockingAtNewPosition) { box.ReplacePosition(pushedToPosition); } else { box.IsRocked(true); } } }
public static bool OpenTileAt(this Pool pool, TilePos position) { var entitiesAtPosition = pool.GetEntitiesAt(position).ToList(); return(entitiesAtPosition.Any(x => x.gameObject.Type == ObjectType.Tile) && entitiesAtPosition.All(x => !x.isBlockingTile)); }