From 3122822b72b2f0330e22e8482fea0a85f582cfa9 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Thu, 25 Jan 2024 10:55:57 +0100 Subject: [PATCH] refactoring: initializing snake --- src/main/c/Snake/snake_start.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index 12fb3d5..68de781 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -6,6 +6,9 @@ #include "snake_start.h" #include "get_character.h" #define TIME_TURN 0.3 +#define START_LENGTH 3 +#define START_DIRECTION 1 +#define START_TILE 8 * 16 + 8 #pragma region Funktion_heads void main_menu(); @@ -63,11 +66,7 @@ void game(){ while (running){ system("clear"); draw(&snake, fruit); - - if(check_if_dead(&snake)){ - break; - } - + if(check_if_dead(&snake)){break;} t = clock() - t; get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake, &running); t = clock(); @@ -77,14 +76,12 @@ void game(){ } Snake initialize_snake(){ - Snake snake = {1, 3}; - for(int i = 0; i < AREA; i++){ - snake.segments[i] = 0; + Snake snake; + snake.direction = START_DIRECTION; + snake.length = START_LENGTH; + for(int i = 0; i < START_LENGTH; i++){ + snake.segments[i] = START_TILE - START_DIRECTION * i; } - snake.segments[0] = 8 + 16 * 8; - snake.segments[1] = 7 + 16 * 8; - snake.segments[2] = 6 + 16 * 8; - return snake; }