I will make a game and it has 3 buttons on its menu. Those buttons supposed to change the picture the background of the menu
When i click on play, another picture should appear like so
I found a solution which is closing the current program and starting another one that has the comming soon picture but what i would like to do is to only change the picture without the need to close the program and start another one , Here is my code for the menu screen:
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
int continuer=1;
SDL_Event event;
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *imageDeFond = NULL, *sapin = NULL;
int continuer=1;
SDL_Event event;
SDL_Rect positionFond,positionSapin;
positionSapin.x = 0;
positionSapin.y = 0;
positionFond.x = 0;
positionFond.y = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
SDL_WM_SetCaption("Chargement d'images en SDL", NULL);
/* Chargement d'une image Bitmap dans une surface */
imageDeFond = SDL_LoadBMP("menu.bmp");
/* On blitte par-dessus l'écran */
SDL_BlitSurface(imageDeFond, NULL, ecran, &positionFond);
SDL_Flip(ecran);
SDL_FreeSurface(imageDeFond);
while(continuer)
{ SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer=0;
break ;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
continuer=0;
break;
}
break;
case SDL_MOUSEBUTTONUP:
if (event.button.button == SDL_BUTTON_LEFT)
{
positionFond.x = event.button.x;
positionFond.y = event.button.y;
if (event.button.x> 150 && event.button.x < 320 && event.button.y > 340 && event.button.y < 415 )
{
continuer = 0;
}
else if (event.button.x> 150 && event.button.x < 320 && event.button.y > 105 && event.button.y < 180 )
{
continuer=0;
SDL_Quit();
int status = system("./cs");
}
}
break ;
}
}
SDL_Quit();
return EXIT_SUCCESS;
}
Here is my second code when i click on the play button:
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
int continuer=1;
SDL_Event event;
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *imageDeFond = NULL, *sapin = NULL;
int continuer=1;
SDL_Event event;
SDL_Rect positionFond,positionSapin;
positionSapin.x = 0;
positionSapin.y = 0;
positionFond.x = 0;
positionFond.y = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE);
SDL_WM_SetCaption("Chargement d'images en SDL", NULL);
/* Chargement d'une image Bitmap dans une surface */
imageDeFond = SDL_LoadBMP("menujouer.bmp");
/* On blitte par-dessus l'écran */
SDL_BlitSurface(imageDeFond, NULL, ecran, &positionFond);
SDL_Flip(ecran);
SDL_FreeSurface(imageDeFond);
while(continuer)
{ SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer=0;
break ;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
continuer=0;
SDL_Quit();
int status = system("./menu");
break;
}
}
}
SDL_Quit();
return EXIT_SUCCESS;
}
Is there any solution to make it in the same program without closing and reopning an other program because when i tried it the problem was the buttons of the first picture(menu image) was still active so when i click on the zone of quit it closes the program even though the menu image is hidden under the second.