mirror of
https://github.com/lov3b/Pong.git
synced 2025-01-18 12:40:12 +01:00
cleanup
This commit is contained in:
parent
a86a3c170a
commit
62e7eb1e93
@ -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<Side> collidedScreenEdgeHorizontal() {
|
||||
[[nodiscard]] std::optional<Side> 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<Side> collidedPaddle() {
|
||||
[[nodiscard]] std::optional<Side> collidedPaddle() const {
|
||||
// Right paddle
|
||||
if (x + RADIUS >= rightPaddle->x &&
|
||||
y >= rightPaddle->y &&
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
const int shadowOffset = 3;
|
||||
|
||||
public:
|
||||
explicit Score(uint8_t max_score, SDL_Point *screenSize, const std::function<void(Side)> whenWon) : MAX_SCORE(
|
||||
explicit Score(uint8_t max_score, SDL_Point *screenSize, const std::function<void(Side)> &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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user