summaryrefslogtreecommitdiffhomepage
path: root/games
diff options
context:
space:
mode:
authorJoseph-Eugene Winzer <[email protected]>2018-08-13 23:52:18 +0200
committerJoseph-Eugene Winzer <[email protected]>2018-08-13 23:52:18 +0200
commitb4c02d94a0cfae773f0955e33978aaaba419f0ea (patch)
tree3006d311b5fd94378f0a3a3b2e28c9eeff70b6e2 /games
parent34493ed2313f3d249ee914ba77423a4882b2cd38 (diff)
downloadraylib-b4c02d94a0cfae773f0955e33978aaaba419f0ea.tar.gz
raylib-b4c02d94a0cfae773f0955e33978aaaba419f0ea.zip
Games: Snake: Fixes fruit spawn position
If the initial fruit position collides with the snake's body a new position for the fruit is generated but without adding the grid offset.
Diffstat (limited to 'games')
-rw-r--r--games/snake.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/games/snake.c b/games/snake.c
index 40d66da8..a4b2d69f 100644
--- a/games/snake.c
+++ b/games/snake.c
@@ -203,7 +203,7 @@ void UpdateGame(void)
if ((snake[0].position.x == snake[i].position.x) && (snake[0].position.y == snake[i].position.y)) gameOver = true;
}
- // TODO: review logic: fruit.position calculation
+ // fruit.position calculation
if (!fruit.active)
{
fruit.active = true;
@@ -211,11 +211,11 @@ void UpdateGame(void)
for (int i = 0; i < counterTail; i++)
{
- while ((fruit.position.x == snake[i].position.x) && (fruit.position.y == snake[i].position.y))
- {
- fruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE };
- i = 0;
- }
+ while ((fruit.position.x == snake[i].position.x) && (fruit.position.y == snake[i].position.y))
+ {
+ fruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 };
+ i = 0;
+ }
}
}