当前位置: 首页>>代码示例>>C++>>正文


C++ CInput::GetKeyCode方法代码示例

本文整理汇总了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);
		}
	}
}
开发者ID:88er,项目名称:tutorials,代码行数:36,代码来源:Main.cpp


注:本文中的CInput::GetKeyCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。