diff --git a/src/game.c b/src/game.c index 4cad3a9..83f4684 100644 --- a/src/game.c +++ b/src/game.c @@ -179,3 +179,19 @@ update_game_time(struct s_game *g) { g->elapsed_time = secs_passed; } + +void +show_score(struct s_game *g) { + SDL_Surface *text; + SDL_Color text_color = {255, 255, 255, 0}; + char buffer[1024]; + + + snprintf(buffer, sizeof(buffer), "%lf", g->elapsed_time); + + text = TTF_RenderText_Solid(g->font, buffer, text_color); + + SDL_BlitSurface(text, NULL, g->screen, NULL); + + SDL_FreeSurface(text); +} diff --git a/src/game.h b/src/game.h index 7ce1fcd..58eb9cd 100644 --- a/src/game.h +++ b/src/game.h @@ -8,6 +8,7 @@ #define GAME_H #include "SDL/SDL.h" +#include "SDL/SDL_ttf.h" #include "SDL_prims.h" #define MUSICS_PATH "./audio/" @@ -94,6 +95,7 @@ struct s_game { } audio; SDL_Surface *screen; + TTF_Font *font; Uint8 *keys; }; @@ -124,5 +126,8 @@ void update_game_time(struct s_game *g); +void +show_score(struct s_game *g); + #endif /* ndef GAME_H */ diff --git a/src/main.c b/src/main.c index 635efd5..1d38b05 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ main() struct s_game ga; srand(time(NULL)); + init_music(&ga); init_SDL(&ga); @@ -32,7 +33,6 @@ start: struct s_obstacle a = create_obstacle(SHAPE_THICK, 2, 1, -1); add_obstacle(&ga, a); - while(1) { //clear the screen SDL_FillRect(ga.screen, NULL, 0); @@ -63,6 +63,7 @@ start: update_obstacles(&ga); draw_game(&ga); + show_score(&ga); SDL_Flip(ga.screen); #if 1 diff --git a/src/music.c b/src/music.c index c7fadd9..5e4f0cc 100644 --- a/src/music.c +++ b/src/music.c @@ -11,7 +11,6 @@ #include "SDL_mixer.h" #include "game.h" #include "utils.h" -#include "mus_beats.h" void music_load_beats(struct s_game *g, int music) { // {{{ diff --git a/src/sdl.c b/src/sdl.c index 6840f53..da4d490 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -7,7 +7,7 @@ #include #include #include "SDL/SDL.h" -#include "SDL2/SDL_ttf.h" +#include "SDL/SDL_ttf.h" #include "game.h" void @@ -33,4 +33,18 @@ init_SDL(struct s_game *g) perror("Could not load SDL TTF"); exit(EXIT_FAILURE); } + + TTF_Font *font; + //TODO FIXME + font = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSerif.ttf", 26); + + if(!font) { + perror("Could not load font"); + } + + g->font = font; + + + atexit(TTF_Quit); + atexit(SDL_Quit); }