diff --git a/deel2.tar.gz b/deel2.tar.gz new file mode 100644 index 0000000..702ab9f Binary files /dev/null and b/deel2.tar.gz differ diff --git a/snake.c b/snake.c index 017ac3f..0c44535 100644 --- a/snake.c +++ b/snake.c @@ -2,6 +2,8 @@ // Created by snapshot112 on 10/15/25. // +#define _POSIX_C_SOURCE 199309 + #include "snake.h" #include @@ -240,8 +242,12 @@ static void update_snake(coordinate new_head, snake_action action) { } static void *snake_move(void *arg) { + struct timespec timer; + timer.tv_sec = 0; + timer.tv_nsec = 250000000L; + while (rooster_vraag_toestand(GRID) == STATE_AAN_HET_SPELEN) { - usleep(250000); + nanosleep(&timer, NULL); pthread_mutex_lock(&MUTEX); coordinate new_head = SNAKE_HEAD; switch (CURRENT_DIRECTION) { @@ -332,17 +338,15 @@ void snake(void) { rooster_zet_toestand(GRID, STATE_AAN_HET_SPELEN); - // Allow turning before you let the snake move. - pthread_create(&user_input, NULL, play_snake, NULL); - while (getch() != ' ') {} // Cleanup the start playing message. mvaddstr(MESSAGE_LOCATION.y, MESSAGE_LOCATION.x, " "); + pthread_create(&user_input, NULL, play_snake, NULL); pthread_create(&game_tick, NULL, snake_move, NULL); - // Cleanup game thread logic. + // Wait until the gamestate is no longer STATE_AAN_HET_SPELEN pthread_join(game_tick, NULL); pthread_join(user_input, NULL); pthread_mutex_destroy(&MUTEX); diff --git a/spel b/spel index f4d050a..5b6dd84 100755 Binary files a/spel and b/spel differ