public void HandleInput(PlayerControl playerControl)
        {
            KeyboardState state = Keyboard.GetState();

            playerControl.Thrust = state.IsKeyDown(keyConfig.ThrustKey) ? 1 : 0;
            playerControl.Rotation = state.IsKeyDown(keyConfig.RotateLeft) ? -1 : 0;
            playerControl.Rotation += state.IsKeyDown(keyConfig.RotateRight) ? 1 : 0;

            playerControl.Fire = state.IsKeyDown(keyConfig.Fire);
            playerControl.FireSpecial = state.IsKeyDown(keyConfig.FireSpecial);
        }
        public void HandleInput(PlayerControl playerControl)
        {
            JoystickState state = Joystick.GetState(controlerIndex);

            playerControl.Thrust = Math.Max(0, -GetAnalogValue(state.GetAxis(JoystickState.Axis.R)));
            playerControl.Rotation = GetAnalogValue(state.GetAxis(JoystickState.Axis.X));
            playerControl.Fire = state.GetButton(3);
            playerControl.FireSpecial = state.GetButton(4);
        }
        public static void Initialize()
        {
            int nrOfPlayers = Settings.Current.Players.Length;
            player = new PlayerControl[nrOfPlayers];
            for(int i = 0; i < player.Length; i++)
                player[i] = new PlayerControl();

            playerInput = new IInputControl[nrOfPlayers];

             GamePadState state = GamePad.GetState(PlayerIndex.Two);

            List<IInputControl> inputHandlers = new List<IInputControl>();
            //int count = Joystick.GetJoystickCount();
            //if(count > 0)
            //    inputHandlers.Add(new InputControlJoystick(0));

            DirectX8Class directx = new DirectX8Class();
            DirectInput8 input = directx.DirectInputCreate();
            DirectInputEnumDevices8 gameControllers = input.GetDIDevices(CONST_DI8DEVICETYPE.DI8DEVCLASS_GAMECTRL, CONST_DIENUMDEVICESFLAGS.DIEDFL_ATTACHEDONLY);
            for(int i = 0; i < gameControllers.GetCount(); i++)
            {
                if(inputHandlers.Count >= nrOfPlayers)
                    break;

                DirectInputDeviceInstance8 gameController = gameControllers.GetItem(i + 1);
                inputHandlers.Add(new InputControlJoystick(input, gameController));
            }

            if(inputHandlers.Count < nrOfPlayers)
                inputHandlers.Add(new InputControlKeyboard(InputControlKeyboard.KeyConfig.Player1));
            if(inputHandlers.Count < nrOfPlayers)
                inputHandlers.Add(new InputControlKeyboard(InputControlKeyboard.KeyConfig.Player2));

            playerInput = inputHandlers.ToArray();
        }
        public void HandleInput(PlayerControl playerControl)
        {
            GamePadState padState = GamePad.GetState(PlayerIndex.One);
            if(!padState.IsConnected)
                return;

            playerControl.Rotation = padState.ThumbSticks.Left.X;
            playerControl.Thrust = Math.Max(0, padState.ThumbSticks.Right.Y);

            if(padState.Buttons.LeftShoulder == ButtonState.Pressed)
                playerControl.Rotation = -1;
            if(padState.Buttons.RightShoulder == ButtonState.Pressed)
                playerControl.Rotation = 1;
            if(padState.Buttons.Back == ButtonState.Pressed)
                playerControl.Thrust = 1;

            playerControl.Fire        = padState.Buttons.A == ButtonState.Pressed;
            playerControl.FireSpecial = padState.Buttons.B == ButtonState.Pressed;
        }
        public static void Initialize()
        {
            int nrOfPlayers = Settings.Current.Players.Length;
            player = new PlayerControl[nrOfPlayers];
            for(int i = 0; i < player.Length; i++)
                player[i] = new PlayerControl();

            playerInput = new IInputControl[nrOfPlayers];

            List<IInputControl> inputHandlers = new List<IInputControl>();
            // TODO (san): First try to get controllers..

            // Default back to keyboard controls
            if(inputHandlers.Count < nrOfPlayers)
                inputHandlers.Add(new InputControlKeyboard(InputControlKeyboard.KeyConfig.Player1));
            if(inputHandlers.Count < nrOfPlayers)
                inputHandlers.Add(new InputControlKeyboard(InputControlKeyboard.KeyConfig.Player2));

            playerInput = inputHandlers.ToArray();
        }
        public void HandleController(PlayerControl control, double dt)
        {
            OldPosition = Position;

            if(!prevFire && control.Fire)
            {
                SoundHandler.Fire();
            }
            prevFire = control.Fire;

            //double g = TestSettings.Value1; // 50
            //double z = TestSettings.Value2; // 0.7
            //double t = TestSettings.Value3; // 200
            double g = 80;
            double z = 0.7;
            double t = 250;

            Rotation.Z += (float)(-control.Rotation * dt * 7);
            Rotation.Y = control.Rotation * 3.14f /2f;
            double  gc, vzg;
            gc = t * Math.Sin(-Rotation.Z) * control.Thrust;
            vzg = Speed.X*z-gc;
            Position.X += (float)((gc*dt+(vzg-vzg*Math.Exp(-z*dt))/z)/z);
            Speed.X = (float)(gc/z+Math.Exp(-z*dt)*vzg/z);

            gc = -g + t * Math.Cos( Rotation.Z) * control.Thrust;
            vzg = Speed.Y*z-gc;
            Position.Y += (float)((gc*dt+(vzg-vzg*Math.Exp(-z*dt))/z)/z);
            Speed.Y = (float)(gc/z+Math.Exp(-z*dt)*vzg/z);
        }