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 void Execute(List <Entity> entities) { var hero = entities.SingleEntity(); var moveDirection = hero.inputMove.Direction; var newPosition = moveDirection + hero.position.Value; var canMoveTo = _pool.OpenTileAt(newPosition); var stillInsideSamePuzzle = _pool.IsStillInsideSamePuzzle(hero.position.Value, newPosition); if (canMoveTo && !(hero.isSpikesCarried && !stillInsideSamePuzzle)) { hero.ReplacePosition(newPosition); hero.ReplaceRotation(LocalDirections.ToRotation(moveDirection)); } else { var hasKnockedObjectInFront = _pool.KnockObjectsInFront(hero.position.Value, moveDirection, true, 0.4f); if (hasKnockedObjectInFront) { var knockedObject = _pool.GetEntityAt(newPosition, x => x.hasKnocked); var pushableCanMove = _pool.OpenTileAt(newPosition + moveDirection); if (pushableCanMove && knockedObject.isBox) { hero.IsPushing(true); hero.ReplacePosition(newPosition); } else { hero.HasBumpedIntoObject(true); } hero.ReplaceRotation(LocalDirections.ToRotation(moveDirection)); } else { } } }
public void Execute(List <Entity> entities) { var hero = entities.SingleEntity(); var pullDirection = hero.inputPullItem.Direction; var pushablePosition = hero.position.Value - pullDirection; var pushableItem = _pool.PushableItemAt(pushablePosition, pullDirection); if (pushableItem != null) { var newHeroPosition = hero.position.Value + pullDirection; var playerHasOpenSpaceToMoveTo = _pool.OpenTileAt(newHeroPosition); if (playerHasOpenSpaceToMoveTo) { pushableItem.ReplaceKnocked(pullDirection, false, 0); hero.ReplacePosition(newHeroPosition); hero.ReplaceRotation(LocalDirections.ToRotation(-pullDirection)); hero.IsPulling(true); } } }
public bool CanMoveTo(TilePos position) { return(_pool.OpenTileAt(position)); }