Skip to content
Snippets Groups Projects
Commit 07345ad8 authored by belkhiritaha's avatar belkhiritaha
Browse files

ajout gestion click sur le bouton menu

parent 74cee428
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -42,6 +42,13 @@ void manageMenu(){
mousePosition.y = event.motion.y;
continue;
case SDL_MOUSEBUTTONDOWN:
if (SDL_PointInRect(&mousePosition, &buttonRect)){
gameState = GAME;
}
break;
default:
continue;
}
......
......@@ -6,6 +6,8 @@ SDL_Renderer *renderer;
TTF_Font *robotoFont;
SDL_DisplayMode screenDimension;
SDL_Rect buttonRect;
SDL_Surface * grassSurface;
SDL_Texture * grassTexture;
......@@ -69,12 +71,16 @@ void drawPlayButton(){
int buttonPosY = screenDimension.h/2;
int buttonW = screenDimension.w/6;
int buttonH = screenDimension.h/6;
SDL_Rect rect = {buttonPosX, buttonPosY, buttonW, buttonH};
buttonRect.x = buttonPosX;
buttonRect.y = buttonPosY;
buttonRect.w = buttonW;
buttonRect.h = buttonH;
if (mousePosition.x <= buttonPosX + buttonW && mousePosition.x >= buttonPosX && mousePosition.y >= buttonPosY && mousePosition.y <= buttonPosY + buttonH){
SDL_RenderCopy(renderer, playButtonHoverTexture, NULL, &rect);
SDL_RenderCopy(renderer, playButtonHoverTexture, NULL, &buttonRect);
}
else {
SDL_RenderCopy(renderer, playButtonTexture, NULL, &rect);
SDL_RenderCopy(renderer, playButtonTexture, NULL, &buttonRect);
}
}
......
......@@ -11,6 +11,7 @@
extern SDL_Window *window;
extern SDL_Renderer *renderer;
extern SDL_DisplayMode screenDimension;
extern SDL_Rect buttonRect;
void drawHover(int x, int y);
void mainLoop();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment