mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
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:
parent
740beea5ce
commit
0abdeb474f
2 changed files with 15 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue