Pong: Extend Game::reset()

Previously, the method reset the ball and the paddles. Now, it will
also reset and redraw the scores and update the ball's rect.
This commit is contained in:
Martin Frederic 2022-04-02 17:28:31 +02:00 committed by Andreas Kling
parent 740beea5ce
commit 0abdeb474f
2 changed files with 15 additions and 0 deletions

View file

@ -36,6 +36,10 @@ void Game::reset_paddles()
void Game::reset()
{
// Make sure the current ball disappears.
update(enclosing_int_rect(m_ball.rect()));
reset_scores();
reset_ball(1);
reset_paddles();
}
@ -130,6 +134,16 @@ void Game::track_mouse_move(Gfx::IntPoint const& point)
update(cursor_paddle_target_rect());
}
void Game::reset_scores()
{
// Clearing the scores first would lead to overly narrow rects for multi-digit scores.
update(player_1_score_rect());
update(player_2_score_rect());
m_player_1_score = 0;
m_player_2_score = 0;
}
void Game::reset_ball(int serve_to_player)
{
int position_y_min = (game_width / 2) - 50;

View file

@ -39,6 +39,7 @@ private:
virtual void timer_event(Core::TimerEvent&) override;
virtual void track_mouse_move(Gfx::IntPoint const&) override;
void reset_scores();
void reset_ball(int serve_to_player);
void reset_paddles();
void tick();