Skip to content

Commit

Permalink
Fix Mouse Controls:
Browse files Browse the repository at this point in the history
- Fix mouse controls when virtual dpad overlaps game screen
- Only react on mouse clicks if clicks are within game space
  • Loading branch information
joyrider3774 committed Jun 18, 2024
1 parent d3eba11 commit 070e816
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/formula1.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ void Game()
GameState -= GSInitDiff;
}

if(buttonReleased(BUTTON_LEFT) || mouseButtonReleased(MOUSE_LEFT))
if(buttonReleased(BUTTON_LEFT) || ((mouseButtonReleased(MOUSE_LEFT) && !anyButtonReleased() && mouseInGameBounds())))
if(CanMove)
MoveLeft();
if(buttonReleased(BUTTON_RIGHT) || mouseButtonReleased(MOUSE_RIGHT))
if(buttonReleased(BUTTON_RIGHT) || ((mouseButtonReleased(MOUSE_RIGHT) && !anyButtonReleased() && mouseInGameBounds())))
if(CanMove)
MoveRight();

Expand Down Expand Up @@ -259,7 +259,7 @@ void GameOver()

if(buttonReleased(BUTTON_LEFT) || buttonReleased(BUTTON_RIGHT) || buttonReleased(BUTTON_UP) ||
buttonReleased(BUTTON_DOWN) || buttonReleased(BUTTON_1) || buttonReleased(BUTTON_2) ||
mouseButtonReleased(MOUSE_LEFT) || mouseButtonReleased(MOUSE_RIGHT))
((mouseButtonReleased(MOUSE_LEFT) || mouseButtonReleased(MOUSE_RIGHT)) && !anyButtonReleased() && mouseInGameBounds()))
GameState = GSGameInit;
setDrawColor(3,4,2,1);
blit(background, 0, 0, backgroundWidth, backgroundHeight, backgroundFlags);
Expand Down Expand Up @@ -292,7 +292,7 @@ void Intro()

if(buttonReleased(BUTTON_LEFT) || buttonReleased(BUTTON_RIGHT) || buttonReleased(BUTTON_UP) ||
buttonReleased(BUTTON_DOWN) || buttonReleased(BUTTON_1) || buttonReleased(BUTTON_2) ||
mouseButtonReleased(MOUSE_LEFT) || mouseButtonReleased(MOUSE_RIGHT))
((mouseButtonReleased(MOUSE_LEFT) || mouseButtonReleased(MOUSE_RIGHT)) && !anyButtonReleased() && mouseInGameBounds()))
GameState = GSGameInit;
setDrawColor(3,4,2,1);
blit(background, 0, 0, backgroundWidth, backgroundHeight, backgroundFlags);
Expand Down
10 changes: 10 additions & 0 deletions src/helperfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,13 @@ void clear(ColorIndex Index)
rect(0,0, SCREEN_SIZE, SCREEN_SIZE);
setDrawColor(Index1, Index2, Index3, Index4);
}

bool mouseInGameBounds()
{
return (*MOUSE_Y <= SCREEN_SIZE) && (*MOUSE_X <= SCREEN_SIZE) && (*MOUSE_Y >= 0) && (*MOUSE_X >=0);
}

bool anyButtonReleased()
{
return buttonReleased(BUTTON_1) || buttonReleased(BUTTON_2) || buttonReleased(BUTTON_DOWN) || buttonReleased(BUTTON_LEFT) || buttonReleased(BUTTON_RIGHT) || buttonReleased(BUTTON_UP);
}
2 changes: 2 additions & 0 deletions src/helperfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ void getDrawColor(ColorIndex *Index1, ColorIndex *Index2, ColorIndex *Index3, Co
void setDrawColor(ColorIndex Index1, ColorIndex Index2, ColorIndex Index3, ColorIndex Index4);
bool buttonReleased(uint32_t Button);
bool mouseButtonReleased(uint32_t Button);
bool mouseInGameBounds();
bool anyButtonReleased();
#endif

0 comments on commit 070e816

Please sign in to comment.