本文整理汇总了C++中CInput::GetKeyCode方法的典型用法代码示例。如果您正苦于以下问题:C++ CInput::GetKeyCode方法的具体用法?C++ CInput::GetKeyCode怎么用?C++ CInput::GetKeyCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CInput
的用法示例。
在下文中一共展示了CInput::GetKeyCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleGameInput
void HandleGameInput()
{
// This is not a function in our CInput class. We wanted the CInput class
// to be generic and not actually handle our game code, but just tell us what
// the user did. We can then make different function to handle the input
// for a given situation. We do this for character movement, save\load prompts,
// menus, etc...
// Let's get the key that the user pressed
int keyCode = g_Input.GetKeyCode();
// If we just hit a key from the keyboard, handle the input accordingly.
if(g_Input.IsKeyboardEvent() && g_Input.IsKeyDown())
{
if(keyCode == VK_ESCAPE) // If escape was pressed
exit(0); // Quit the game
else if(keyCode == VK_UP) // If up arrow key was pressed
g_Player.Move(kUp); // Move the character up
else if(keyCode == VK_DOWN) // If down arrow key was pressed
g_Player.Move(kDown); // Move the character down
else if(keyCode == VK_LEFT) // If left arrow key was pressed
g_Player.Move(kLeft); // Move the character left
else if(keyCode == VK_RIGHT) // If right arrow key was pressed
g_Player.Move(kRight); // Move the character right
// If the key pressed was for character movement, let's check for special tiles
if(keyCode == VK_RIGHT || keyCode == VK_LEFT || keyCode == VK_UP || keyCode == VK_DOWN)
{
// Here we check if the character stepped on an exit, if so .... exit.
g_Map.CheckForExit(g_Player.GetPosition().X, g_Player.GetPosition().Y);
// We want to draw the screen again if the character moved
g_Map.SetDrawFlag(true);
}
}
}