Fixed self-collision detection

This commit is contained in:
Valentino Orlandi 2022-11-13 01:43:57 +01:00
parent df72851b91
commit 6bc706d188
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
1 changed files with 5 additions and 2 deletions

View File

@ -589,8 +589,11 @@ void Snake::checkCollision()
} else if ( this->snakeInTile( x, y ) ) {
// collision with another part of the snake
this->game_over = true;
this->game_over_msg = Snake::tr("You ate yourself!");
if ( this->snake.back().x != x || this->snake.back().y != y ) {
// not the tail
this->game_over = true;
this->game_over_msg = Snake::tr("You ate yourself!");
}
} else if ( x == this->food.x && y == this->food.y ) {
// will eat