1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| /*
Objets
Feu :
.surface *objetFeu
.position positionOFeu
.IMG non utilisé : feu.png
.IMG utilisé : useFeu.png
.Nb désigné : objet = 1
*/
int ouvrirInventaire(SDL_Surface* ecran, int objet)
{
SDL_Surface *inventaire = NULL, *objetFeu = NULL, *oSouris = NULL;
SDL_Rect positionInventaire, positionOFeu, positionSouris;
SDL_Event event;
int continuer = 1;
SDL_Init(SDL_INIT_VIDEO);
inventaire = IMG_Load("inventaire.jpg"); //Chargement de l'image de l'inventaire
positionInventaire.x = ecran->w / 2 - inventaire->w / 2;
positionInventaire.y = ecran->h / 2 - inventaire->h / 2;
if(objet == 0) //Si l'objet n'a pas encore été utilisé
{
objetFeu = IMG_Load("feu.png");
positionOFeu.x = 320;
positionOFeu.y = 260;
}
else //Sinon on le grise
{
objetFeu = IMG_Load("useFeu.png");
positionOFeu.x = 320;
positionOFeu.y = 260;
}
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_MOUSEBUTTONDOWN:
if((event.button.button == SDL_BUTTON_LEFT) &&(event.button.x <= 360)&&(event.button.x >= 320)&&(event.button.y <= 290)&&(event.button.y >= 260)) //Si le joueur clique à cet endroit
{
objetFeu = IMG_Load("useFeu.png");
objet = 1; //1 représente l'objet "feu"
oSouris = IMG_Load("feu.png"); //On charge l'icone feu qui va suivre la souris
}
if(event.button.button == SDL_BUTTON_RIGHT)
continuer = 0; //on quitte l'inventaire
case SDL_MOUSEMOTION:
positionSouris.x = event.motion.x;
positionSouris.y = event.motion.y;
break;
}
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
SDL_BlitSurface(inventaire,NULL,ecran,&positionInventaire);
SDL_BlitSurface(objetFeu,NULL,ecran,&positionOFeu);
SDL_BlitSurface(oSouris,NULL,ecran,&positionSouris);
SDL_Flip(ecran);
}
SDL_FreeSurface(ecran);
SDL_FreeSurface(inventaire);
SDL_FreeSurface(objetFeu);
return objet;
} |
Partager