Skip to content
Snippets Groups Projects
Commit e3194bfc authored by Montjoie Henri's avatar Montjoie Henri
Browse files

appel des fonctions de liberation de l'espace memoire

parent a9a4b7e1
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -24,15 +24,17 @@ char* nom_2; ...@@ -24,15 +24,17 @@ char* nom_2;
*/ */
int main_affichage() int main_affichage()
{ {
nom_1="Joueur 1";
nom_2="Joueur 2";
etat=LANCEMENT;/*lance le jeu direct l'ecran de lancement, sans rentrer les noms des joueurs*/ etat=LANCEMENT;/*lance le jeu direct l'ecran de lancement, sans rentrer les noms des joueurs*/
//etat=SAISIE_JOUEURS; /*lance le jeu l'ecran "entrer nom joueur 1"*/ //etat=SAISIE_JOUEURS; /*lance le jeu l'ecran "entrer nom joueur 1"*/
if (SDL_Init(SDL_INIT_VIDEO)<0) if (SDL_Init(SDL_INIT_VIDEO)<0) /*initialisation de la SDL*/
{ {
printf("Unable to init SDL: %s\n", SDL_GetError()); printf("Unable to init SDL: %s\n", SDL_GetError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(TTF_Init()==-1) if(TTF_Init()==-1) /*initialisation de SDL_ttf (affichage de texte)*/
{ {
fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError()); fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -59,6 +61,7 @@ int main_affichage() ...@@ -59,6 +61,7 @@ int main_affichage()
} }
} }
TTF_Quit();
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }
...@@ -68,8 +71,8 @@ int main_affichage() ...@@ -68,8 +71,8 @@ int main_affichage()
* \fn char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Font* police,SDL_Color couleurTexte) * \fn char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Font* police,SDL_Color couleurTexte)
* \brief Fonction permettant le choix de la classe d'un personnage par le joueur * \brief Fonction permettant le choix de la classe d'un personnage par le joueur
* *
* \param le tableau contenant les noms des classes, le tableau contenant les adresse de leurs images, le nombre de classes, et la police et la couleur dans lesquelles crire les noms * \param le tableau contenant les noms des classes, le tableau contenant les adresses de leurs images, le nombre de classes, et la police et la couleur dans lesquelles crire les noms
* \return le nom de la classe choisie * \return le nom de la classe choisie (ou "fermer" si l'utilisateur ferme la fenetre)
*/ */
char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Font* police,SDL_Color couleurTexte) char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix, TTF_Font* police,SDL_Color couleurTexte)
{ {
...@@ -131,6 +134,11 @@ char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix, ...@@ -131,6 +134,11 @@ char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix,
} }
SDL_Flip(fenetre); SDL_Flip(fenetre);
} }
for(i=0;i<nbChoix;i++)
{
SDL_FreeSurface(tabTextes[i]);
SDL_FreeSurface(tabSkins[i]);
}
SDL_FreeSurface(fenetre); SDL_FreeSurface(fenetre);
return classeChoisie; return classeChoisie;
} }
...@@ -208,6 +216,10 @@ int saisie_noms_joueurs() ...@@ -208,6 +216,10 @@ int saisie_noms_joueurs()
nom_1=nom_joueur1; nom_1=nom_joueur1;
nom_2=nom_joueur2; nom_2=nom_joueur2;
TTF_CloseFont(police);
SDL_FreeSurface(ecran);
SDL_FreeSurface(logo);
SDL_FreeSurface(texte);
return 0; return 0;
} }
...@@ -218,26 +230,7 @@ int saisie_noms_joueurs() ...@@ -218,26 +230,7 @@ int saisie_noms_joueurs()
*/ */
int affichage_ecran_accueil() int affichage_ecran_accueil()
{ {
if(etat!=LANCEMENT) etat=LANCEMENT;
{
etat=LANCEMENT;
nom_1="Joueur 1";
nom_2="Joueur 2";
ajouterUnJoueur(nom_1,&etat);
ajouterUnJoueur(nom_2,&etat);
}
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
exit(EXIT_FAILURE);
}
if(TTF_Init() == -1)
{
fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
SDL_Surface* ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF); SDL_Surface* ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_WM_SetCaption("Elder Internal Ignition",NULL); SDL_WM_SetCaption("Elder Internal Ignition",NULL);
SDL_Event event; SDL_Event event;
...@@ -290,6 +283,11 @@ int affichage_ecran_accueil() ...@@ -290,6 +283,11 @@ int affichage_ecran_accueil()
SDL_BlitSurface(rectangle,NULL,ecran,&pos_texte); SDL_BlitSurface(rectangle,NULL,ecran,&pos_texte);
SDL_Flip(ecran); SDL_Flip(ecran);
} }
TTF_CloseFont(police);
SDL_FreeSurface(ecran);
SDL_FreeSurface(logo);
SDL_FreeSurface(rectangle);
SDL_FreeSurface(texte);
return 0; return 0;
} }
...@@ -300,25 +298,30 @@ int affichage_ecran_accueil() ...@@ -300,25 +298,30 @@ int affichage_ecran_accueil()
*/ */
int affichage_menu_configuration() int affichage_menu_configuration()
{ {
if(etat!=CONFIGURATION) etat=CONFIGURATION;
{
etat=CONFIGURATION;
}
SDL_Surface* ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF); SDL_Surface* ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_WM_SetCaption("Elder Internal Ignition",NULL); SDL_WM_SetCaption("Elder Internal Ignition",NULL);
SDL_Event event; SDL_Event event;
SDL_Surface* map_choisie = NULL;
SDL_Surface* texte = NULL; SDL_Surface* texte = NULL;
SDL_Surface* texte2 = NULL; SDL_Surface* texte2 = NULL;
SDL_Surface* texte3 = NULL; SDL_Surface* texte3 = NULL;
TTF_Font *police = NULL; SDL_Surface* previsualisation[5]={NULL};
TTF_Font *petite_police = NULL; SDL_Surface* textes[NB_JOUEURS*NB_PERSO]={NULL};
SDL_Surface* images_classes[nbClasses()];
SDL_Surface* images_persos[NB_PERSO][NB_JOUEURS]={{NULL}};
SDL_Rect positions_images[NB_PERSO][NB_JOUEURS];
SDL_Rect posTextes[NB_JOUEURS*NB_PERSO];
SDL_Rect pos_texte; SDL_Rect pos_texte;
SDL_Rect pos_texte2; SDL_Rect pos_texte2;
SDL_Rect pos_texte3; SDL_Rect pos_texte3;
SDL_Rect pos_texte3_bis; SDL_Rect pos_texte3_bis;
SDL_Rect position_carte[5];
TTF_Font *police = NULL;
TTF_Font *petite_police = NULL;
SDL_Color couleurNoire = {0, 0, 0}; SDL_Color couleurNoire = {0, 0, 0};
SDL_Color couleurBlanche = {255, 255, 255}; SDL_Color couleurBlanche = {255, 255, 255};
int i; int i,j,p,k,c;
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0)); SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
...@@ -342,50 +345,40 @@ int affichage_menu_configuration() ...@@ -342,50 +345,40 @@ int affichage_menu_configuration()
SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3); SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3);
SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis); SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis);
SDL_Surface textes[6];
SDL_Rect posTextes[6];
police=TTF_OpenFont("../resources/fonts/arial.ttf",26); police=TTF_OpenFont("../resources/fonts/arial.ttf",26);
char src[50], dest[50]; char src[50], dest[50];
char buffer[3]; char buffer[3];
for(i=0;i<3;i++) for(i=0;i<3;i++)
{ {
strcpy(dest, "personnage "); strcpy(dest, "personnage ");
strcpy(src, itoa(i+1,buffer,10)); strcpy(src, itoa(i+1,buffer,10));
textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire); textes[i]= TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire);
} }
for(i=3;i<6;i++) for(i=3;i<6;i++)
{ {
strcpy(dest, "personnage "); strcpy(dest, "personnage ");
strcpy(src, itoa(i-2,buffer,10)); strcpy(src, itoa(i-2,buffer,10));
textes[i]= *TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire); textes[i]= TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire);
} }
for(i=0;i<3;i++) for(i=0;i<3;i++)
{ {
posTextes[i].x=ecran->w/4-textes[i].w/2; posTextes[i].x=ecran->w/4-textes[i]->w/2;
posTextes[i].y=(i+1)*ecran->h/6; posTextes[i].y=(i+1)*ecran->h/6;
SDL_BlitSurface(&textes[i],NULL,ecran,&(posTextes[i])); SDL_BlitSurface(textes[i],NULL,ecran,&(posTextes[i]));
} }
for(i=3;i<6;i++) for(i=3;i<6;i++)
{ {
posTextes[i].x=(3*ecran->w)/4-textes[i].w/2; posTextes[i].x=(3*ecran->w)/4-textes[i]->w/2;
posTextes[i].y=posTextes[i-3].y; posTextes[i].y=posTextes[i-3].y;
SDL_BlitSurface(&textes[i],NULL,ecran,&posTextes[i]); SDL_BlitSurface(textes[i],NULL,ecran,&posTextes[i]);
} }
SDL_Flip(ecran); SDL_Flip(ecran);
char** path_images=obtenirSkinsClasses(); char** path_images=obtenirSkinsClasses();
SDL_Surface* images_classes[nbClasses()];
SDL_Surface* images_persos[3][2]={{NULL}};
SDL_Rect positions_images[3][2];
int numClassePerso[3][2]={{-1,-1},{-1,-1},{-1,-1}}; int numClassePerso[3][2]={{-1,-1},{-1,-1},{-1,-1}};
int j,p,k; j=0; /*numero du joeuur*/
j=0; p=0; /*numero du personnage*/
p=0;
char *classeChoisie; char *classeChoisie;
for(i=0;i<nbClasses();i++) for(i=0;i<nbClasses();i++)
{ {
...@@ -398,7 +391,7 @@ int affichage_menu_configuration() ...@@ -398,7 +391,7 @@ int affichage_menu_configuration()
SDL_SetColorKey(images_classes[i], SDL_SRCCOLORKEY, SDL_MapRGB(images_classes[i]->format, 0, 0, 255)); SDL_SetColorKey(images_classes[i], SDL_SRCCOLORKEY, SDL_MapRGB(images_classes[i]->format, 0, 0, 255));
} }
SDL_Surface* map_choisie=SDL_LoadBMP("../resources/Skins/Map_select.bmp"); map_choisie=SDL_LoadBMP("../resources/Skins/Map_select.bmp");
if (!map_choisie) if (!map_choisie)
{ {
printf("Unable to load bitmap: %s\n", SDL_GetError()); printf("Unable to load bitmap: %s\n", SDL_GetError());
...@@ -406,17 +399,13 @@ int affichage_menu_configuration() ...@@ -406,17 +399,13 @@ int affichage_menu_configuration()
} }
SDL_SetColorKey(map_choisie, SDL_SRCCOLORKEY, SDL_MapRGB(map_choisie->format, 0, 0, 255)); SDL_SetColorKey(map_choisie, SDL_SRCCOLORKEY, SDL_MapRGB(map_choisie->format, 0, 0, 255));
SDL_Surface* previsualisation[5]={NULL};
SDL_Rect position_carte[5];
char* path[5]; char* path[5];
path[0]="../resources/Skins/Map_1.bmp"; path[0]="../resources/Skins/Map_1.bmp"; //a revoir : cela peut se trouver dans le XML
path[1]="../resources/Skins/Map_2.bmp"; path[1]="../resources/Skins/Map_2.bmp";
path[2]="../resources/Skins/Map_3.bmp"; path[2]="../resources/Skins/Map_3.bmp";
path[3]="../resources/Skins/Map_4.bmp"; path[3]="../resources/Skins/Map_4.bmp";
path[4]="../resources/Skins/autre_map.bmp"; path[4]="../resources/Skins/autre_map.bmp";
int c=-1;
for(i=0;i<5;i++) for(i=0;i<5;i++)
{ {
previsualisation[i]=SDL_LoadBMP(path[i]); previsualisation[i]=SDL_LoadBMP(path[i]);
...@@ -429,6 +418,7 @@ int affichage_menu_configuration() ...@@ -429,6 +418,7 @@ int affichage_menu_configuration()
position_carte[i].x=(ecran->w-previsualisation[i]->w)/2+(10+previsualisation[i]->w)*(i-2); position_carte[i].x=(ecran->w-previsualisation[i]->w)/2+(10+previsualisation[i]->w)*(i-2);
} }
c=-1; /*le numro de la carte choisie*/
while(etat==CONFIGURATION) while(etat==CONFIGURATION)
{ {
SDL_WaitEvent(&event); SDL_WaitEvent(&event);
...@@ -446,35 +436,36 @@ int affichage_menu_configuration() ...@@ -446,35 +436,36 @@ int affichage_menu_configuration()
selectionnerCarte(obtenirNomsCartes()[c]); selectionnerCarte(obtenirNomsCartes()[c]);
} }
} }
if(event.button.x>posTextes[0].x&&event.button.x<posTextes[0].x+textes[0].w) if(event.button.x>posTextes[0].x&&event.button.x<posTextes[0].x+textes[0]->w)
j=1; j=1;
if(event.button.x>posTextes[3].x&&event.button.x<posTextes[3].x+textes[3].w) if(event.button.x>posTextes[3].x&&event.button.x<posTextes[3].x+textes[3]->w)
j=2; j=2;
for(i=0;i<3;i++){ for(i=0;i<3;i++)
if(event.button.y>posTextes[i].y&&event.button.y<posTextes[i].y+textes[i].h) {
if(event.button.y>posTextes[i].y&&event.button.y<posTextes[i].y+textes[i]->h)
p=i+1; p=i+1;
} }
if(j!=0&&p!=0){ if(j!=0&&p!=0)
{
classeChoisie=afficherListeClasses(obtenirNomsClasses(), obtenirSkinsClasses(), nbClasses(), police, couleurBlanche); classeChoisie=afficherListeClasses(obtenirNomsClasses(), obtenirSkinsClasses(), nbClasses(), police, couleurBlanche);
if(classeChoisie!="fermer") if(classeChoisie!="fermer")
{ {
numClassePerso[p-1][j-1]=ajouterPersonnage(classeChoisie, p-1, j); numClassePerso[p-1][j-1]=ajouterPersonnage(classeChoisie, p-1, j);
} }
ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF); ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
} }
break; break;
default: default:
break; break;
} }
for(i=0;i<6;i++)
for(i=0;i<6;i++){ {
SDL_BlitSurface(&textes[i],NULL,ecran,&(posTextes[i])); SDL_BlitSurface(textes[i],NULL,ecran,&(posTextes[i]));
} }
for(i=0;i<3;i++){ for(i=0;i<3;i++){
for(k=0;k<2;k++){ for(k=0;k<2;k++){
positions_images[i][k].y=posTextes[i].y+textes[i].h; positions_images[i][k].y=posTextes[i].y+textes[i]->h;
positions_images[i][k].x=posTextes[3*k].x+(textes[3*k].w-images_classes[0]->w)/2; positions_images[i][k].x=posTextes[NB_PERSO*k].x+(textes[NB_PERSO*k]->w-images_classes[0]->w)/2;
images_persos[i][k]=images_classes[numClassePerso[i][k]]; images_persos[i][k]=images_classes[numClassePerso[i][k]];
if(numClassePerso[i][k]!=-1) if(numClassePerso[i][k]!=-1)
{ {
...@@ -495,6 +486,26 @@ int affichage_menu_configuration() ...@@ -495,6 +486,26 @@ int affichage_menu_configuration()
p=0; p=0;
j=0; j=0;
} }
TTF_CloseFont(police);
TTF_CloseFont(petite_police);
SDL_FreeSurface(ecran);
SDL_FreeSurface(map_choisie);
SDL_FreeSurface(texte);
SDL_FreeSurface(texte2);
SDL_FreeSurface(texte3);
for(i=0;i<5;i++){
SDL_FreeSurface(previsualisation[i]);
}
for(i=0;i<NB_PERSO;i++){
for(k=0;k<NB_JOUEURS;k++){
SDL_FreeSurface(textes[i*k]);
SDL_FreeSurface(images_persos[i][k]);
}
}
for(i=0;i<nbClasses();i++){
SDL_FreeSurface(images_classes[i]);
}
return 0; return 0;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#define LARGEUR_CASE 53 #define LARGEUR_CASE 53
#define HAUTEUR_CASE 71 #define HAUTEUR_CASE 71
#define NB_PERSO 3 #define NB_PERSO 3
#define NB_JOUEURS 3
#define HAUTEUR_BOUTON 20 #define HAUTEUR_BOUTON 20
#define LARGEUR_BOUTON 115 #define LARGEUR_BOUTON 115
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment