a simple score

This commit is contained in:
Frank Villaro-Dixon 2015-01-04 11:35:10 +01:00
parent 4c78342cea
commit f8a448d9ce
5 changed files with 38 additions and 3 deletions

View file

@ -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);
}

View file

@ -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 */

View file

@ -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

View file

@ -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) { // {{{

View file

@ -7,7 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#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);
}