Game Development Reference
In-Depth Information
private:
GamepadButtons _button;
KeyState _state;
KeyState _expectedState;
public:
GamepadButtonTrigger() :
_button(GamepadButtons::None),
_expectedState(KeyState::Released) {};
virtual bool IsTriggered(InputManager *input);
void SetData(GamepadButtons button, KeyState
state);
};
The code for this is almost the same as
KeyTrigger
; however, to retrieve the state
of the button from
InputManager
we need to get the
wButtons
word and bitwise-
and it against the expected button to get a Boolean. For more information on this
please refer back to
Chapter 3
,
Adding the Input
.
auto xState = input->GetGamepadState(0);
auto isSet = (xState.Gamepad.wButtons &
(WORD)_button) > 0;
The final trigger we will define is
PointerAxisBoundsTrigger
. This one is a bit of
a mouthful but it essentially lets us define a region of the screen that fires the trigger
if the player presses within.
We'll begin by specifying a new type that provides the
Lower
and
Upper
bounds for
a single axis. We'll use this in the game code to allow the player to press anywhere
within the top or bottom half of the screen and move the ship towards that side.
typedef struct
{
float Lower;
float Upper;