diff --git a/src/VisibleObjects/Ball.h b/src/VisibleObjects/Ball.h index 09a9d59..992630b 100644 --- a/src/VisibleObjects/Ball.h +++ b/src/VisibleObjects/Ball.h @@ -22,14 +22,9 @@ private: public: explicit Ball(const SDL_Point *screen, const PlayerPaddle *leftPaddle, const PlayerPaddle *rightPaddle, - Score *score) { - this->score = score; - this->screen = screen; - this->leftPaddle = leftPaddle; - this->rightPaddle = rightPaddle; - this->x = screen->x / 2; - this->y = screen->y / 2; - vec2d = new Vec2d(6); + Score *score) : + score(score), screen(screen), leftPaddle(leftPaddle), rightPaddle(rightPaddle), x(screen->x / 2), + y(screen->y / 2), vec2d(new Vec2d(6)) { } void resetPosition() { @@ -66,11 +61,11 @@ public: } private: - bool collidedScreenEdgeVertical() { + [[nodiscard]]bool collidedScreenEdgeVertical() const { return y - RADIUS <= 0 || y + RADIUS >= screen->y; } - std::optional collidedScreenEdgeHorizontal() { + [[nodiscard]] std::optional collidedScreenEdgeHorizontal() const { if (x + RADIUS >= screen->x) return Side::RIGHT; else if (x - RADIUS <= 0) @@ -78,7 +73,7 @@ private: return std::nullopt; } - std::optional collidedPaddle() { + [[nodiscard]] std::optional collidedPaddle() const { // Right paddle if (x + RADIUS >= rightPaddle->x && y >= rightPaddle->y && diff --git a/src/VisibleObjects/PlayerPaddle.h b/src/VisibleObjects/PlayerPaddle.h index 2810235..3bf8f67 100644 --- a/src/VisibleObjects/PlayerPaddle.h +++ b/src/VisibleObjects/PlayerPaddle.h @@ -44,13 +44,13 @@ public: SDL_RenderFillRect(renderer, this); } - void startMoving(bool up) { + void startMoving(const bool up) { if (up) movingUp = true; else movingDown = true; } - void stopMoving(bool up) { + void stopMoving(const bool up) { if (up) movingUp = false; else movingDown = false; @@ -68,11 +68,11 @@ public: } private: - bool canMoveDown() { + [[nodiscard]] bool canMoveDown() const { return y + h < screen->y; } - bool canMoveUp() { + [[nodiscard]] bool canMoveUp() const { return y > 0; } diff --git a/src/VisibleObjects/Score.h b/src/VisibleObjects/Score.h index 3760d99..2d9d1fc 100644 --- a/src/VisibleObjects/Score.h +++ b/src/VisibleObjects/Score.h @@ -36,7 +36,7 @@ private: const int shadowOffset = 3; public: - explicit Score(uint8_t max_score, SDL_Point *screenSize, const std::function whenWon) : MAX_SCORE( + explicit Score(uint8_t max_score, SDL_Point *screenSize, const std::function &whenWon) : MAX_SCORE( max_score), whenWon(whenWon) { resetScore(); if (defaultFontPath == nullptr) { @@ -57,17 +57,14 @@ public: ~Score() { if (font) TTF_CloseFont(font); - if (surface) - SDL_FreeSurface(surface); + SDL_FreeSurface(surface); } void update() { if (!hasIncremented && surface != nullptr && shadowSurface != nullptr) return; - if (surface != nullptr) - SDL_FreeSurface(surface); - if (shadowSurface != nullptr) - SDL_FreeSurface(shadowSurface); + SDL_FreeSurface(surface); + SDL_FreeSurface(shadowSurface); hasIncremented = false; char score_text[8]; @@ -112,7 +109,7 @@ public: leftScore = rightScore = 0; } - void incrementScore(Side side) { + void incrementScore(const Side side) { hasIncremented = true; uint8_t temp; switch (side) {