I'm trying to create a simple recreation of the popular memory game "Simon" using C and SDL2. The idea is that the game is a small window with four squares of different colors that are purposefully dim. When the player clicks on a square, I want it to "light up" until the player let's go of their mouse button, in which it returns to it's original dim color.
I have this working to an extent, but the problem is that it only works if the player let's go of the mouse button while the pointer is over the square. If they let go anywhere else, the square stays lit up.
Here is the example code:
if(e.type == SDL_MOUSEBUTTONDOWN && mouseX >= 10 && mouseX <= 110 && mouseY >= 10 && mouseY <= 110) {
if(e.button.button == SDL_BUTTON_LEFT) {
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, &squareOne);
SDL_RenderPresent(renderer);
}
}
if(e.type == SDL_MOUSEBUTTONUP && mouseX >= 10 && mouseX <= 110 && mouseY >= 10 && mouseY <= 110) {
if(e.button.button == SDL_BUTTON_LEFT) {
SDL_SetRenderDrawColor(renderer, 0, 50, 0, 255);
SDL_RenderFillRect(renderer, &squareOne);
SDL_RenderPresent(renderer);
}
}
As you can see, I'm looking for the user to be clicking in a very specific area, and waiting for them to "unclick" in that same specific area. There has got to be a better way to do this. Would anyone do me the pleasure of offering a few hints?