Browse Source

refactoring: initializing snake

remotes/origin/David
David Moeller 11 months ago
parent
commit
3122822b72
  1. 21
      src/main/c/Snake/snake_start.c

21
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;
}

Loading…
Cancel
Save