mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 10:08:10 +00:00
Pong: Switch to global tracking
When I play Pong, I don't really pay attention to whether my mouse is in the Pong window. That means that sometimes, annoyingly, the window loses my mouse, and I lose control of the paddle. Gasp! D: This commit teaches Pong the wonders of global mouse tracking, thus enabling the player to focus solely on the game.
This commit is contained in:
parent
4f2bcebe74
commit
9c3da7a3e3
2 changed files with 7 additions and 4 deletions
|
@ -108,7 +108,7 @@ void Game::keydown_event(GUI::KeyEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void Game::mousemove_event(GUI::MouseEvent& event)
|
||||
void Game::track_mouse_move(Gfx::IntPoint const& point)
|
||||
{
|
||||
if (m_up_key_held || m_down_key_held) {
|
||||
// We're using the keyboard to move the paddle, the cursor is doing something else
|
||||
|
@ -118,7 +118,8 @@ void Game::mousemove_event(GUI::MouseEvent& event)
|
|||
if (m_cursor_paddle_target_y.has_value())
|
||||
update(cursor_paddle_target_rect());
|
||||
|
||||
m_cursor_paddle_target_y = clamp(event.y() - m_player1_paddle.rect.height() / 2, 0.f, game_height - m_player1_paddle.rect.height());
|
||||
auto relative_point = point - window()->position();
|
||||
m_cursor_paddle_target_y = clamp(relative_point.y() - m_player1_paddle.rect.height() / 2, 0.f, game_height - m_player1_paddle.rect.height());
|
||||
if (m_player1_paddle.rect.y() > *m_cursor_paddle_target_y) {
|
||||
m_player1_paddle.moving_up = true;
|
||||
m_player1_paddle.moving_down = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue