diff --git a/main.c b/main.c index a67292d..9e5ec9a 100644 --- a/main.c +++ b/main.c @@ -31,6 +31,9 @@ void init_snake(struct event* world, struct state* st){ st->foodx[i] = rand() % w; st->foody[i] = rand() % h; } + // Initial game vector + st->sx = 1; + st->sy = 0; } // Step is called in a loop once in interval. @@ -70,11 +73,15 @@ int world_event(struct event* w,void* game){ } // Called on interval timeout else if (w->type == EVENT_TIMEOUT){ + clear_screen(); // Copy screen size st->width = w->width; st->height = w->height; // Change game state int r = step_state(st); + char ms[200]; + sprintf(ms,"r %d\n",r); + set_message(ms,9,9); // Draw snake struct snake* sn = st->snake; while (sn != NULL){ @@ -90,9 +97,7 @@ int world_event(struct event* w,void* game){ // Stop the game if (r){ char message[] = "Koniec"; - for (int i = 0; i < 6; i++){ - set_cell(message[i],10+i,10); - } + set_message(message,10,10); } } return 0; diff --git a/world.h b/world.h index 73be057..e7a3fdb 100644 --- a/world.h +++ b/world.h @@ -104,10 +104,19 @@ void set_color_cell(int character,int x,int y,short front_color,short back_color */ int start_world(void* (*init_game)(),int (*world_event)(struct event* event,void* game),void (*destroy_game)(void* game)); - +/** + * Set timeout interval in miliseconds + */ void game_speed(int value); +/* + * Prints a message in screen on a position x,y + */ + void set_message(const char* message,int x,int y); +/* + * Clears screen + */ void clear_screen(); #endif