本文整理汇总了C++中Snake::SetDirection方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::SetDirection方法的具体用法?C++ Snake::SetDirection怎么用?C++ Snake::SetDirection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snake
的用法示例。
在下文中一共展示了Snake::SetDirection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleInput
void Game::HandleInput() {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)
&& _snake.GetPhysicalDirection() != Direction::Down) {
_snake.SetDirection(Direction::Up);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)
&& _snake.GetPhysicalDirection() != Direction::Up) {
_snake.SetDirection(Direction::Down);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)
&& _snake.GetPhysicalDirection() != Direction::Right) {
_snake.SetDirection(Direction::Left);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)
&& _snake.GetPhysicalDirection() != Direction::Left) {
_snake.SetDirection(Direction::Right);
}
}
示例2: WndProc
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE:
hdc = GetDC(hWnd);
SetMapMode(hdc, MM_LOMETRIC);
POINT p[1];
p[0].x = 1000;
p[0].y = -1000;
LPtoDP(hdc, p, 1);
DeleteDC(hdc);
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, p[0].x + 10, p[0].y + 52, NULL); //Padding na ramkê
SetTimer(hWnd, TIMER, 25, (TIMERPROC)NULL);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
SetMapMode(hdc, MM_LOMETRIC); //ustaw gruboϾ na 0,1 mm
SelectObject(hdc, hPen); //wybierz utworzone pióro
snake.Draw(hdc);
EndPaint(hWnd, &ps);
break;
case WM_USER:
DeleteObject(hPen); //usuñ pióro
PostQuitMessage(0);
break;
case WM_TIMER:
snake.Move(); //wykonaj ruch wê¿em
RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_NOCHILDREN); //i odœwie¿ okno
break;
case WM_DESTROY:
DeleteObject(hPen); //usuñ pióro
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_LEFT:
snake.Turn(LEFT);
break;
case VK_RIGHT:
snake.Turn(RIGHT);
break;
case VK_DOWN:
PostMessage(HWND_BROADCAST, GORIGHT, 0, 0);
break;
default:
break;
}
break;
default:
break;
}
if(message == GOLEFT)
{
snake.Add(wParam);
snake.SetDirection(LEFT);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}