diff --git a/src/draw.c b/src/draw.c index 506a602..cb7291b 100644 --- a/src/draw.c +++ b/src/draw.c @@ -500,7 +500,8 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) { } -void draw_level_time(SDL_Renderer *ren, struct environment * e) { +void draw_text(SDL_Renderer *rend, Vect pos, struct colour colour, char *text) { + static SDL_Renderer *ren = NULL; static TTF_Font* font = NULL; if (!font) { font = TTF_OpenFont("TerminusTTF.ttf", 18); @@ -509,20 +510,15 @@ void draw_level_time(SDL_Renderer *ren, struct environment * e) { printf("%s\n", err); } } - - int margin = height / 10; - SDL_Rect position = {.x = margin, .y = height - margin}; - struct colour colour = e->colours.fg1; - - int minutes = level_time / 60000; - float seconds = level_time * 0.001; - char time_string[250]; - snprintf(time_string, 250, "%d:%.4f", minutes, seconds); + if (!ren) { + ren = rend; + } SDL_Colour sdl_col = {colour.r, colour.g, colour.b, 255}; + SDL_Rect position = {.x = pos.x, .y = pos.y}; SDL_SetRenderDrawColor(ren, colour.r, colour.g, colour.b, 255); - SDL_Surface *surf = TTF_RenderText_Solid(font, time_string, sdl_col); + SDL_Surface *surf = TTF_RenderText_Solid(font, text, sdl_col); SDL_Texture *texture = SDL_CreateTextureFromSurface(ren, surf); SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h); @@ -533,6 +529,22 @@ void draw_level_time(SDL_Renderer *ren, struct environment * e) { } +void draw_level_time(SDL_Renderer *ren, struct environment * e) { + + int margin = height / 10; + Vect position = {.x = margin, .y = height - margin}; + + struct colour colour = e->colours.fg1; + + int minutes = level_time / 60000; + float seconds = level_time * 0.001; + char time_string[250]; + snprintf(time_string, 250, "%d:%.4f", minutes, seconds); + + draw_text(ren, position, colour, time_string); + +} + void redraw_buffer(SDL_Renderer * ren) { static int mousex = 0; static int mousey = 0; diff --git a/src/draw.h b/src/draw.h index 2600311..3180d7a 100644 --- a/src/draw.h +++ b/src/draw.h @@ -35,6 +35,7 @@ extern Vect viewport_pos; extern int width, height; +void draw_text(SDL_Renderer *ren, Vect pos, struct colour colour, char *text); #endif diff --git a/src/game.c b/src/game.c index 9fac029..ac602d3 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,5 @@ #include "game.h" +#include #include #include @@ -1530,6 +1531,7 @@ void step(int interval) { if (player.physics->position.x > world.uniques_index[ROOM_W]->room ->floor.items[world.uniques_index[ROOM_W]->room->floor.numItems - 1]->position.x) { + SDL_Delay(1000); next_level(); level_timer_update(true); } diff --git a/src/main.c b/src/main.c index 87d19de..7cd3eda 100644 --- a/src/main.c +++ b/src/main.c @@ -40,7 +40,7 @@ void redraw(struct SDL_Renderer * ren) { int physics_loop(void *ptr) { while (true) { step(10); - SDL_Delay(5); + SDL_Delay(10); } }