Game Development Reference
In-Depth Information
KeyDown() can focus on changing the _sidePressed to trigger the right move-
ment.
The goal of the KeyDown() method is to interpret the provided key code and de-
termine if the right buttons have been clicked on, to perform a single action. For our
game we want to offer the player the choice of using any of the cursor keys to control
the ship, depending on what feels right for them. For that reason, we use the pass-
through characteristic of case statements to allow us to perform the same action for
multiple cases.
Here we're using the up and left cursor keys to move towards the top of the
screen, and the down and right keys to move towards the bottom. The Win-
dows::System::VirtualKey enumeration provides us with readable names for
all of the available keys, making it easy to support what you need. One benefit of the
VirtualKey is that it can be represented as an integer, making it easy to serialize
for custom configurations.
There are many keys on the keyboard, and the VirtualKey even includes some
mouse buttons and other commands to help reduce the amount of special code you
need to support what are really just more buttons. The Microsoft Developer Network
(MSDN) has a complete list of virtual key codes at
http://msdn.microsoft.com/en-au/library/windows/apps/windows.system.virtualkey
There's really only one input method left to cover all of the common gaming situ-
ations that Windows accommodates, and that is the GamePad.
Search WWH ::




Custom Search