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

je commence a modifier le code que j'avais ecrit pour afficher la carte

parent 84ef91ec
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -533,158 +533,47 @@ int affichage_menu_configuration()
*/
int affichage_carte(char* Map)
{
int i,j,affichermenu;
SDL_Surface* ecran=NULL;
{/*
int i,j=0;
int nombre_classes=nbClasses();
int nombre_terrains=nbTerrains();
SDL_Event event;
SDL_Surface* guerrier=NULL;
SDL_Surface* mage=NULL;
SDL_Surface* voleur=NULL;
SDL_Surface* archer=NULL;
SDL_Surface* guerisseur=NULL;
SDL_Surface* plaine=NULL;
SDL_Surface* eau=NULL;
SDL_Surface* montagne=NULL;
SDL_Surface* foret=NULL;
SDL_Surface* bouton_continuer=NULL;
SDL_Surface* bouton_quitter=NULL;
SDL_Surface* ecran=NULL;
SDL_Surface* classes[nombre_classes];
SDL_Surface* terrains[nombre_terrains];
SDL_Surface* persos[NB_PERSO*NB_JOUEURS];
SDL_Surface* Case_brillante=NULL;
SDL_Surface* Guerrier_select=NULL;
SDL_Rect Position_Case[LARGEUR_CARTE*HAUTEUR_CARTE];
SDL_Rect Position_Perso[NB_PERSO];
SDL_Rect Position_Perso[NB_PERSO*NB_JOUEURS];
SDL_Rect Position_Case_brillante;
SDL_Rect Position_Guerrier_select;
SDL_Rect pos_bouton_continuer;
SDL_Rect pos_bouton_quitter;
int x_case_brillante;
int y_case_brillante;
int x_guerrier_select;
int y_guerrier_select;
int quitter=0;
affichermenu=0;
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
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);
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;
guerrier = SDL_LoadBMP("../resources/Skins/guerrier.bmp");
if (!guerrier)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(guerrier, SDL_SRCCOLORKEY, SDL_MapRGB(guerrier->format, 0, 0, 255));
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;
}
mage = SDL_LoadBMP("../resources/Skins/mage.bmp");
if (!mage)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(mage, SDL_SRCCOLORKEY, SDL_MapRGB(mage->format, 0, 0, 255));
voleur = SDL_LoadBMP("../resources/Skins/voleur.bmp");
if (!voleur)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(voleur, SDL_SRCCOLORKEY, SDL_MapRGB(voleur->format, 0, 0, 255));
archer = SDL_LoadBMP("../resources/Skins/archer.bmp");
if (!archer)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(archer, SDL_SRCCOLORKEY, SDL_MapRGB(archer->format, 0, 0, 255));
guerisseur = SDL_LoadBMP("../resources/Skins/guerisseur.bmp");
if (!guerisseur)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(guerisseur, SDL_SRCCOLORKEY, SDL_MapRGB(guerisseur->format, 0, 0, 255));
plaine = SDL_LoadBMP("../resources/Skins/plaine.bmp");
if (!plaine)
for(i=0;i<nbClasses();i++){
classes[i]=SDL_LoadBMP(obtenirSkinsClasses()[i]);
if (!classes[i])
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(plaine, SDL_SRCCOLORKEY, SDL_MapRGB(plaine->format, 0, 0, 255));
eau = SDL_LoadBMP("../resources/Skins/eau.bmp");
if (!eau)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(eau, SDL_SRCCOLORKEY, SDL_MapRGB(eau->format, 0, 0, 255));
montagne = SDL_LoadBMP("../resources/Skins/montagne.bmp");
if (!montagne)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(montagne, SDL_SRCCOLORKEY, SDL_MapRGB(montagne->format, 0, 0, 255));
foret = SDL_LoadBMP("../resources/Skins/foret.bmp");
if (!foret)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
SDL_SetColorKey(foret, SDL_SRCCOLORKEY, SDL_MapRGB(foret->format, 0, 0, 255));
SDL_SetColorKey(classes[i], SDL_SRCCOLORKEY, SDL_MapRGB(classes[i]->format, 0, 0, 255));
}
Case_brillante = SDL_LoadBMP("../resources/Skins/case_brillante.bmp");
if (!Case_brillante)
Guerrier_select = SDL_LoadBMP("../resources/Skins/guerrier_select.bmp");
if (!Guerrier_select)
{
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));
SDL_SetColorKey(Guerrier_select, SDL_SRCCOLORKEY, SDL_MapRGB(Guerrier_select->format, 0, 0, 255));
Guerrier_select = SDL_LoadBMP("../resources/Skins/guerrier_select.bmp");
if (!Guerrier_select)
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(Guerrier_select, SDL_SRCCOLORKEY, SDL_MapRGB(Guerrier_select->format, 0, 0, 255));
SDL_SetColorKey(Case_brillante, SDL_SRCCOLORKEY, SDL_MapRGB(Case_brillante->format, 0, 0, 255));
for(i=0;i<LARGEUR_CARTE;i+=2)
{
......@@ -703,43 +592,13 @@ int affichage_carte(char* Map)
}
}
init_controleur(Position_Case);
while(quitter==0)
while(etat!=FERMER&&etat!=VICTOIRE)
{
SDL_WaitEvent(&event);
if(affichermenu==1){
switch(event.type) /* Test du type d'vnement */
{
/* {
case SDL_QUIT: /* Si c'est un vnement de type "Quitter" */
quitter=1;
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.x+HAUTEUR_BOUTON){
affichermenu=0;
}
if(pos_bouton_quitter.y<event.button.y&&event.button.y<pos_bouton_quitter.x+HAUTEUR_BOUTON){
quitter=1;
}
}
break;
case SDL_KEYDOWN:/* Si c'est un vnement de type "touche presse" */
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
affichermenu=0;
break;
default:
quitter=0;
}
break;
}
}
else{
switch(event.type) /* Test du type d'vnement */
{
case SDL_QUIT: /* Si c'est un vnement de type "Quitter" */
quitter=1;
/* etat=FERMER;
break;
case SDL_MOUSEBUTTONDOWN:
deplacement_personnage(event.button.x,event.button.y);
......@@ -747,37 +606,31 @@ int affichage_carte(char* Map)
case SDL_MOUSEMOTION:
if(event.motion.x<LARGEUR_CARTE*LARGEUR_CASE&&event.motion.y<HAUTEUR_CARTE*HAUTEUR_CASE)
{
x_case_brillante = get_position_case_x(deplacement_brillance(event.motion.x,event.motion.y));
y_case_brillante = get_position_case_y(deplacement_brillance(event.motion.x,event.motion.y));
Position_Case_brillante.x = get_position_case_x(deplacement_brillance(event.motion.x,event.motion.y));
Position_Case_brillante.y = get_position_case_y(deplacement_brillance(event.motion.x,event.motion.y));
}
break;
case SDL_KEYDOWN:/* Si c'est un vnement de type "touche presse" */
switch(event.key.keysym.sym){
/* switch(event.key.keysym.sym){
case SDLK_n:
persosuivant();
break;
case SDLK_ESCAPE:
affichermenu=1;
afficher_menu();
break;
default:
quitter=0;
break;
}
break;
}
}
for(i=0;i<NB_PERSO;i++){
Position_Perso[i].x=get_position_perso_x(i);
Position_Perso[i].y=get_position_perso_y(i);
}
Position_Case_brillante.x=x_case_brillante;
Position_Case_brillante.y=y_case_brillante;
x_guerrier_select = get_position_case_x(&Position_Perso[persoactuel()]);
y_guerrier_select = get_position_case_y(&Position_Perso[persoactuel()]);
Position_Guerrier_select.x=x_guerrier_select;
Position_Guerrier_select.y=y_guerrier_select;
Position_Guerrier_select.x = get_position_case_x(&Position_Perso[persoactuel()]);
Position_Guerrier_select.y = get_position_case_y(&Position_Perso[persoactuel()]);
SDL_FillRect(ecran,NULL,SDL_MapRGB(ecran->format,0,0,0));
if(affichermenu==0)
{
for(i=0;i<LARGEUR_CARTE*HAUTEUR_CARTE;i++)
{
switch(Map[i])
......@@ -795,40 +648,81 @@ int affichage_carte(char* Map)
SDL_BlitSurface(montagne,NULL,ecran,&Position_Case[i]);
break;
default:
quitter=0;
break;
}
}
// for(i=0;i<NB_PERSO;i++)
// {
SDL_BlitSurface(guerisseur,NULL,ecran,&Position_Perso[0]);
SDL_BlitSurface(mage,NULL,ecran,&Position_Perso[1]);
SDL_BlitSurface(guerrier,NULL,ecran,&Position_Perso[2]);
// }
for(i=0;i<NB_PERSO*NB_JOUEURS;i++)
{
//TODO
}
SDL_BlitSurface(Guerrier_select,NULL,ecran,&Position_Guerrier_select);
SDL_BlitSurface(Case_brillante,NULL,ecran,&Position_Case_brillante);
}else{
SDL_BlitSurface(bouton_continuer,NULL,ecran,&pos_bouton_continuer);
SDL_BlitSurface(bouton_quitter,NULL,ecran,&pos_bouton_quitter);
}
}
SDL_Flip(ecran);
}
quitter=0;
SDL_FreeSurface(guerrier);
SDL_FreeSurface(Case_brillante);
SDL_FreeSurface(Guerrier_select);
SDL_FreeSurface(plaine);
SDL_FreeSurface(mage);
SDL_FreeSurface(voleur);
SDL_FreeSurface(archer);
SDL_FreeSurface(guerisseur);
SDL_FreeSurface(eau);
SDL_FreeSurface(montagne);
SDL_FreeSurface(foret);
SDL_Quit();
//free les surfaces*/
etat=FERMER;
return 0;
}
/*!
* \fn int afficher_menu()
* \brief fonction qui gre l'affichage du menu
*
*/
int afficher_menu()
{
SDL_Event event;
SDL_Surface* ecran = 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" */
etat=FERMER;
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.x+HAUTEUR_BOUTON){
return 0;
}
if(pos_bouton_quitter.y<event.button.y&&event.button.y<pos_bouton_quitter.x+HAUTEUR_BOUTON){
etat=FERMER;
}
}
break;
case SDL_KEYDOWN:/* Si c'est un vnement de type "touche presse" */
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
return 0;
break;
default:
break;
}
break;
}
}
//free les surfaces
return 0;
}
......@@ -26,5 +26,7 @@ int affichage_ecran_accueil();
int affichage_carte(char* Map);
int afficher_menu();
#endif
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