mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
Pong: Explicitly clear held keys in Game::reset()
The paddle's movement is determined by the currently held keys. A key is no longer considered held when a matching keyup_event() fires. However, the event does not fire when the timer has stopped (e.g. due to a game over condition), which can result in the paddle keeping its former direction and moving on its own -- even after the player started a new game. Therefore, any held keys will be cleared explicitly.
This commit is contained in:
parent
02d2a300e7
commit
3e6c083754
2 changed files with 8 additions and 0 deletions
|
@ -15,6 +15,12 @@ Game::Game()
|
|||
reset();
|
||||
}
|
||||
|
||||
void Game::reset_keys()
|
||||
{
|
||||
m_up_key_held = false;
|
||||
m_down_key_held = false;
|
||||
}
|
||||
|
||||
void Game::reset_paddles()
|
||||
{
|
||||
if (m_cursor_paddle_target_y.has_value())
|
||||
|
@ -46,6 +52,7 @@ void Game::reset()
|
|||
|
||||
reset_scores();
|
||||
reset_ball(1);
|
||||
reset_keys();
|
||||
reset_paddles();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ private:
|
|||
|
||||
void reset_scores();
|
||||
void reset_ball(int serve_to_player);
|
||||
void reset_keys();
|
||||
void reset_paddles();
|
||||
void tick();
|
||||
void round_over(int player);
|
||||
|
|
Loading…
Add table
Reference in a new issue