Skip to content

Commit

Permalink
fix: use more precise mouse scale factor to determine players paddle …
Browse files Browse the repository at this point in the history
…on screen at any screen resolution
  • Loading branch information
mikedsharp committed Aug 19, 2024
1 parent 181e7cb commit cd8ffb6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Game/src/States/RandomRebound_GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void RandomRebound_GameState::CheckEvent()
int mouseX, mouseY;

SDL_GetMouseState(&mouseX, &mouseY);
m_cursorBounds->SetPosition(mouseX, mouseY);
// apply scaling to cursor position
m_cursorBounds->SetPosition((float)mouseX / m_engineInstance->GetGameWindow()->m_mouseScaleFactorX, mouseY / m_engineInstance->GetGameWindow()->m_mouseScaleFactorY);

while (SDL_PollEvent(e) != 0)
{
Expand All @@ -76,7 +77,7 @@ void RandomRebound_GameState::CheckEvent()
}
else if (e->type == SDL_MOUSEMOTION)
{
m_player->SetPosition((mouseX - m_player->Bounds().Width() / 2), m_player->Bounds().Y());
m_player->SetPosition((m_cursorBounds->X()), m_player->Bounds().Y());
}
else if (e->type == SDL_MOUSEBUTTONDOWN)
{
Expand Down Expand Up @@ -483,8 +484,8 @@ void RandomRebound_GameState::StartState()
#else
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
SDL_WarpMouseInWindow(m_engineInstance->GetGameWindow()->m_windowObj, mouseX, mouseY);
SDL_ShowCursor(SDL_DISABLE);
m_player->SetPosition((mouseX - m_player->Bounds().Width() / 2), m_player->Bounds().Y());
#endif
m_gameBall->YSpeed(BALL_BASE_SPEED);
m_gameBall->XSpeed(0);
Expand Down
2 changes: 1 addition & 1 deletion rebound-engine

0 comments on commit cd8ffb6

Please sign in to comment.