Ejemplo n.º 1
0
        public void MoveBoss(Entity boss)
        {
            var hero         = _pool.GetHero();
            var heroPosition = hero.position.Value;

            var pathToHero = _movementCalculator.CalculateMoveToTarget(
                boss.position.Value,
                LocalDirections.ToDirection(boss.rotation.Value),
                heroPosition);

            if (!pathToHero.HasStepsLeft)
            {
                return;
            }

            var nextStep = pathToHero.NextStep();

            if (nextStep.Position != heroPosition)
            {
                if (Debug.isDebugBuild)
                {
                    DrawBossPath(pathToHero);
                }

                boss.ReplacePosition(nextStep.Position);

                var knockedObjectInFront = _pool.KnockObjectsInFront(nextStep.Position, nextStep.Direction, false, 0.4f);
                if (knockedObjectInFront)
                {
                    boss.HasBumpedIntoObject(true);
                }
                else if (_pool.GetTileAt(nextStep.Position + nextStep.Direction) == null)
                {
                    boss.HasRecoveredAtEdge(true);
                }
            }
            else
            {
                boss.IsAttacking(true);
                hero.ReplaceHealth(hero.health.Value - 1);
                _pool.SwitchCurse();
            }

            boss.ReplaceRotation(LocalDirections.ToRotation(nextStep.Direction));
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
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
                {
                }
            }
        }
Ejemplo n.º 4
0
        public Path CalculateMoveToTarget(
            TilePos initialPosition,
            TilePos initialDirection,
            TilePos targetPosition)
        {
            _targetPosition = targetPosition;
            var victoryPath = new Path(initialPosition, initialDirection);

            SetInitialState(initialPosition, initialDirection);
            while (_pathsToContinue.Count > 0)
            {
                var path = PopPathToContinue();
                var pos  = path.GetLastPosition();

                if (pos == _targetPosition)
                {
                    victoryPath = SelectLateTurnPathWithSameCost(path);
                    break;
                }

                foreach (var moveDirection in LocalDirections.GetAll())
                {
                    var newPos = pos + moveDirection;
                    if (_walkValidator.CanMoveTo(newPos) && !_visited.Contains(newPos))
                    {
                        AddNewPathToContinue(newPos, moveDirection, path);
                    }
                }

                _visited.Add(pos);
                OrderByCost();
            }

            victoryPath.Steps.RemoveAt(0);
            return(victoryPath);
        }