diff --git a/src/VisibleObjects/PlayerPaddle.h b/src/VisibleObjects/PlayerPaddle.h index faac2d5..2810235 100644 --- a/src/VisibleObjects/PlayerPaddle.h +++ b/src/VisibleObjects/PlayerPaddle.h @@ -31,7 +31,7 @@ public: color[3] = 255; } - PaddleDirection getPaddleDirection() const { + [[nodiscard]] PaddleDirection getPaddleDirection() const { if (movingUp != movingDown) return PaddleDirection::NOT_MOVING; else if (movingUp) diff --git a/src/VisibleObjects/Score.h b/src/VisibleObjects/Score.h index fae1ad3..ae58f4a 100644 --- a/src/VisibleObjects/Score.h +++ b/src/VisibleObjects/Score.h @@ -16,13 +16,13 @@ #include #if defined(_WIN32) || defined(_WIN64) -// Windows - const char* defaultFontPath = "C:\\Windows\\Fonts\\Arial.ttf"; +const char* defaultFontPath = "C:\\Windows\\Fonts\\Arial.ttf"; #elif defined(__linux__) const char *defaultFontPath = "/usr/share/fonts/truetype/DejaVuSans-Bold.ttf"; +#elif defined(__APPLE__) || defined(__MACH__) +const char *defaultFontPath = "/System/Library/Fonts/Supplemental/Arial.ttf"; #else -// Other platforms - const char* defaultFontPath = "path/to/a/default/font.ttf"; +const char* defaultFontPath = nullptr; #endif @@ -30,7 +30,7 @@ class Score { private: uint8_t leftScore, rightScore; const uint8_t MAX_SCORE; - std::function &whenWon; + const std::function whenWon; TTF_Font *font; bool hasIncremented = false; @@ -40,14 +40,19 @@ private: SDL_Surface *surface = nullptr; // Shadow - const SDL_Color shadowColor = {243, 156, 18, 100}; // Black color for the shadow + const SDL_Color shadowColor = {243, 156, 18, 100}; SDL_Surface *shadowSurface = nullptr; const int shadowOffset = 3; public: - explicit Score(uint8_t max_score, SDL_Point *screenSize, std::function whenWon) : MAX_SCORE(max_score), - whenWon(whenWon) { + explicit Score(uint8_t max_score, SDL_Point *screenSize, const std::function whenWon) : MAX_SCORE( + max_score), whenWon(whenWon) { resetScore(); + if (defaultFontPath == nullptr) { + std::cerr << "Font path is not set for this platform (null)" << std::endl; + exit(-1); + } + this->font = TTF_OpenFont(defaultFontPath, 42); if (font == nullptr) { std::cerr << "Failed to load font: " << TTF_GetError() << std::endl; @@ -55,6 +60,7 @@ public: } this->position = SDL_Rect{screenSize->x / 2 - 50, 10, 100, 40}; + this->rightScore = this->leftScore = 0; } ~Score() { @@ -96,7 +102,7 @@ public: if (shadowTexture != nullptr) { SDL_Rect shadowPosition = {position.x + shadowOffset, position.y + shadowOffset, position.w, position.h}; - SDL_RenderCopy(renderer, shadowTexture, NULL, &shadowPosition); + SDL_RenderCopy(renderer, shadowTexture, nullptr, &shadowPosition); SDL_DestroyTexture(shadowTexture); } } @@ -105,7 +111,7 @@ public: if (surface != nullptr) { SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); if (texture != nullptr) { - SDL_RenderCopy(renderer, texture, NULL, &position); + SDL_RenderCopy(renderer, texture, nullptr, &position); SDL_DestroyTexture(texture); } }