Newer
Older
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include "affichage.h"
#include "controleur.h"
/*!
* \file affichage.c
* \brief Fichier contenant le code des fonctions liees l'affichage par la SDL.
*/
EtatsJeu etat;
char* nom_1;
char* nom_2;
/*!
* \fn int main_affichage()
* \brief Fonction principale de la partie affichage, elle appelle les autres en fonction de l'etat du jeu
*
*/
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=SAISIE_JOUEURS; /*lance le jeu l'ecran "entrer nom joueur 1"*/
if (SDL_Init(SDL_INIT_VIDEO)<0) /*initialisation de la SDL*/
{
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
if(TTF_Init()==-1) /*initialisation de SDL_ttf (affichage de texte)*/
{
fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
exit(EXIT_FAILURE);
}
while(etat!=FERMER)
{
switch(etat)
{
case SAISIE_JOUEURS:
saisie_noms_joueurs();
break;
case LANCEMENT:
affichage_ecran_accueil();
break;
case CONFIGURATION:
affichage_menu_configuration();
break;
case TOUR_J1P1:
affichage_carte();
break;
default:
break;
}
}
SDL_Quit();
return 0;
}
/*!
* \fn int perso_suivant(int numPerso)
* \brief permet de changer de personnage
*
* \param le numro du personnage actuel (1,2, ou 3 pour le 1er joueur, 4,5, ou 6 pour le 2eme)
* \return le numro du personnage suivant (respectivement 2,3,1 et 5,6,4)
*/
int perso_suivant(int numPerso)
{
if (numPerso==NB_PERSO) numPerso=1;
else if (numPerso==NB_PERSO*2) numPerso=NB_PERSO+1;
else numPerso++;
return numPerso;
/*!
* \fn int actualiser_num_perso(int numPerso)
* \brief permet de changer le personnage actuel lorsqu'on change de joueur
*
* \param le numro du personnage actuel (1,2,3 pour le 1er joueur, 4,5,6 pour le 2eme)
* \return le numro du 1er personnage du joueur suivant (4 ou 1)
*/
int actualiser_num_perso(int numPerso)
{
if (numPerso<=NB_PERSO) numPerso=NB_PERSO+1;
else numPerso=1;
return numPerso;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*!
* \fn int afficher_cartes_personnalisees()
* \brief Fonction permettant le choix d'une carte personnalisee (cd qui n'est pas l'une des 4 previsualisees) par le joueur
* elle affiche leur nom, et leur description
*
* \return le numero de la carte choisie (ou -2 si l'utilisateur ferme la fenetre)
*/
int afficher_cartes_personnalisees()
{
int i;
int c=-1;
int nbChoix=nbCartes()-4;
SDL_Surface* fenetre=NULL;
SDL_Surface* textes[nbChoix];
SDL_Surface* desc[nbChoix];
SDL_Rect positionsTextes[nbChoix];
SDL_Rect positionsDesc[nbChoix];
SDL_Event event;
SDL_Color couleurNoire = {0, 0, 0};
SDL_Color couleurBlanche = {255, 255, 255};
TTF_Font* police=TTF_OpenFont("../resources/fonts/arial.ttf",40);
TTF_Font* petite_police=TTF_OpenFont("../resources/fonts/arial.ttf",22);
for(i=0; i<nbChoix; i++)
{
textes[i]=TTF_RenderText_Shaded(police, obtenirNomsCartes()[i+4], couleurBlanche,couleurNoire);
desc[i]=TTF_RenderText_Shaded(petite_police, obtenirDescriptionCarte()[i+4], couleurBlanche,couleurNoire);
positionsTextes[i].x=0;
positionsDesc[i].x=0;
positionsTextes[i].y=i*(textes[0]->h+desc[0]->h+5);
positionsDesc[i].y=positionsTextes[i].y+textes[i]->h;
}
fenetre = SDL_SetVideoMode(400, nbChoix*(textes[0]->h+desc[0]->h), 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
while(c==-1)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
c=-2;
break;
case SDL_MOUSEBUTTONDOWN:
for(i=0; i<nbChoix; i++)
{
if(event.button.y/(textes[0]->h+desc[0]->h)==i)
{
c=4+i;
}
}
break;
default:
break;
}
for(i=0; i<nbChoix; i++)
{
SDL_BlitSurface(textes[i],NULL,fenetre,&positionsTextes[i]);
SDL_BlitSurface(desc[i],NULL,fenetre,&positionsDesc[i]);
}
SDL_Flip(fenetre);
}
SDL_FreeSurface(fenetre);
for(i=0; i<nbChoix; i++)
{
SDL_FreeSurface(textes[i]);
SDL_FreeSurface(desc[i]);
}
TTF_CloseFont(police);
TTF_CloseFont(petite_police);
return c;
}
* \fn char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix)
* \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 adresses de leurs images, et le nombre de classes
* \return le nom de la classe choisie (ou "fermer" si l'utilisateur ferme la fenetre)
char* afficherListeClasses(char** nomsClasses, char** skinsClasses, int nbChoix)
{
int i, quitter;
char* classeChoisie;
SDL_Surface* fenetre=NULL;
SDL_Event event;
SDL_Surface* tabTextes[nbChoix];
SDL_Surface* tabSkins[nbChoix];
SDL_Rect positionsTextes[nbChoix];
SDL_Rect positionsSkins[nbChoix];
SDL_Color couleurNoire = {0, 0, 0};
SDL_Color couleurTexte = {255,255,255};
TTF_Font* police = TTF_OpenFont("../resources/fonts/arial.ttf",26);
for(i=0; i<nbChoix; i++)
{
tabSkins[i]=SDL_LoadBMP(skinsClasses[i]);
if (!tabSkins[i])
{
printf("Unable to load bitmap: %s\n", skinsClasses[i]);
return NULL;
}
SDL_SetColorKey(tabSkins[i], SDL_SRCCOLORKEY, SDL_MapRGB(tabSkins[i]->format, 0, 0, 255));
}
fenetre = SDL_SetVideoMode(260, nbChoix*tabSkins[0]->h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
SDL_FillRect(fenetre,NULL,SDL_MapRGB(fenetre->format,0,0,0));
quitter=0;
while(quitter==0)
{
SDL_WaitEvent(&event);
switch(event.type)
{
classeChoisie= "fermer";
quitter=1;
break;
case SDL_MOUSEBUTTONDOWN:
for(i=0; i<nbChoix; i++)
{
if(event.button.y/positionsSkins[0].h==i)
{
classeChoisie=nomsClasses[i];
quitter=1;
}
}
break;
default:
break;
for(i=0; i<nbChoix; i++)
{
tabTextes[i]=TTF_RenderText_Shaded(police, nomsClasses[i], couleurTexte,couleurNoire);
positionsSkins[i].y=i*tabSkins[0]->h;
positionsSkins[i].x=0;
positionsTextes[i].x=tabSkins[i]->w+4;
positionsTextes[i].y=positionsSkins[i].y+(tabSkins[i]->h/3);
SDL_BlitSurface(tabTextes[i],NULL,fenetre,&positionsTextes[i]);
SDL_BlitSurface(tabSkins[i],NULL,fenetre,&positionsSkins[i]);
}
SDL_Flip(fenetre);
}
for(i=0; i<nbChoix; i++)
{
SDL_FreeSurface(tabTextes[i]);
SDL_FreeSurface(tabSkins[i]);
}
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
return classeChoisie;
}
/*!
* \fn int saisie_noms_joueurs()
* \brief fonction qui gre l'affichage de l'ecran de saisie des noms des joueurs
*/
int saisie_noms_joueurs()
{
SDL_Surface* ecran=NULL;
SDL_Surface* logo = NULL;
SDL_Surface* texte = NULL;
SDL_Rect pos_logo;
SDL_Rect pos_texte;
TTF_Font *police = NULL;
SDL_Color couleurNoire = {0, 0, 0};
SDL_Color couleurBlanche = {255, 255, 255};
etat=SAISIE_JOUEURS;
police=TTF_OpenFont("../resources/fonts/arial.ttf",26);
ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
if (ecran == NULL) // Si l'ouverture a chou, on le note et on arrte
{
fprintf(stderr, "Impossible de charger le mode vido : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("Elder Internal Ignition",NULL);
texte = TTF_RenderText_Shaded(police, "Entrez le nom du joueur 1", couleurBlanche,couleurNoire);
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
logo = SDL_LoadBMP("../resources/Skins/logo.bmp");
if (!logo)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
pos_logo.x=(ecran->w-logo->w)/2;
pos_logo.y=0;
pos_texte.x=(ecran->w-texte->w)/2;
pos_texte.y=ecran->h-200;
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_BlitSurface(logo,NULL,ecran,&pos_logo);
SDL_Flip(ecran);
char nom_joueur1[TAILLE_NOMS] = "";
fgets(nom_joueur1, sizeof(nom_joueur1), stdin);
if(strlen(nom_joueur1)>TAILLE_NOMS-2)
{
if(strlen(nom_joueur1)>1)
{
nom_joueur1[strlen(nom_joueur1)-1]=NULL;
}
char nom_joueur2[TAILLE_NOMS] = "";
texte = TTF_RenderText_Shaded(police, "Entrez le nom du joueur 2", couleurBlanche,couleurNoire);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_Flip(ecran);
fgets(nom_joueur2, sizeof(nom_joueur2), stdin);
if(strlen(nom_joueur1)>TAILLE_NOMS-2)
{
if(strlen(nom_joueur2)>1)
{
nom_joueur2[strlen(nom_joueur2)-1]=NULL;
}
TTF_CloseFont(police);
SDL_FreeSurface(ecran);
SDL_FreeSurface(logo);
SDL_FreeSurface(texte);
* \fn int affichage_ecran_accueil()
* \brief fonction qui gre l'affichage de l'ecran d'accueil (logo + bouton de lancement)
*/
int affichage_ecran_accueil()
{
ajouterUnJoueur(nom_2,&etat);
ajouterUnJoueur(nom_1,&etat);
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
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_Event event;
SDL_Surface* logo = NULL;
SDL_Surface* texte = NULL;
TTF_Font *police = NULL;
SDL_Rect pos_logo;
SDL_Rect pos_texte;
SDL_Color couleurBleue = {10, 30, 80};
SDL_Color couleurDoree = {190, 190, 120};
police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",40);
texte = TTF_RenderText_Shaded(police, "Entrez dans le Royaume !", couleurDoree,couleurBleue);
pos_texte.x=(ecran->w-texte->w)/2;
pos_texte.y=ecran->h-200;
logo = SDL_LoadBMP("../resources/Skins/logo.bmp");
if (!logo)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
pos_logo.x=(ecran->w-logo->w)/2;
pos_logo.y=0;
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
SDL_BlitSurface(logo,NULL,ecran,&pos_logo);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_Flip(ecran);
while(etat==LANCEMENT)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
etat=FERMER;
break;
case SDL_MOUSEBUTTONDOWN:
if (event.button.x<pos_texte.x+texte->w&&event.button.x>pos_texte.x&&event.button.y<pos_texte.y+texte->h&&event.button.y>pos_texte.y)
{
etat=CONFIGURATION;
}
break;
default:
break;
}
SDL_BlitSurface(logo,NULL,ecran,&pos_logo);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_Flip(ecran);
}
TTF_CloseFont(police);
SDL_FreeSurface(ecran);
SDL_FreeSurface(logo);
SDL_FreeSurface(texte);
return 0;
}
/*!
* \fn int affichage_menu_configuration()
* \brief fonction qui gre l'affichage de l'ecran de configuration de la partie (choix de la carte et des personnages)
*/
int affichage_menu_configuration()
{
etat=CONFIGURATION;
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_Event event;
SDL_Surface* map_choisie = NULL;
SDL_Surface* texte = NULL;
SDL_Surface* texte2 = NULL;
SDL_Surface* texte3 = NULL;
SDL_Surface* previsualisation[5]= {NULL};
SDL_Surface* textes[NB_JOUEURS*NB_PERSO]= {NULL};
SDL_Surface* images_classes[nombre_classes];
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_texte2;
SDL_Rect pos_texte3;
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 couleurBlanche = {255, 255, 255};
SDL_Color couleurBleue = {10, 30, 80};
SDL_Color couleurDoree = {190, 190, 120};
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",46);
petite_police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",32);
lancer_partie= TTF_RenderText_Shaded(police, "Lancer la partie", couleurDoree, couleurBleue);
pos_bouton.y=ecran->h-lancer_partie->h-25;
pos_bouton.x=(ecran->w-lancer_partie->w)/2;
texte= TTF_RenderText_Shaded(police, nom_1, couleurBlanche,couleurNoire);
texte2= TTF_RenderText_Shaded(police, nom_2, couleurBlanche, couleurNoire);
texte3= TTF_RenderText_Shaded(petite_police, "Choisissez vos personnages", couleurBlanche, couleurNoire);
pos_texte.x=ecran->w/4-texte->w/2;
pos_texte.y=10;
pos_texte2.x=(3*ecran->w)/4-texte2->w/2;
pos_texte2.y=10;
pos_texte3.x=pos_texte.x-(texte3->w-texte->w)/2;
pos_texte3.y=pos_texte.y+(3*texte3->h)/2;
pos_texte3_bis.x=pos_texte2.x-(texte3->w-texte2->w)/2;
pos_texte3_bis.y=pos_texte2.y+(3*texte3->h)/2;
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2);
SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3);
SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis);
police=TTF_OpenFont("../resources/fonts/arial.ttf",26);
for(i=0; i<NB_PERSO; i++)

Sanchez Alexandre
committed
sprintf(src, "%d", i+1);
textes[i]= TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire);
posTextes[i].x=ecran->w/4-textes[i]->w/2;
SDL_BlitSurface(textes[i],NULL,ecran,&(posTextes[i]));
for(i=NB_PERSO; i<NB_JOUEURS*NB_PERSO; i++)

Sanchez Alexandre
committed
sprintf(src, "%d", i-NB_PERSO+1);
textes[i]= TTF_RenderText_Shaded(police, strcat(dest, src), couleurBlanche,couleurNoire);
posTextes[i].x=(3*ecran->w)/4-textes[i]->w/2;
posTextes[i].y=posTextes[i-NB_PERSO].y;
SDL_BlitSurface(textes[i],NULL,ecran,&posTextes[i]);
int numClassePerso[NB_PERSO][NB_JOUEURS]= {{-1,-1},{-1,-1},{-1,-1}};
j=0; /*numero du joeuur*/
p=0; /*numero du personnage*/
for(i=0; i<nombre_classes; i++)
{
images_classes[i]=SDL_LoadBMP(path_images[i]);
if (!images_classes[i])
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(images_classes[i], SDL_SRCCOLORKEY, SDL_MapRGB(images_classes[i]->format, 0, 0, 255));
}
map_choisie=SDL_LoadBMP("../resources/Skins/Map_select.bmp");
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(map_choisie, SDL_SRCCOLORKEY, SDL_MapRGB(map_choisie->format, 0, 0, 255));
path[0]="../resources/Skins/Map_1.bmp"; //a revoir : cela peut se trouver dans le XML
path[1]="../resources/Skins/Map_2.bmp";
path[2]="../resources/Skins/Map_3.bmp";
path[3]="../resources/Skins/Map_4.bmp";
path[4]="../resources/Skins/autre_map.bmp";
{
previsualisation[i]=SDL_LoadBMP(path[i]);
if (!previsualisation[i])
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
position_carte[i].y=(ecran->h)-(previsualisation[i]->h+100);
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)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
etat=FERMER;
return 0;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.x>pos_bouton.x&&event.button.x<pos_bouton.x+lancer_partie->w&&event.button.y>pos_bouton.y&&event.button.y<pos_bouton.y+lancer_partie->h)
{
for(i=0; i<NB_PERSO; i++)
{
for(k=0; k<NB_JOUEURS; k++)
{
if(numClassePerso[i][k]==-1)
{
p=-1;
printf("Choisissez une carte\n");
printf("Selectionnez des personnages\n");
}
for(i=0; i<5; i++)
{
if(event.button.x>position_carte[i].x&&event.button.x<position_carte[i].x+previsualisation[0]->w&&event.button.y>position_carte[i].y&&event.button.y<position_carte[i].y+previsualisation[0]->h)
{
if(i!=4)
{
c=i;
selectionnerCarte(obtenirNomsCartes()[c]);
}
else
{
c=afficher_cartes_personnalisees();
selectionnerCarte(obtenirNomsCartes()[c]);
}
ecran = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
}
}
}
if(event.button.x>posTextes[0].x&&event.button.x<posTextes[0].x+textes[0]->w)
j=1;
if(event.button.x>posTextes[NB_PERSO].x&&event.button.x<posTextes[NB_PERSO].x+textes[NB_PERSO]->w)
j=2;
for(i=0; i<NB_PERSO; i++)
{
if(event.button.y>posTextes[i].y&&event.button.y<posTextes[i].y+textes[i]->h)
p=i+1;
}
if(j!=0&&p!=0)
{
classeChoisie=afficherListeClasses(obtenirNomsClasses(), obtenirSkinsClasses(), nombre_classes);
if(classeChoisie!="fermer")
{
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);
}
break;
default:
break;
for(i=0; i<NB_JOUEURS*NB_PERSO; i++)
{
SDL_BlitSurface(textes[i],NULL,ecran,&(posTextes[i]));
for(i=0; i<NB_PERSO; i++)
{
for(k=0; k<NB_JOUEURS; k++)
{
positions_images[i][k].y=posTextes[i].y+textes[i]->h;
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]];
if(numClassePerso[i][k]!=-1)
{
SDL_BlitSurface(images_persos[i][k],NULL,ecran,&positions_images[i][k]);
}
}
}
SDL_BlitSurface(lancer_partie,NULL,ecran,&pos_bouton);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_BlitSurface(texte2,NULL,ecran,&pos_texte2);
SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3);
SDL_BlitSurface(texte3,NULL,ecran,&pos_texte3_bis);
{
SDL_BlitSurface(previsualisation[i],NULL,ecran,&position_carte[i]);
}
if(c>-1&&c<4) SDL_BlitSurface(map_choisie,NULL,ecran,&position_carte[c]);
if(c>3) SDL_BlitSurface(map_choisie,NULL,ecran,&position_carte[4]);
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*NB_JOUEURS; i++)
{
for(i=0; i<nombre_classes; i++)
{
SDL_FreeSurface(images_classes[i]);
}
* \fn int affichage_carte()
* \brief fonction qui gre l'affichage pendant la partie (carte, personnages, PV, etc)
int affichage_carte()
SDL_Surface* ecran=SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE)+LARGEUR_BORDURE, HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);;
SDL_Surface* cases[HAUTEUR_CARTE][LARGEUR_CARTE];
SDL_Surface* persos[NB_PERSO*NB_JOUEURS];
SDL_Rect Position_Case[HAUTEUR_CARTE][LARGEUR_CARTE];
SDL_Rect Position_Perso[NB_PERSO*NB_JOUEURS];
SDL_Surface* perso; //surfaces affichees sur le cote
SDL_Surface* texte = NULL;
SDL_Surface* nom_joueur = NULL;
SDL_Surface* bouton1 = NULL;
SDL_Surface* bouton2 = NULL;
Lénaïg Le Moigne
committed
SDL_Surface* personnage_numero = NULL;
SDL_Surface* nombre_deplacement = NULL;
SDL_Rect pos_texte;
SDL_Rect pos_nom_joueur;
SDL_Rect pos_bouton1;
SDL_Rect pos_bouton2;
Lénaïg Le Moigne
committed
SDL_Rect pos_personnage_numero;
SDL_Rect pos_nombre_deplacement;
Lénaïg Le Moigne
committed
TTF_Font *vieille_police = NULL;
SDL_Color couleurNoire = {0, 0, 0};
SDL_Color couleurBlanche = {255, 255, 255};
SDL_Color couleurBleue = {10, 30, 80};
SDL_Color couleurDoree = {190, 190, 120};
vieille_police=TTF_OpenFont("../resources/fonts/OLDENGL.ttf",30);
police_arial=TTF_OpenFont("../resources/fonts/arial.ttf",22);
texte= TTF_RenderText_Shaded(vieille_police, "Joueur actuel :", couleurBlanche,couleurNoire);
nom_joueur= TTF_RenderText_Shaded(vieille_police, obtenirNomJoueurCourant(), couleurBlanche, couleurNoire);
bouton1= TTF_RenderText_Shaded(vieille_police, "Perso suivant", couleurDoree, couleurBleue);
bouton2= TTF_RenderText_Shaded(vieille_police, "Joueur suivant", couleurDoree, couleurBleue);
char buffer_PV[40];
sprintf(buffer_PV, "PV: %d/%d", obtenirPVPersonnage(perso_actuel),obtenirPVMaxPersonnage(perso_actuel));
PV=TTF_RenderText_Shaded(vieille_police, buffer_PV, couleurBlanche, couleurNoire);
sprintf(buffer_PV, "Mana: %d/%d", obtenirManaPersonnage(perso_actuel),obtenirManaMaxPersonnage(perso_actuel));
mana=TTF_RenderText_Shaded(vieille_police, buffer_PV, couleurBlanche, couleurNoire);
sprintf(buffer_PV, "Personnage %d", perso_actuel-NB_PERSO);
Lénaïg Le Moigne
committed
personnage_numero=TTF_RenderText_Shaded(police_arial, buffer_PV, couleurBlanche, couleurNoire);
sprintf(buffer_PV, "Deplacement : %d", obtenirPDPersonnage(perso_actuel));
nombre_deplacement=TTF_RenderText_Shaded(police_arial, buffer_PV, couleurBlanche, couleurNoire);
pos_texte.x=ecran->w-(LARGEUR_BORDURE+texte->w)/2;
pos_nom_joueur.x=ecran->w-(LARGEUR_BORDURE+nom_joueur->w)/2;
pos_nom_joueur.y=pos_texte.y+(3*texte->h)/2;
pos_bouton2.x=ecran->w-(LARGEUR_BORDURE+bouton2->w)/2;
pos_bouton2.y=ecran->h-bouton2->h-40;
pos_bouton1.x=ecran->w-(LARGEUR_BORDURE+bouton1->w)/2;
pos_bouton1.y=pos_bouton2.y-(2*bouton2->h);
pos_PV.x=ecran->w-(LARGEUR_BORDURE+PV->w)/2;
pos_PV.y=pos_nom_joueur.y+(2*nom_joueur->h);
pos_mana.x=ecran->w-(LARGEUR_BORDURE+mana->w)/2.1;
pos_perso.x=ecran->w-(LARGEUR_BORDURE+texte->w)/2.7;
Lénaïg Le Moigne
committed
pos_perso.y=pos_mana.y+(1*mana->h);
pos_personnage_numero.x=ecran->w-(LARGEUR_BORDURE+mana->w)/2.4;
Lénaïg Le Moigne
committed
pos_personnage_numero.y=pos_perso.y+(2*PV->h);
pos_nombre_deplacement.x=ecran->w-(LARGEUR_BORDURE+mana->w)/2.4;
Lénaïg Le Moigne
committed
pos_nombre_deplacement.y=pos_personnage_numero.y+(1.1*PV->h);
pos_nombre_deplacement.y=pos_personnage_numero.y+(1*PV->h);
for(i=0; i<LARGEUR_CARTE; i++)
{
for(j=0; j<HAUTEUR_CARTE; j++)
cases[j][i]=SDL_LoadBMP(ObtenirRessourceTerrain(i,j));
if (!cases[j][i])
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(cases[j][i], SDL_SRCCOLORKEY, SDL_MapRGB(cases[j][i]->format, 0, 0, 255));
}
{
persos[i]=SDL_LoadBMP(obtenirRessourcePersonnageNum(i+1));
if (!persos[i])
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey( persos[i], SDL_SRCCOLORKEY, SDL_MapRGB( persos[i]->format, 0, 0, 255));
}
perso=persos[perso_actuel-1];
perso_select = SDL_LoadBMP("../resources/Skins/guerrier_select.bmp");
if (!perso_select)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(perso_select, SDL_SRCCOLORKEY, SDL_MapRGB(perso_select->format, 0, 0, 255));
Case_brillante = SDL_LoadBMP("../resources/Skins/case_brillante.bmp");
if (!Case_brillante)
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
SDL_SetColorKey(Case_brillante, SDL_SRCCOLORKEY, SDL_MapRGB(Case_brillante->format, 0, 0, 255));
for(j=0; j<HAUTEUR_CARTE; j++)
for(i=0; i<LARGEUR_CARTE; i+=2)
{
Position_Case[j][i].x=i*LARGEUR_CASE;
Position_Case[j][i].y=j*HAUTEUR_CASE;
}
for(i=1; i<LARGEUR_CARTE; i+=2)
{
Position_Case[j][i].x=i*LARGEUR_CASE;
Position_Case[j][i].y=j*HAUTEUR_CASE+(HAUTEUR_CASE/2);
}
switch(event.type) /* Test du type d'vnement */
{
case SDL_QUIT: /* Si c'est un vnement de type "Quitter" */
etat=FERMER;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.y>pos_bouton1.y&&event.button.y<pos_bouton1.y+bouton1->h&&event.button.x>LARGEUR_CARTE*LARGEUR_CASE)
sprintf(buffer_PV, "PV: %d/%d", obtenirPVPersonnage(perso_actuel),obtenirPVMaxPersonnage(perso_actuel));
PV=TTF_RenderText_Shaded(vieille_police, buffer_PV, couleurBlanche, couleurNoire);
sprintf(buffer_PV, "Mana: %d/%d", obtenirManaPersonnage(perso_actuel),obtenirManaMaxPersonnage(perso_actuel));
mana=TTF_RenderText_Shaded(vieille_police, buffer_PV, couleurBlanche, couleurNoire);
Lénaïg Le Moigne
committed
if(perso_actuel <=3){
sprintf(buffer_PV, "Personnage %d", perso_actuel);
Lénaïg Le Moigne
committed
personnage_numero=TTF_RenderText_Shaded(police_arial, buffer_PV, couleurBlanche, couleurNoire);
}else{
sprintf(buffer_PV, "Personnage %d", perso_actuel-NB_PERSO);
Lénaïg Le Moigne
committed
personnage_numero=TTF_RenderText_Shaded(police_arial, buffer_PV, couleurBlanche, couleurNoire);
perso=persos[perso_actuel-1];
if(event.button.y>pos_bouton2.y&&event.button.y<pos_bouton2.y+bouton2->h&&event.button.x>LARGEUR_CARTE*LARGEUR_CASE)
finDuTour();
debutDuTour();
nom_joueur= TTF_RenderText_Shaded(vieille_police, obtenirNomJoueurCourant(), couleurBlanche, couleurNoire);
perso_actuel=actualiser_num_perso(perso_actuel);
sprintf(buffer_PV, "PV: %d/%d", obtenirPVPersonnage(perso_actuel),obtenirPVMaxPersonnage(perso_actuel));
PV=TTF_RenderText_Shaded(vieille_police, buffer_PV, couleurBlanche, couleurNoire);
sprintf(buffer_PV, "Mana: %d/%d", obtenirManaPersonnage(perso_actuel),obtenirManaMaxPersonnage(perso_actuel));
mana=TTF_RenderText_Shaded(vieille_police, buffer_PV, couleurBlanche, couleurNoire);
Lénaïg Le Moigne
committed
if(perso_actuel <=3){
sprintf(buffer_PV, "Personnage %d", perso_actuel);
Lénaïg Le Moigne
committed
personnage_numero=TTF_RenderText_Shaded(police_arial, buffer_PV, couleurBlanche, couleurNoire);
}else{
sprintf(buffer_PV, "Personnage %d", perso_actuel-NB_PERSO);
Lénaïg Le Moigne
committed
personnage_numero=TTF_RenderText_Shaded(police_arial, buffer_PV, couleurBlanche, couleurNoire);
perso=persos[perso_actuel-1];
if(event.button.x<LARGEUR_CARTE*LARGEUR_CASE)
{
deplacement_personnage(perso_actuel,event.button.x,event.button.y);
break;
case SDL_MOUSEMOTION:
if(event.motion.x<LARGEUR_CARTE*LARGEUR_CASE&&event.motion.y<HAUTEUR_CARTE*HAUTEUR_CASE)
{
Position_Case_brillante = Position_Case[y_case_cliquee(event.motion.x,event.motion.y)][x_case_cliquee(event.motion.x,event.motion.y)];
}
break;
case SDL_KEYDOWN:/* Si c'est un vnement de type "touche presse" */
switch(event.key.keysym.sym)
{
case SDLK_ESCAPE:
break;
default:
for(i=0; i<NB_PERSO*NB_JOUEURS; i++)
Position_Perso[i].x=x*LARGEUR_CASE;
Position_Perso[i].y=y*HAUTEUR_CASE;
for(j=1; j<LARGEUR_CARTE; j+=2)
{
if(x==j)
{
Position_Perso[i].y=y*HAUTEUR_CASE+(HAUTEUR_CASE/2);
}
}
for(i=0; i<LARGEUR_CARTE; i++)
for(j=0; j<HAUTEUR_CARTE; j++)
{
SDL_BlitSurface(cases[j][i],NULL,ecran,&Position_Case[j][i]);
}
for(i=0; i<NB_PERSO*NB_JOUEURS; i++)
{
SDL_BlitSurface(persos[i],NULL,ecran,&Position_Perso[i]);
sprintf(buffer_PV, "Deplacement : %d", obtenirPDPersonnage(perso_actuel));
nombre_deplacement=TTF_RenderText_Shaded(police_arial, buffer_PV, couleurBlanche, couleurNoire);
SDL_BlitSurface(perso_select,NULL,ecran,&Position_Perso[perso_actuel-1]);
SDL_BlitSurface(Case_brillante,NULL,ecran,&Position_Case_brillante);
SDL_BlitSurface(texte,NULL,ecran,&pos_texte);
SDL_BlitSurface(nom_joueur,NULL,ecran,&pos_nom_joueur);
SDL_BlitSurface(bouton1,NULL,ecran,&pos_bouton1);
SDL_BlitSurface(bouton2,NULL,ecran,&pos_bouton2);
SDL_BlitSurface(perso,NULL,ecran,&pos_perso);
Lénaïg Le Moigne
committed
SDL_BlitSurface(personnage_numero,NULL,ecran,&pos_personnage_numero);
SDL_BlitSurface(nombre_deplacement,NULL,ecran,&pos_nombre_deplacement);
for(i=0; i<HAUTEUR_CARTE; i++)
{
for(j=0; j<LARGEUR_CARTE; j++)
{
SDL_FreeSurface(cases[i][j]);
}
for(i=0; i<NB_PERSO*NB_JOUEURS; i++)
{
SDL_FreeSurface(persos[i]);
}
SDL_FreeSurface(Case_brillante);
SDL_FreeSurface(bouton1);
SDL_FreeSurface(bouton2);
SDL_FreeSurface(ecran);
SDL_FreeSurface(personnage_numero);
SDL_FreeSurface(nombre_deplacement);
TTF_CloseFont(police_arial);
etat=FERMER;
return 0;
/*!
* \fn int afficher_menu()
* \brief fonction qui gre l'affichage du menu
*
*/
int afficher_menu()
{
SDL_Event event;
SDL_Surface* fenetre = SDL_SetVideoMode(LARGEUR_CARTE*(LARGEUR_CASE+1), HAUTEUR_CARTE*(HAUTEUR_CASE+2), 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_Surface* bouton_continuer=NULL;
SDL_Surface* bouton_quitter=NULL;
SDL_Rect pos_bouton_continuer;
SDL_Rect pos_bouton_quitter;
pos_bouton_quitter.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2;
pos_bouton_continuer.x=(LARGEUR_CARTE*LARGEUR_CASE-LARGEUR_BOUTON)/2;
pos_bouton_quitter.y=(HAUTEUR_CARTE*HAUTEUR_CASE-HAUTEUR_BOUTON)/2+HAUTEUR_BOUTON;
pos_bouton_continuer.y=(HAUTEUR_CARTE*HAUTEUR_CASE-HAUTEUR_BOUTON)/2-HAUTEUR_BOUTON;
bouton_continuer = SDL_LoadBMP("../resources/Skins/continuer.bmp");
if (!bouton_continuer)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
bouton_quitter = SDL_LoadBMP("../resources/Skins/quitter.bmp");
if (!bouton_continuer)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
while(etat!=FERMER)
{
switch(event.type) /* Test du type d'vnement */
{
case SDL_QUIT: /* Si c'est un vnement de type "Quitter" */
break;
case SDL_MOUSEBUTTONDOWN:
if(pos_bouton_continuer.x<event.button.x&&event.button.x<pos_bouton_continuer.x+LARGEUR_BOUTON)
{
if(pos_bouton_continuer.y<event.button.y&&event.button.y<pos_bouton_continuer.y+HAUTEUR_BOUTON)
{
return 0;
}