|
@ -11,7 +11,7 @@ |
|
|
void main_menu(); |
|
|
void main_menu(); |
|
|
void game(); |
|
|
void game(); |
|
|
Snake initialize_snake(); |
|
|
Snake initialize_snake(); |
|
|
void get_next_move(double limit, Snake *snake); |
|
|
|
|
|
|
|
|
void get_next_move(double limit, Snake *snake, bool *running); |
|
|
void move_snake(Snake *snake); |
|
|
void move_snake(Snake *snake); |
|
|
void draw(Snake *snake); |
|
|
void draw(Snake *snake); |
|
|
int part_of_snake(Snake *snake, unsigned char tile); |
|
|
int part_of_snake(Snake *snake, unsigned char tile); |
|
@ -56,25 +56,19 @@ void game(){ |
|
|
bool running = true; |
|
|
bool running = true; |
|
|
clock_t t = clock(); |
|
|
clock_t t = clock(); |
|
|
|
|
|
|
|
|
//while (running){ |
|
|
|
|
|
for(int i = 0; i < 100; i++){ |
|
|
|
|
|
|
|
|
while (running){ |
|
|
system("clear"); |
|
|
system("clear"); |
|
|
draw(&snake); |
|
|
draw(&snake); |
|
|
|
|
|
|
|
|
t = clock() - t; |
|
|
t = clock() - t; |
|
|
get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake); |
|
|
|
|
|
|
|
|
get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake, &running); |
|
|
t = clock(); |
|
|
t = clock(); |
|
|
move_snake(&snake); |
|
|
move_snake(&snake); |
|
|
|
|
|
|
|
|
running = false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
getchar(); |
|
|
|
|
|
getchar(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Snake initialize_snake(){ |
|
|
Snake initialize_snake(){ |
|
|
Snake snake = {{0, 1}, 3}; |
|
|
|
|
|
|
|
|
Snake snake = {{1, 0}, 3}; |
|
|
for(int i = 0; i < AREA; i++){ |
|
|
for(int i = 0; i < AREA; i++){ |
|
|
snake.segments[i] = 0; |
|
|
snake.segments[i] = 0; |
|
|
} |
|
|
} |
|
@ -82,12 +76,10 @@ Snake initialize_snake(){ |
|
|
snake.segments[1] = 7 + 16 * 8; |
|
|
snake.segments[1] = 7 + 16 * 8; |
|
|
snake.segments[2] = 6 + 16 * 8; |
|
|
snake.segments[2] = 6 + 16 * 8; |
|
|
|
|
|
|
|
|
snake.direction[0] = 1; |
|
|
|
|
|
snake.direction[1] = 0; |
|
|
|
|
|
return snake; |
|
|
return snake; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void get_next_move(double limit, Snake *snake){ |
|
|
|
|
|
|
|
|
void get_next_move(double limit, Snake *snake, bool *running){ |
|
|
char c; |
|
|
char c; |
|
|
|
|
|
|
|
|
c = get_character(limit); |
|
|
c = get_character(limit); |
|
@ -113,6 +105,8 @@ void get_next_move(double limit, Snake *snake){ |
|
|
snake->direction[0] = 1; |
|
|
snake->direction[0] = 1; |
|
|
snake->direction[1] = 0; |
|
|
snake->direction[1] = 0; |
|
|
break; |
|
|
break; |
|
|
|
|
|
case 'q': |
|
|
|
|
|
*running = false; |
|
|
|
|
|
|
|
|
default: |
|
|
default: |
|
|
break; |
|
|
break; |
|
@ -120,7 +114,10 @@ void get_next_move(double limit, Snake *snake){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void move_snake(Snake *snake){ |
|
|
void move_snake(Snake *snake){ |
|
|
|
|
|
|
|
|
|
|
|
for(int i = snake->length - 1; i > 0; i--){ |
|
|
|
|
|
snake->segments[i] = snake->segments[i - 1]; |
|
|
|
|
|
} |
|
|
|
|
|
snake->segments[0] += snake->direction[0] + snake->direction[1] * 16; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void draw(Snake *snake){ |
|
|
void draw(Snake *snake){ |
|
|