I'm creating a mini-game with many questions and want you to have time, or want an accountant who go to x to scratch . The counter only needs to have seconds and minutes. Does anyone know of some function C ++ or some "workaround" for a countdown?
I'm creating a mini-game with many questions and want you to have time, or want an accountant who go to x to scratch . The counter only needs to have seconds and minutes. Does anyone know of some function C ++ or some "workaround" for a countdown?
The best way to make a game counter is by using Threads , so it will be possible to count the time without interference from the FPS ).
void time_decrement(void *game_config){
GameConfig *gc = (GameConfig*) game_config;
while(gc->time > 0){
sleep(1);
gc->time--;
}
gc->game_loop = false;
}
main:
//...
pthread_create(&line,NULL,time_decrement,(void *) g_config);
//...
GameConfig
represents struct
or classe
that has the game settings, (time, pause, end of game, etc.). It's an optional medium, but from my point of view, it's better to leave it in separate variables.
In this example Thread will close the game as soon as the counter reaches 0 .