/// <summary>
        /// Initializes a new instance of the <see cref="BasePathScenario" /> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        protected BasePathScenario(int width, int height)
        {
            Width  = width;
            Height = height;

            int volume = Width * Height;

            Directions  = DirectionHelper.GetValues().ToList();
            Cache       = UseCache ? new BitArray(volume) : null;
            DistanceMap = new ushort[volume];

            IsFirstRun = true;
            AreHollowAreasMinimized = true;
            ObstacleDetectionMethod = BlockMethodType.Precise;
        }
    private IEnumerator FireProjectile()
    {
        while (Health > 0)
        {
            yield return(new WaitForSecondsRealtime(timeBetweenAttacks));

            if (!playerSensor.playerInRange)
            {
                continue;
            }
            EnemyProjectile projectile      = Instantiate(projectilePrefab, transform.position, Quaternion.identity).GetComponent <EnemyProjectile>();
            Vector2         playerDirection = DirectionHelper.GetDirectionVector((player.transform.position - transform.position).x > 0 ? EDirection.Right : EDirection.Left);
            projectile.TargetPosition = transform.position + new Vector3(playerDirection.x, playerDirection.y, 0);
        }
    }
Exemplo n.º 3
0
        public void DoTurn()
        {
            if (DOTween.IsTweening(MakeUniqueId(TurnTweenId)))
            {
                DOTween.Kill(MakeUniqueId(TurnTweenId));
                OnTurnNotCompleted();
            }

            var targetDirection = DirectionHelper.SwapHorizontalDirection(Direction);

            var rot = targetDirection == HorizontalDirection.Left ? LeftRotation : RightRotation;

            Direction = DirectionHelper.SwapHorizontalDirection(Direction);
            StartTurnMotionAndPlayTurnSound(rot, TurnTime, TurnEase, TurnTweenId, OnTurnCompleted, OnTurnStarted);
        }
        /* Highlighting of all possible moves
         */
        private void HighlightPossibleTurns(BaseChecker currentSelectedChecker)
        {
            PathPoint turns = currentSelectedChecker.GetPossibleTurns();

            if (!turns.IsDeadEnd())
            {
                foreach (TurnDirection direction in DirectionHelper.GetAllDirections())
                {
                    foreach (PathPoint point in turns[direction])
                    {
                        board[point.Position.X, point.Position.Y].Highlighted = true;
                    }
                }
            }
        }
        private static ProgressLine[] GetProgressLines(
            Point origin,
            Direction entranceDirection,
            Direction exitDirection)
        {
            var lines = new List <ProgressLine>();

            var combinedDirection = DirectionHelper.GetCombinedDirection(
                entranceDirection,
                exitDirection);

            switch (combinedDirection)
            {
            case Direction.Right:
                lines.AddRange(GetRightProgressLines(origin));
                break;

            case Direction.Left:
                lines.AddRange(GetLeftProgressLines(origin));
                break;

            case Direction.Top:
                lines.AddRange(GetTopProgressLines(origin));
                break;

            case Direction.Bottom:
                lines.AddRange(GetBottomProgressLines(origin));
                break;

            case Direction.BottomLeft:
                lines.AddRange(GetBottomLeftProgressLines(origin));
                break;

            case Direction.BottomRight:
                lines.AddRange(GetBottomRightProgressLines(origin));
                break;

            case Direction.TopLeft:
                lines.AddRange(GetTopLeftProgressLines(origin));
                break;

            case Direction.TopRight:
                lines.AddRange(GetTopRightProgressLines(origin));
                break;
            }

            return(lines.ToArray());
        }
Exemplo n.º 6
0
    private void UpdateVelocity()
    {
        if (executed)
        {
            return;
        }

        if (Health > 0)
        {
            enemyRigidbody.velocity = (DirectionHelper.GetDirectionVector(moveDirection) * moveSpeed) + new Vector2(0, enemyRigidbody.velocity.y);
        }
        else
        {
            enemyRigidbody.velocity = new Vector2();
        }
    }
Exemplo n.º 7
0
        void doMouseMovement(double frameMS)
        {
            var player = (Mobile)WorldModel.Entities.GetPlayerEntity();

            if (player == null)
            {
                return;
            }
            // if the move button is pressed, change facing and move based on mouse cursor direction.
            if (ContinuousMouseMovementCheck)
            {
                var resolution     = UltimaGameSettings.UserInterface.PlayWindowGumpResolution;
                var centerScreen   = new Vector2Int(resolution.Width / 2, resolution.Height / 2);
                var mouseDirection = DirectionHelper.DirectionFromPoints(centerScreen, MouseOverWorldPosition);
                _timeSinceMovementButtonPressed += frameMS;
                if (_timeSinceMovementButtonPressed >= c_PauseBeforeMouseMovementMS)
                {
                    // Get the move direction.
                    var moveDirection = mouseDirection;
                    // add the running flag if the mouse cursor is far enough away from the center of the screen.
                    var distanceFromCenterOfScreen = Utility.DistanceBetweenTwoPoints(centerScreen, MouseOverWorldPosition);
                    if (distanceFromCenterOfScreen >= 150.0f || UltimaGameSettings.UserInterface.AlwaysRun)
                    {
                        moveDirection |= Direction.Running;
                    }
                    player.PlayerMobile_Move(moveDirection);
                }
                else
                {
                    // Get the move direction.
                    var facing = mouseDirection;
                    if (player.Facing != facing)
                    {
                        // Tell the player entity to change facing to this direction.
                        player.PlayerMobile_ChangeFacing(facing);
                        // reset the time since the mouse cursor was pressed - allows multiple facing changes.
                        _timeSinceMovementButtonPressed = 0d;
                    }
                }
            }
            else
            {
                _timeSinceMovementButtonPressed = 0d;
                // Tell the player to stop moving.
                player.PlayerMobile_Move(Direction.Nothing);
            }
        }
        private void UpdateMeshAndDirection()
        {
            // Count number of connections along cardinal (which is all that we use atm)
            var cardinalInfo = adjacents.GetCardinalInfo();

            // Determine rotation and mesh specially for every single case.
            // TODO: add meshes mentioned in header to script
            float rotation = 0.0f;
            Mesh  mesh;

            if (cardinalInfo.IsO())
            {
                mesh = o;
            }
            else if (cardinalInfo.IsC())
            {
                mesh     = c;
                rotation = DirectionHelper.AngleBetween(Direction.North, cardinalInfo.GetOnlyPositive());
            }
            else if (cardinalInfo.IsI())
            {
                mesh     = i;
                rotation = OrientationHelper.AngleBetween(Orientation.Vertical, cardinalInfo.GetFirstOrientation());
            }
            else if (cardinalInfo.IsL())
            {
                mesh     = l;
                rotation = DirectionHelper.AngleBetween(Direction.NorthEast, cardinalInfo.GetCornerDirection());
            }
            else if (cardinalInfo.IsT())
            {
                mesh     = t;
                rotation = DirectionHelper.AngleBetween(Direction.South, cardinalInfo.GetOnlyNegative());
            }
            else // Must be X
            {
                mesh = xAll;
            }

            if (filter == null)
            {
                filter = GetComponent <MeshFilter>();
            }

            filter.mesh             = mesh;
            transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, rotation, transform.localRotation.eulerAngles.z);
        }
Exemplo n.º 9
0
    private Direction ChooseDirection(Vector2Int currentTile, Vector2Int targetTile, List <Direction> validDirections)
    {
        Direction chosenDirection = currentDirection; // Dummy value
        var       leastDistance   = float.MaxValue;

        foreach (var direction in validDirections)
        {
            if (DirectionHelper.DirectionsAreOpposite(currentDirection, direction))
            {
                continue;
            }

            var xCoord = currentTile.x;
            var yCoord = currentTile.y;
            switch (direction)
            {
            case Direction.Down:
                yCoord += 1;
                break;

            case Direction.Up:
                yCoord -= 1;
                break;

            case Direction.Right:
                xCoord += 1;
                break;

            case Direction.Left:
                xCoord -= 1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Vector2Int projectedTile = new Vector2Int(xCoord, yCoord);
            var        distance      = Vector2Int.Distance(targetTile, projectedTile);
            if (distance < leastDistance)
            {
                chosenDirection = direction;
                leastDistance   = distance;
            }
        }
        return(chosenDirection);
    }
        private void CloseWall(Wall wallEntity, Wall wall)
        {
            wallEntity.Row       = wall.Row;
            wallEntity.Column    = wall.Column;
            wallEntity.Direction = wall.Direction;

            var nextPosition     = PositionHelper.GetNextPosition(wall.Row, wall.Column, wall.Direction);
            var reverseDirection = DirectionHelper.GetReverseDirection(wall.Direction);

            GameObject wallObject        = null;
            GameObject reverseWallObject = null;

            foreach (var wallObj in _wallGameObjects)
            {
                var wallElement = wallObj.transform.GetComponent <WallElement>();
                if (
                    wallElement.Row == wall.Row &&
                    wallElement.Column == wall.Column &&
                    wallElement.Direction == wall.Direction
                    )
                {
                    wallObject = wallObj;
                }

                if (
                    wallElement.Row == nextPosition.Row &&
                    wallElement.Column == nextPosition.Column &&
                    wallElement.Direction == reverseDirection
                    )
                {
                    reverseWallObject = wallObj;
                }
            }

            wallEntity.Transforms = new List <Transform>();
            if (wallObject != null)
            {
                wallEntity.Transforms.Add(wallObject.transform);
                wallObject.SetActive(true);
            }
            if (reverseWallObject != null)
            {
                wallEntity.Transforms.Add(reverseWallObject.transform);
                reverseWallObject.SetActive(true);
            }
        }
Exemplo n.º 11
0
        public ArrowThreeWayCell(int col, int row) : base(col, row)
        {
            CellType = CellType.ArrowThreeWay;
            Terminal = false;

            directionHelper = new DirectionHelper();
            direction       = directionHelper.RandomizeDirection();

            var dirs = new List <Direction> {
                Direction.N,
                Direction.E,
                Direction.SW
            };


            turnListTo = directionHelper.TurnListTo(direction, dirs);
        }
Exemplo n.º 12
0
    public void ManageMovement()
    {
        Vector2 input = GetInput();

        BaseConstants.Direction direction = DirectionHelper.VectorToDirection(input);

        if (direction != BaseConstants.Direction.None)
        {
            Move(direction);

            // Animate walking if receiving input
            if (!currentDirection.Equals(BaseConstants.Direction.None))
            {
                AnimateMovement();
            }
        }
    }
Exemplo n.º 13
0
    /// <summary>
    /// Shoots projectile in given direction
    /// </summary>
    /// <param name="vector">Vector</param>
    /// <param name="actor">Actor that shot projectile</param>
    public void Shoot(Vector2 vector, Actor actor)
    {
        // Set velocity
        GetComponent <Rigidbody2D>().velocity = vector * speed;
        GameController.Log("Trajectory: " + vector, GameController.LogPhysics);

        // Set rotation (flip 90 degrees if needed)
        if (!DirectionHelper.IsVertical(DirectionHelper.VectorToDirection(vector)))
        {
            Quaternion rotation = transform.rotation;
            rotation.eulerAngles = new Vector3(0, 0, 90F);
            transform.rotation   = rotation;
        }

        // Save reference to actor so his bullets don't damage him
        this.actor = actor;
    }
Exemplo n.º 14
0
    private bool IsElementAvailable(int column, int row, int round, int number, DirectionEnum direction)
    {
        var position = PositionHelper.GetNextPosition(column, row, direction);
        var element  = GetBoardElement(position);
        var wall     = GetWall(position, DirectionHelper.GetReverseDirection(direction));

        if (
            wall != null ||
            (element.ContainsSnakeStep && element.Round == round) ||
            (element.ContainsTarget && element.Round == round && !TargetHelper.CanGetTargetElement(number))
            )
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 15
0
        protected override void Awake()
        {
            if (this.SetDirectionAutomatically)
            {
                this.AllowedDirection = DirectionHelper.FromRotation(this.Rotation2D, Direction2D.Down);
            }

            _previousScaleY    = this.Scale2D.Y;
            _previousPositionY = this.Position2D.Y;

            var boxCollider = this.Get <BoxCollider2D>();

            if (boxCollider != null)
            {
                _scaleMultiplier = boxCollider.size.y;
            }
        }
Exemplo n.º 16
0
    public void JumpPressed()
    {
        if ((!IsGrounded || !CanMove) && !IsWallclimbing)
        {
            return;
        }

        if (IsWallclimbing)
        {
            playerRigidbody.AddForce(new Vector2(JumpPower * -2 * DirectionHelper.GetDirectionVector(forwardDirection).x, JumpPower));
        }
        else
        {
            playerRigidbody.AddForce(new Vector2(0, JumpPower));
        }
        playerRigidbody.gravityScale = jumpGravityScale;
        jumpHeld = true;
    }
Exemplo n.º 17
0
    private Sequence OnTurnInternal()
    {
        Sequence sequence = DOTween.Sequence();

        // Store the previous location
        prevPos = pos.GetVector2i();

        // Move the projectile based on the position
        var moveDir = DirectionHelper.ToVector2i(MovingDirection);

        sequence.Append(pos.AnimatedMove(pos.X + moveDir.x, pos.Y + moveDir.y, 0.2f));

        OnTurn(sequence);

        CheckAndDestroy(sequence);

        return(sequence);
    }
Exemplo n.º 18
0
        public void Update(double deltaTime)
        {
            _player.Update(deltaTime);

            if (_player.Dead)
            {
                MainWindow.SetGameState(new GameStateGameOver((int)_player.Score));
            }

            _scoreText.Str = $"Score: {(int)_player.Score}";
            _world.Update();

            var playerPosition = _player.PositionForCamera;

            _camera.Target = playerPosition + new Vector3(0, 2.5f, 0);
            _camera.UpdateCameraPosition(playerPosition + (-DirectionHelper.GetVectorFromDirection(_player.CurrentDirection) * 4f) + new Vector3(0, 3, 0), (float)deltaTime, 5f);
            _coinsRotation += 0.1f;
        }
        public Map GenerateRandomMap()
        {
            while (true)
            {
                var mapBuilder = CreateMapBuilder();
                var directions = new List <Direction>();

                var seenPoints = new HashSet <Point>();

                var repeatedFailureCount = 0;

                var currentDirection = Direction.Top;
                while (repeatedFailureCount < 100)
                {
                    var previousDirection = currentDirection;
                    var newDirection      = directionHelper.GetRandomDirectionOtherThan(
                        previousDirection,
                        DirectionHelper.GetOppositeDirection(
                            previousDirection));

                    mapBuilder.MoveInDirection(newDirection);

                    repeatedFailureCount = 0;

                    var currentPoint = mapBuilder.CurrentPoint;
                    currentDirection = newDirection;

                    directions.Add(newDirection);
                    seenPoints.Add(currentPoint);

                    if (currentPoint.X == 0 && currentPoint.Y == 0)
                    {
                        if (directions.Count == 4)
                        {
                            break;
                        }

                        return(mapBuilder.Build());
                    }
                }
            }

            throw new NotImplementedException();
        }
Exemplo n.º 20
0
        /// <summary>
        /// 更新一帧
        /// </summary>
        /// <param name="input">用户在这一帧内的输入。当前来说,如果玩家在一帧内按下了多个按钮,我们只处理第一个</param>
        /// <returns>地图上被改变了的点的坐标集合</returns>
        public IEnumerable <Point> Update(params GameKey[] input)
        {
            // 如果没有输入的话,那么蛇继续沿着之前的方向移动
            if (input.Length == 0)
            {
                return(this.ProcessPlayerMove());
            }

            var key = input[0];

            switch (key)
            {
            case GameKey.A:
                break;

            case GameKey.B:
                // 更新间隔在5帧和3帧之间切换
                this.frameSkipper.FramePerUpdate = this.frameSkipper.FramePerUpdate == 5 ? 3 : 5;
                break;

            // 如果输入了方向键的话
            case GameKey.Up:
            case GameKey.Down:
            case GameKey.Left:
            case GameKey.Right:
                // ToDirection是扩展方法,返回的是带问号(Nullable)的Direction,也就是【Direction?】。需要用强制类型转换转成Direction
                var newDirection = (Direction)key.ToDirection();
                // 蛇只能转向,不能掉头
                if (!DirectionHelper.IsOpposite(this.currentDirection, newDirection))
                {
                    this.currentDirection = newDirection;
                }

                return(ProcessPlayerMove());

            default:
                break;
            }

            // 什么情况下会执行到这行呢?
            // 答案:当用户有输入,但是输入的不是方向键的情况下
            return(ProcessPlayerMove());
        }
Exemplo n.º 21
0
        public void Grow()
        {
            _logger.Debug($"Snake.Grow()");

            if (Head == null)
            {
                Head = new SnakeSegment(new Vector2((float)_gameSettings.TileSize), new Size2(_gameSettings.TileSize, _gameSettings.TileSize), Direction.Left); //GenerateRandomSegment();
            }
            else
            {
                var last = Tail.Any() ? Tail.LastOrDefault() : Head;

                if (last != null)
                {
                    var position = last.Position + DirectionHelper.RotateVector(_unitVector, DirectionHelper.GetOppositeDirection(last.Direction));
                    _tail.Add(new SnakeSegment(position, last.Size, last.Direction));
                }
            }
        }
Exemplo n.º 22
0
    protected override void WhenDestroyed()
    {
        base.WhenDestroyed();
        Direction        firstDir = DirectionHelper.GetRandom();
        List <Direction> dirs     = new List <Direction>()
        {
            Direction.Down, Direction.Left, Direction.Right, Direction.Up
        }
        .Where(dir => dir != firstDir)
        .Where(dir => CheckTileIsNormal(pos.GetVector2i() + dir.ToVector2i())).ToList();
        Direction secondDir = Direction.None;

        if (dirs.Any())
        {
            secondDir = dirs.GetRandom();
        }

        SpawnMonster("ZacBaby", pos.X, pos.Y, firstDir);
        SpawnMonster("ZacBaby", pos.X, pos.Y, secondDir);

        /*
         *      if (CheckTileIsNormal (pos.X + 2, pos.Y) && CheckTileIsNormal (pos.X - 2, pos.Y))
         *      {
         *              SpawnMonster ("ZacBaby", pos.X + 2, pos.Y);
         *              SpawnMonster ("ZacBaby", pos.X - 2, pos.Y);
         *      }
         *      else if (CheckTileIsNormal (pos.X, pos.Y - 2) && CheckTileIsNormal (pos.X, pos.Y + 2))
         *      {
         *              SpawnMonster ("ZacBaby", pos.X, pos.Y - 2);
         *              SpawnMonster ("ZacBaby", pos.X, pos.Y + 2);
         *      }
         *      else if (CheckTileIsNormal (pos.X + 2, pos.Y) && CheckTileIsNormal (pos.X, pos.Y + 2))
         *      {
         *              SpawnMonster ("ZacBaby", pos.X + 2, pos.Y);
         *              SpawnMonster ("ZacBaby", pos.X, pos.Y + 2);
         *      }
         *      else if (CheckTileIsNormal (pos.X - 2, pos.Y) && CheckTileIsNormal (pos.X, pos.Y - 2))
         *      {
         *              SpawnMonster ("ZacBaby", pos.X - 2, pos.Y);
         *              SpawnMonster ("ZacBaby", pos.X, pos.Y - 2);
         *      }
         */
    }
Exemplo n.º 23
0
        public override void Move(int registerOffset)
        {
            if (Robot == null)
            {
                return;
            }

            Debug.WriteLine(this + " move");

            var newConveyorBeltTile = Game.MoveRobot(Robot, Direction) as ConveyorBeltTile;

            if (newConveyorBeltTile == null)
            {
                return;
            }

            var rotationDirection = DirectionHelper.GetRotationDirection(Direction, newConveyorBeltTile.Direction);

            Game.RotateRobot(newConveyorBeltTile.Robot, rotationDirection);
        }
Exemplo n.º 24
0
    private Wall GetWall(PositionModel position, DirectionEnum direction)
    {
        var nextPosition     = PositionHelper.GetNextPosition(position.Row, position.Column, direction);
        var reverseDirection = DirectionHelper.GetReverseDirection(direction);

        return(_wallsFilter
               .ToEntitiesList()
               .FirstOrDefault(e =>
                               (
                                   e.Row == position.Row &&
                                   e.Column == position.Column &&
                                   e.Direction == direction
                               ) ||
                               (
                                   e.Row == nextPosition.Row &&
                                   e.Column == nextPosition.Column &&
                                   e.Direction == reverseDirection
                               )
                               ));
    }
        public MapBuilder MoveInDirection(Direction direction)
        {
            var node = GenerateMapSegmentNode(
                nodes.Count,
                origin,
                DirectionHelper.GetOppositeDirection(previousDirection),
                direction);

            var offset   = DirectionHelper.GetDirectionalOffset(direction);
            var newPoint = new Point(
                origin.X + offset.X,
                origin.Y + offset.Y);

            origin            = newPoint;
            previousDirection = direction;

            nodes.Add(node);

            return(this);
        }
        public void IsPointInDirectionOfSensorLineWorks()
        {
            Assert.IsTrue(DirectionHelper
                          .IsPointInDirectionOfSensorLine(
                              new Line()
            {
                Start = new Point(-1, -1),
                End   = new Point(1, 1)
            },
                              new Point(0.5m, 0.5m)));

            Assert.IsTrue(DirectionHelper
                          .IsPointInDirectionOfSensorLine(
                              new Line()
            {
                Start = new Point(0, 0),
                End   = new Point(0.1m, 0.1m)
            },
                              new Point(0.5m, 0.5m)));
        }
Exemplo n.º 27
0
        public bool Move(Direction direction, bool closePrev = false)
        {
            //Sadly AoC uses different int values than I do
            int dirCode = 4;

            if (direction == Direction.North)
            {
                dirCode = 1;
            }
            if (direction == Direction.South)
            {
                dirCode = 2;
            }
            if (direction == Direction.West)
            {
                dirCode = 3;
            }

            int response = (int)brain.Run(new List <BigInteger> {
                dirCode
            })[0];

            if (response > 0)
            {
                if (mentalMap[X, Y] == "D")
                {
                    SetMapTiles(X, Y, closePrev ? "#" : " ");
                }
                (X, Y) = DirectionHelper.NeighbourInDirection(direction, X, Y);

                Finished = response == 2;
                SetMapTiles(X, Y, Finished ? "O" : "D");
                return(true);
            }
            else
            {
                var(mentalX, mentalY) = DirectionHelper.NeighbourInDirection(direction, X, Y);
                SetMapTiles(mentalX, mentalY, "\u2588");
                return(false);
            }
        }
Exemplo n.º 28
0
        private void DrawSegment(SpriteBatch spriteBatch, ISnakeSegment segment)
        {
            var selectedTexture = SelectTexture(segment);

            var rotation = DirectionHelper.GetRotation(segment.Direction);
            var origin   = new Vector2(selectedTexture.Bounds.Width / 2f, selectedTexture.Bounds.Height / 2f);

            var scale = CalculateScale(segment, selectedTexture);

            spriteBatch.Draw(
                texture: selectedTexture.Texture,
                position: segment.Position,
                sourceRectangle: selectedTexture.Bounds,
                color: Color.White,
                rotation: rotation,
                scale: scale,
                origin: origin,
                effects: SpriteEffects.None,
                layerDepth: LayerDepths.Snake
                );
        }
Exemplo n.º 29
0
        public void TestNeighbourInDirection()
        {
            var(x, y) = (0, 0);
            var north     = DirectionHelper.NeighbourInDirection(Direction.North, x, y);
            var northEast = DirectionHelper.NeighbourInDirection(Direction.NorthEast, x, y);
            var east      = DirectionHelper.NeighbourInDirection(Direction.East, x, y);
            var southEast = DirectionHelper.NeighbourInDirection(Direction.SouthEast, x, y);
            var south     = DirectionHelper.NeighbourInDirection(Direction.South, x, y);
            var southWest = DirectionHelper.NeighbourInDirection(Direction.SouthWest, x, y);
            var west      = DirectionHelper.NeighbourInDirection(Direction.West, x, y);
            var northWest = DirectionHelper.NeighbourInDirection(Direction.NorthWest, x, y);

            Assert.AreEqual((x, y + 1), north);
            Assert.AreEqual((x + 1, y + 1), northEast);
            Assert.AreEqual((x + 1, y), east);
            Assert.AreEqual((x + 1, y - 1), southEast);
            Assert.AreEqual((x, y - 1), south);
            Assert.AreEqual((x - 1, y - 1), southWest);
            Assert.AreEqual((x - 1, y), west);
            Assert.AreEqual((x - 1, y + 1), northWest);
        }
Exemplo n.º 30
0
        public void Execute(Puzzle puzzle, int arg)
        {
            Point oldPosition = puzzle.Player.Position;
            Point newPosition = DirectionHelper.ShiftPoint(oldPosition, arg);

            bool moved = false;

            if (puzzle.Timelines[puzzle.Player.Timeline].IsWalkableOrPushable(newPosition))
            {
                Element pushable = puzzle.Timelines[puzzle.Player.Timeline].GetPushable(newPosition);

                if (pushable != null)
                {
                    if (puzzle.Timelines[puzzle.Player.Timeline].IsUnwalkableOrPushable(DirectionHelper.ShiftPoint(newPosition, arg)))
                    {
                        moved = false;
                    }
                    else
                    {
                        Pushed = pushable;
                        DirectionHelper.ShiftPoint(ref pushable.Position, arg);
                        moved = true;
                    }
                }
                else
                {
                    moved = true;
                }
            }

            if (moved)
            {
                PlayerMovement         = DirectionHelper.ToPoint(arg);
                puzzle.Player.Position = newPosition;
            }
            else
            {
                PlayerMovement = Point.Zero;
            }
        }