Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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
                {
                }
            }
        }