#include #include #include #include "structures.h" #include "constantes.h" #include "prototypes.h" #include #include void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) { TTF_Font *police = NULL; int Vchoix = PALADIN; SDL_Color vert; bool continuer = true; PERSONNAGES persos[3]; ENNEMIS ennemis[5]; SDL_Event event; int Vnbperso = 0; vert.r = 39; vert.g = 189; vert.b = 31; police = TTF_OpenFont ("TIMESI.TTF",36); /* loop until we have actually chosen our three characters */ while (Vnbperso < 3) { static const char *strings[] = { "Please choose the class of your first character", "Please choose the class of your second character", "Please choose the class of your third character", }; /* display the background with the selected text */ if (Vchoix == PALADIN) { SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); } else if (Vchoix == PRETRE) { SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); } else if (Vchoix == VOLEUR) { SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); } else { abort(); } /* display the string associated with the current character number (aka Please choose ...) */ surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police, strings[Vnbperso], vert); positions->Vpositiontextemenu.x=XWIN/2-surfaces->Ptextechoixmenu->w/2; SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); SDL_Flip (surfaces->Pecran); continuer = true; while (continuer) { SDL_WaitEvent (&event); switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_LEFT: case SDLK_h: if (Vchoix > PALADIN) { Vchoix--; } else { Vchoix=VOLEUR; } Fchangersurlignage2 (Vchoix,surfaces,positions); break; case SDLK_RIGHT: case SDLK_l: if (Vchoix < VOLEUR) { Vchoix++; } else { Vchoix = PALADIN; } Fchangersurlignage2 (Vchoix,surfaces,positions); break; case SDLK_RETURN: case SDLK_f: persos[Vnbperso++].classe = Vchoix; continuer = false; break; default: break; } break; } } } TTF_CloseFont (police); SDL_Flip(surfaces->Pecran); Fremplirpersos2 (surfaces,persos); Fmap(surfaces,positions,persos,ennemis); } void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) { if (Vchoix==PALADIN) SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); else if (Vchoix==PRETRE) SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); else if (Vchoix==VOLEUR) SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); SDL_Flip (surfaces->Pecran); } void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]) { int i; for (i = 0; i < 3; i++) { switch (persos[i].classe) { case PALADIN: surfaces->Tperso[i] = surfaces->Ppaladin; break; case PRETRE: surfaces->Tperso[i] = surfaces->Ppretre; break; case VOLEUR: surfaces->Tperso[i] = surfaces->Pvoleur; break; default: abort(); } } } void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]) { int i; for (i=0;i<=Vnbennemis;i++) { if (ennemis[i].classe==GUERRIER_GOBELIN) surfaces->Tennemi[i]=surfaces->Pgobelin; } } int Fcalculernbennemis () { int nb; nb=(rand()%(4-0+1))+0; return nb; }