Updated: fix traling SNAKE_BODY char on board
This commit is contained in:
parent
2cbeea0de9
commit
6c88b3c89b
2 changed files with 5 additions and 1 deletions
BIN
serpent
BIN
serpent
Binary file not shown.
|
@ -296,6 +296,8 @@ void moveSnake(board_t *board) {
|
||||||
if ((ABS(snake->dX) > 0) || (ABS(snake->dY) > 0)) {
|
if ((ABS(snake->dX) > 0) || (ABS(snake->dY) > 0)) {
|
||||||
int new_head_x = snake->head->pX + snake->dX;
|
int new_head_x = snake->head->pX + snake->dX;
|
||||||
int new_head_y = snake->head->pY + snake->dY;
|
int new_head_y = snake->head->pY + snake->dY;
|
||||||
|
int new_tail_x = snake->tail->pX + snake->dX;
|
||||||
|
int new_tail_y = snake->tail->pY + snake->dY;
|
||||||
|
|
||||||
if (!appleOccupies(new_head_x, new_head_y)) {
|
if (!appleOccupies(new_head_x, new_head_y)) {
|
||||||
// Move the tail to the new position
|
// Move the tail to the new position
|
||||||
|
@ -327,8 +329,10 @@ void moveSnake(board_t *board) {
|
||||||
snake->head->prev = new_head;
|
snake->head->prev = new_head;
|
||||||
snake->head = new_head;
|
snake->head = new_head;
|
||||||
|
|
||||||
// Append a new node to the snake
|
// Append a new node to the snake's tail
|
||||||
appendSnakeNode(snake);
|
appendSnakeNode(snake);
|
||||||
|
snake->tail->pX = new_tail_x;
|
||||||
|
snake->tail->pY = new_tail_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for collisions and update the snake
|
// Check for collisions and update the snake
|
||||||
|
|
Loading…
Reference in a new issue