Example #1
0
        static public IEnumerator MouseAsJoystick(GameController gameController, float desiredAngle)
        {
            var gameWindowRect = gameController.Window.GetWindowRectangle();
            var centerOfScreen = gameController.Game.IngameState.Camera.WorldToScreen(gameController.Player.Pos);

            float mouseDistance = 0.2f * gameWindowRect.Height;
            float xPos          = mouseDistance * (float)Math.Cos(desiredAngle * Math.PI / 180);
            float yPos          = -mouseDistance * (float)Math.Sin(desiredAngle * Math.PI / 180);

            Vector2 mousePositionClient = new Vector2(centerOfScreen.X + xPos,
                                                      centerOfScreen.Y + yPos);
            Vector2 mousePositionToClick = gameWindowRect.TopLeft + mousePositionClient;

            yield return(Input.SetCursorPositionSmooth(mousePositionToClick));
        }