Games: Snake: Fixes snake head collision with fruit
CheckCollisionRecs() returns true on edge-collision what means that the snake eats the fruit when colliding with it but also when sliding by one unit above or below the fruit.
This commit is contained in:
parent
b4c02d94a0
commit
ab7acd6e34
1 changed files with 2 additions and 2 deletions
|
@ -220,8 +220,8 @@ void UpdateGame(void)
|
|||
}
|
||||
|
||||
// collision
|
||||
if (CheckCollisionRecs((Rectangle){(int)snake[0].position.x, (int)snake[0].position.y, (int)snake[0].size.x, (int)snake[0].size.y},
|
||||
(Rectangle){(int)fruit.position.x, (int)fruit.position.y, (int)fruit.size.x, (int)fruit.size.y}))
|
||||
if ((snake[0].position.x < (fruit.position.x + fruit.size.x) && (snake[0].position.x + snake[0].size.x) > fruit.position.x) &&
|
||||
(snake[0].position.y < (fruit.position.y + fruit.size.y) && (snake[0].position.y + snake[0].size.y) > fruit.position.y))
|
||||
{
|
||||
snake[counterTail].position = snakePosition[counterTail - 1];
|
||||
counterTail += 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue