/// <summary> /// Handles Lets Go Island controls. /// </summary> /// <param name="playerButtons"></param> /// <param name="playerNumber"></param> private void HandleLgiControls(PlayerButtons playerButtons, int playerNumber) { while (true) { if (KillMe) { return; } if (playerNumber == 1) { if (playerButtons.UpPressed()) { if (InputCode.AnalogBytes[0] <= 0xE0) { InputCode.AnalogBytes[0] += _player1GunMultiplier; } } if (playerButtons.DownPressed()) { if (InputCode.AnalogBytes[0] >= 10) { InputCode.AnalogBytes[0] -= _player1GunMultiplier; } } if (playerButtons.RightPressed()) { if (InputCode.AnalogBytes[2] >= 10) { InputCode.AnalogBytes[2] -= _player1GunMultiplier; } } if (playerButtons.LeftPressed()) { if (InputCode.AnalogBytes[2] <= 0xE0) { InputCode.AnalogBytes[2] += _player1GunMultiplier; } } } if (playerNumber == 2) { if (playerButtons.UpPressed()) { if (InputCode.AnalogBytes[4] <= 0xE0) { InputCode.AnalogBytes[4] += _player2GunMultiplier; } } if (playerButtons.DownPressed()) { if (InputCode.AnalogBytes[4] >= 10) { InputCode.AnalogBytes[4] -= _player2GunMultiplier; } } if (playerButtons.RightPressed()) { if (InputCode.AnalogBytes[6] >= 10) { InputCode.AnalogBytes[6] -= _player2GunMultiplier; } } if (playerButtons.LeftPressed()) { if (InputCode.AnalogBytes[6] <= 0xE0) { InputCode.AnalogBytes[6] += _player2GunMultiplier; } } } Thread.Sleep(10); } }
/// <summary> /// Get directional press from button, POV and analog. /// </summary> /// <param name="playerButtons"></param> /// <param name="button"></param> /// <param name="state"></param> /// <param name="direction"></param> private static void GetDirectionPress(PlayerButtons playerButtons, XInputButton button, State state, Direction direction) { if (button == null) { return; } // Analog Axis, we expect that the both direction are on same axis!!!! if (button.IsLeftThumbX || button.IsLeftThumbY || button.IsRightThumbX || button.IsRightThumbY) { var calcVal = 0; if (button.IsLeftThumbY) { calcVal = state.Gamepad.LeftThumbY; } if (button.IsLeftThumbX) { calcVal = state.Gamepad.LeftThumbX; } if (button.IsRightThumbX) { calcVal = state.Gamepad.RightThumbX; } if (button.IsRightThumbY) { calcVal = state.Gamepad.RightThumbY; } if (button.IsAxisMinus) { if (calcVal >= 0 + 15000) { } else if (calcVal <= 0 - 15000) { InputCode.SetPlayerDirection(playerButtons, direction); } else { if (direction == Direction.Left || direction == Direction.Right) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Up || direction == Direction.Down) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } } } else { if (calcVal >= 0 + 15000) { InputCode.SetPlayerDirection(playerButtons, direction); } else if (calcVal <= 0 - 15000) { } else { if (direction == Direction.Left || direction == Direction.Right) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Up || direction == Direction.Down) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } } } } // Normal button if (button.IsButton) { if ((button.ButtonCode & (short)state.Gamepad.Buttons) != 0) { InputCode.SetPlayerDirection(playerButtons, direction); } else { if (direction == Direction.Left && !playerButtons.RightPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Right && !playerButtons.LeftPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Up && !playerButtons.DownPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } if (direction == Direction.Down && !playerButtons.UpPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } } } }
/// <summary> /// Get directional press from button, POV and analog. /// </summary> /// <param name="playerButtons"></param> /// <param name="button"></param> /// <param name="state"></param> /// <param name="direction"></param> private static void GetDirectionPress(PlayerButtons playerButtons, JoystickButton button, JoystickUpdate state, Direction direction) { if (button == null) { return; } if ((JoystickOffset)button.Button != state.Offset) { return; } // POV if (button.Button >= 32 && button.Button <= 44) { switch (state.Value) { case -1: InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); break; case 0: InputCode.SetPlayerDirection(playerButtons, Direction.Up); break; case 4500: InputCode.SetPlayerDirection(playerButtons, Direction.Up); InputCode.SetPlayerDirection(playerButtons, Direction.Right); break; case 9000: InputCode.SetPlayerDirection(playerButtons, Direction.Right); break; case 13500: InputCode.SetPlayerDirection(playerButtons, Direction.Down); InputCode.SetPlayerDirection(playerButtons, Direction.Right); break; case 18000: InputCode.SetPlayerDirection(playerButtons, Direction.Down); break; case 22500: InputCode.SetPlayerDirection(playerButtons, Direction.Left); InputCode.SetPlayerDirection(playerButtons, Direction.Down); break; case 27000: InputCode.SetPlayerDirection(playerButtons, Direction.Left); break; case 31500: InputCode.SetPlayerDirection(playerButtons, Direction.Left); InputCode.SetPlayerDirection(playerButtons, Direction.Up); break; } } // Analog Axis, we expect that the both direction are on same axis!!!! if (state.Offset == JoystickOffset.X || state.Offset == JoystickOffset.Y || state.Offset == JoystickOffset.Z || state.Offset == JoystickOffset.RotationX || state.Offset == JoystickOffset.RotationY || state.Offset == JoystickOffset.RotationZ || state.Offset == JoystickOffset.Sliders0 || state.Offset == JoystickOffset.Sliders1 || state.Offset == JoystickOffset.AccelerationX || state.Offset == JoystickOffset.AccelerationY || state.Offset == JoystickOffset.AccelerationZ) { if (button.IsAxisMinus) { if (state.Value >= 32064 + 15000) { } else if (state.Value <= 32064 - 15000) { InputCode.SetPlayerDirection(playerButtons, direction); } else { if (direction == Direction.Left || direction == Direction.Right) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Up || direction == Direction.Down) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } } } else { if (state.Value >= 32064 + 15000) { InputCode.SetPlayerDirection(playerButtons, direction); } else if (state.Value <= 32064 - 15000) { } else { if (direction == Direction.Left || direction == Direction.Right) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Up || direction == Direction.Down) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } } } } // Normal button if (button.Button >= 48 && button.Button <= 175) { if (state.Value != 0) { InputCode.SetPlayerDirection(playerButtons, direction); } else { if (direction == Direction.Left && !playerButtons.RightPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Right && !playerButtons.LeftPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.HorizontalCenter); } if (direction == Direction.Up && !playerButtons.DownPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } if (direction == Direction.Down && !playerButtons.UpPressed()) { InputCode.SetPlayerDirection(playerButtons, Direction.VerticalCenter); } } } }