From 7bff197db2e87175bd5c181f1e46716351701769 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Mon, 6 Feb 2023 15:36:36 -0800 Subject: fixed obstacle collisions --- snake.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/snake.c b/snake.c index bfd1bf7..c63a2d4 100644 --- a/snake.c +++ b/snake.c @@ -164,16 +164,7 @@ int main(int argc, char **argv) { while(1) { /* handle ctrl-c interrupt */ if(intCtrlC) { -EXIT: - /* unhide cursor */ - printf("\033[?25h"); - /* kill the listener thread */ - *cancellationToken = 1; - printf("Your score was %d. Press any key to exit\n", score); - pthread_join(listenerID, NULL); - free(cancellationToken); - free((int*)lastInput); - return 0; + goto EXIT; } /* first, draw the current state of the board */ @@ -192,7 +183,7 @@ EXIT: } /* check if snake lands on obstacle */ for (int i = 0; i < obstaclePositions.length; i ++) { - if ((snakePositions.vectors[0].mx + lastMoveDir.mx == obstaclePositions.vectors[i].mx) && (snakePositions.vectors[0].my + lastMoveDir.my == obstaclePositions.vectors[i].mx)) { + if ((snakePositions.vectors[0].mx + lastMoveDir.mx == obstaclePositions.vectors[i].mx) && (snakePositions.vectors[0].my + lastMoveDir.my == obstaclePositions.vectors[i].my)) { goto EXIT; } } @@ -240,6 +231,7 @@ EXIT: break; } } +EXIT: /* clear the last getch call from the listener */ *cancellationToken = 1; printf("\n%sYou died. Score: %d. Press any key to exit%s\n", RED, score, COLOR_RESET); -- cgit v1.3.1