summaryrefslogtreecommitdiffhomepage
path: root/games/snake.c
diff options
context:
space:
mode:
authorJoseph-Eugene Winzer <[email protected]>2018-08-13 23:58:42 +0200
committerJoseph-Eugene Winzer <[email protected]>2018-08-13 23:58:42 +0200
commitab7acd6e3435b3443c8346ab495f05699a0e9750 (patch)
tree7bbc62e7e15d3fe5b1ded915f95e078974b9963d /games/snake.c
parentb4c02d94a0cfae773f0955e33978aaaba419f0ea (diff)
downloadraylib-ab7acd6e3435b3443c8346ab495f05699a0e9750.tar.gz
raylib-ab7acd6e3435b3443c8346ab495f05699a0e9750.zip
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.
Diffstat (limited to 'games/snake.c')
-rw-r--r--games/snake.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/games/snake.c b/games/snake.c
index a4b2d69f..23d1bd1d 100644
--- a/games/snake.c
+++ b/games/snake.c
@@ -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;