Beispiel #1
0
        public void Move()
        {
            if (!stopMovement)
            {
                double x = player.CanvasPositionX;
                double y = player.CanvasPositionY;

                if (moveLeft && moveUp)
                {
                    if (!collider.IsPathBlocked(player, -5, -5))
                    {
                        x -= MovementSpeed;
                        y -= MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.NorthWest);

                        player.SetCanvasPositionX(x);
                        player.SetCanvasPositionY(y);
                        return;
                    }
                }
                if (moveRight && moveUp)
                {
                    if (!collider.IsPathBlocked(player, 5, -5))
                    {
                        x += MovementSpeed;
                        y -= MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.NorthEast);

                        player.SetCanvasPositionX(x);
                        player.SetCanvasPositionY(y);
                        return;
                    }
                }
                if (moveLeft && moveDown)
                {
                    if (!collider.IsPathBlocked(player, -5, 5))
                    {
                        x -= MovementSpeed;
                        y += MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.SouthWest);

                        player.SetCanvasPositionX(x);
                        player.SetCanvasPositionY(y);
                        return;
                    }
                }
                if (moveRight && moveDown)
                {
                    if (!collider.IsPathBlocked(player, 5, 5))
                    {
                        x += MovementSpeed;
                        y += MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.SouthEast);

                        player.SetCanvasPositionX(x);
                        player.SetCanvasPositionY(y);
                        return;
                    }
                }
                if (moveLeft)
                {
                    if (!collider.IsPathBlocked(player, -5, 0))
                    {
                        x -= MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.West);
                    }
                }
                if (moveRight)
                {
                    if (!collider.IsPathBlocked(player, 5, 0))
                    {
                        x += MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.East);
                    }
                }
                if (moveUp)
                {
                    if (!collider.IsPathBlocked(player, 0, -5))
                    {
                        y -= MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.North);
                    }
                }
                if (moveDown)
                {
                    if (!collider.IsPathBlocked(player, 0, 5))
                    {
                        y += MovementSpeed;

                        player.RectangleBody.LayoutTransform = new RotateTransform((int)CardinalPoint.South);
                    }
                }
                player.SetCanvasPositionX(x);
                player.SetCanvasPositionY(y);
            }
        }