本文整理汇总了C++中Snake::EatedItself方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::EatedItself方法的具体用法?C++ Snake::EatedItself怎么用?C++ Snake::EatedItself使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Snake
的用法示例。
在下文中一共展示了Snake::EatedItself方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start_game
//.........这里部分代码省略.........
draw = true;
gameState = PauseGame;
break;
}
}
break;
}
if (events.type == ALLEGRO_EVENT_TIMER)
{
if (events.timer.source == timer)
{
draw = true;
/* navigation keys */
if (al_key_down(&keystate, ALLEGRO_KEY_DOWN) || al_key_down(&keystate, ALLEGRO_KEY_S))
{
new_direction = DOWN;
}
else if (al_key_down(&keystate, ALLEGRO_KEY_UP) || al_key_down(&keystate, ALLEGRO_KEY_W))
{
new_direction = UP;
}
else if (al_key_down(&keystate, ALLEGRO_KEY_RIGHT) || al_key_down(&keystate, ALLEGRO_KEY_D))
{
new_direction = RIGHT;
}
else if (al_key_down(&keystate, ALLEGRO_KEY_LEFT) || al_key_down(&keystate, ALLEGRO_KEY_A))
{
new_direction = LEFT;
}
/* checking boundaries */
if (!snake.IsInScreenBoundaries() || snake.EatedItself())
{
draw = true;
al_play_sample(game_over_sound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);
gameState = GameOver;
break;
}
}
else if (events.timer.source == frametimer)
{
/* moving snake */
snake.SetSnakeDirection(new_direction);
snake.MoveSnake();
if (snake.EatedApple(apple.GetAppleX(), apple.GetAppleY()))
{
al_play_sample(eating_apple_sound, 0.5, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, 0);
apple.NewApple(snake.GetSnakeCells());
snake.IncreaseSnakeLength();
draw = true;
}
}
}
/* ------------ NOW DRAWING ------------ */
if (draw)
{
/* game frame */
if (Fullscreen)
{
al_draw_rectangle(0, 0, CurrentScreenWidth, CurrentScreenHeight, DarkRed, 20);
//al_draw_rectangle(0, 0, 1360, 760, DarkRed, 20);
}
else