|
|
@ -77,7 +77,7 @@ void game(){ |
|
|
|
} |
|
|
|
|
|
|
|
Snake initialize_snake(){ |
|
|
|
Snake snake = {{1, 0}, 3}; |
|
|
|
Snake snake = {1, 3}; |
|
|
|
for(int i = 0; i < AREA; i++){ |
|
|
|
snake.segments[i] = 0; |
|
|
|
} |
|
|
@ -96,23 +96,19 @@ void get_next_move(double limit, Snake *snake, bool *running){ |
|
|
|
switch (c){ |
|
|
|
case 'w': |
|
|
|
case 'A': |
|
|
|
snake->direction[0] = 0; |
|
|
|
snake->direction[1] = -1; |
|
|
|
snake->direction = -16; |
|
|
|
break; |
|
|
|
case 'a': |
|
|
|
case 'D': |
|
|
|
snake->direction[0] = -1; |
|
|
|
snake->direction[1] = 0; |
|
|
|
snake->direction = -1; |
|
|
|
break; |
|
|
|
case 's': |
|
|
|
case 'B': |
|
|
|
snake->direction[0] = 0; |
|
|
|
snake->direction[1] = 1; |
|
|
|
snake->direction = 16; |
|
|
|
break; |
|
|
|
case 'd': |
|
|
|
case 'C': |
|
|
|
snake->direction[0] = 1; |
|
|
|
snake->direction[1] = 0; |
|
|
|
snake->direction = 1; |
|
|
|
break; |
|
|
|
case 'q': |
|
|
|
*running = false; |
|
|
@ -126,7 +122,7 @@ 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; |
|
|
|
snake->segments[0] += snake->direction; |
|
|
|
} |
|
|
|
|
|
|
|
void draw(Snake *snake, unsigned char fruit){ |
|
|
|