Game Development Reference
In-Depth Information
class KeyTrigger :
public Trigger
{
private:
Windows::System::VirtualKey _key;
KeyState _state;
KeyState _expectedState;
public:
KeyTrigger() :
_key(Windows::System::VirtualKey::None),
_expectedState(KeyState::Released) {};
virtual bool IsTriggered(InputManager *input);
void SetData(Windows::System::VirtualKey key,
KeyState state);
};
This class just uses the standard windows VirtualKey enumeration to define the
desired key, and the KeyState enumeration we defined earlier to indicate when to
trigger. In the public block of methods we just define some defaults and implement
the pure virtual method defined in the abstract Trigger base class. Alongside that
we provide a method to set the expected key and when to trigger so that we can
configure this object as required.
For this class, IsTriggered is pretty simple and looks like the following.
bool KeyTrigger::IsTriggered(InputManager
*input)
{
if (input->IsKeyDown(_key))
_state = KeyState::Pressed;
else if (_state == KeyState::Pressed)
_state = KeyState::JustReleased;
else
_state = KeyState::Released;
Search WWH ::




Custom Search