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