feat: ajout d'une fonctionnalité pour basculer l'affichage du FPS avec la touche F2

- Ajout d'une variable `std::atomic<bool> displayFPSFlag` pour suivre l'état d'affichage du FPS
- Modification de la gestion des événements pour basculer `displayFPSFlag` lorsque la touche F2 est pressée
- Mise à jour de la fonction `renderScene` pour afficher le FPS uniquement si `displayFPSFlag` est vrai
This commit is contained in:
2024-12-18 14:46:59 +01:00
parent 5ca2cae04e
commit 7d11ece61b
4 changed files with 9 additions and 1 deletions

View File

@@ -43,6 +43,10 @@ void handleQuit() {
Mix_VolumeMusic(MIX_MAX_VOLUME);
}
}
if (keystate[SDL_SCANCODE_F2]) {
displayFPSFlag = !displayFPSFlag;
}
}
void cleanup() {

View File

@@ -31,6 +31,7 @@ int SOUND_CHANNEL = 1;
SDL_Texture* playerTexture = nullptr;
SDL_Texture* fishTextures[100];
std::vector<Fish> school;
std::atomic<bool> displayFPSFlag(true);
void resetAll(){

View File

@@ -49,6 +49,7 @@ extern int SOUND_CHANNEL;
extern SDL_Texture* fishTextures[100];
extern SDL_Texture* playerTexture;
extern std::vector<Fish> school;
extern std::atomic<bool> displayFPSFlag;
bool initEnvironment(SDL_Renderer* renderer);
std::vector<SDL_Texture*> initTexture(SDL_Renderer* renderer);

View File

@@ -233,7 +233,9 @@ void renderScene(std::vector<Player>& players, const std::vector<Kelp>& kelps, c
shark.draw(renderer);
displayFPS(renderer, font, fps);
if (displayFPSFlag) {
displayFPS(renderer, font, fps);
}
SDL_RenderPresent(renderer);
}