diff --git a/include/input.h b/include/input.h index 6815f3a..70bd425 100644 --- a/include/input.h +++ b/include/input.h @@ -9,6 +9,6 @@ typedef struct input_args_t bool *alive; } InputArgs; -void input(void *vargp); +void *input(void *vargp); #endif /* __INPUT_H__ */ diff --git a/src/input.c b/src/input.c index eb13829..05b411a 100644 --- a/src/input.c +++ b/src/input.c @@ -1,5 +1,6 @@ #include "input.h" #include +#include #include #include @@ -21,7 +22,7 @@ char getch(void) return buf; } -void input(void *vargp) +void *input(void *vargp) { char *out = ((InputArgs *)vargp)->out; bool *alive = ((InputArgs *)vargp)->alive; @@ -30,4 +31,5 @@ void input(void *vargp) { *out = getch(); } + return NULL; } diff --git a/src/main.c b/src/main.c index 871aeb6..c276096 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,34 @@ +#include +#include +#include +#include +#include + +#include "input.h" #include "screen.h" +#include "player.h" + +void drawPlayer(Player *player, Screen *screen) +{ + PlayerNode *node; + for (node = player->tail; node != NULL; node = node->next) + *screenGetPoint(screen, node->x, node->y) = '#'; +} int main(int argc, char **argv) { - Screen *screen = screenCreate(5, 5, '#'); - screenShow(screen); + Player *player = playerCreate(DOWN, 0, 0, 0); + Screen *screen = screenCreate(10, 10, ' '); + pthread_t input_thread; + + bool *running = malloc(sizeof(bool)); *running = true; + char *key = malloc(sizeof(char)); *key = 0; + InputArgs input_args = (InputArgs){ key, running }; + + pthread_create(&input_thread, NULL, input, &input_args); + while (*running) + { + if (*key == 'q') *running = false; + } return 0; } diff --git a/src/player.c b/src/player.c index 2e66033..9be05d5 100644 --- a/src/player.c +++ b/src/player.c @@ -54,5 +54,8 @@ void playerDoTick(Player *player, bool food_collision) PlayerNode *new_tail = player->tail->next; free(player->tail); player->tail = new_tail; + } else + { + ++player->score; } }