From 46d38f2857e468fdf8dd9853ca2189323cab467b Mon Sep 17 00:00:00 2001 From: David Moeller Date: Thu, 25 Jan 2024 10:16:08 +0100 Subject: [PATCH] Snake gets longer when eating fruit --- src/main/c/Snake/snake_start.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index a56e34c..068eca7 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -5,7 +5,7 @@ #include #include "snake_start.h" #include "get_character.h" -#define TIME_TURN 0.5 +#define TIME_TURN 0.3 void main_menu(); @@ -17,6 +17,7 @@ void draw(Snake *snake, unsigned char fruit); int part_of_snake(Snake *snake, unsigned char tile); bool check_if_dead(Snake *snake); unsigned char spawn_fruit(Snake *snake); +unsigned char eating_fruit(Snake *snake); void snake_start(){ @@ -71,6 +72,7 @@ void game(){ get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake, &running); t = clock(); move_snake(&snake); + if(part_of_snake(&snake, fruit) == 0){fruit = eating_fruit(&snake);} } } @@ -180,4 +182,9 @@ unsigned char spawn_fruit(Snake *snake){ printf("%d\n", r); } return r; +} + +unsigned char eating_fruit(Snake *snake){ + snake->length++; + return spawn_fruit(snake); } \ No newline at end of file