#include #include #include #include "structures.h" #include "constantes.h" #include "prototypes.h" #include #include #include "players.h" static struct team_t *new_ally_team(SURFACES *surfaces, const enum character_class_t *classes, int cnt) { struct team_t *team = malloc(sizeof(struct team_t)); team->name = "Team Player"; team->cpu = false; team->chr_cnt = cnt; team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); for (int i = 0; i < team->chr_cnt; i++) { struct character_t *chr = &team->chrs[i]; chr->name = "Player"; chr->cpu = false; chr->team = team; chr->class_ = classes[i]; chr->alive = true; switch (chr->class_) { case CLASS_PALADIN: chr->def_surf = surfaces->Ppaladin; chr->red_surf = surfaces->red_paladin; break; case CLASS_PRIEST: chr->def_surf = surfaces->Ppretre; chr->red_surf = surfaces->red_priest; break; case CLASS_THIEF: chr->def_surf = surfaces->Pvoleur; chr->red_surf = surfaces->red_thief; break; default: abort(); } chr->surf = chr->def_surf; chr->hp = base_stats_g[chr->class_].hp; chr->max_hp = base_stats_g[chr->class_].hp; chr->mp = base_stats_g[chr->class_].mp; chr->max_mp = base_stats_g[chr->class_].mp; chr->magic = base_stats_g[chr->class_].magic; chr->strength = base_stats_g[chr->class_].strength; chr->defense = base_stats_g[chr->class_].defense; chr->spirit = base_stats_g[chr->class_].spirit; /* set its position */ chr->pos.x = 20; chr->pos.y = (YWIN / (cnt + 1)) * (i + 1) - chr->def_surf->h / 2; } return team; } void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) { TTF_Font *police = NULL; int Vchoix = PALADIN; SDL_Color vert; bool continuer = true; struct team_t *ally_team; enum character_class_t chr_classes[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: chr_classes[Vnbperso++] = Vchoix; continuer = false; break; default: break; } break; } } } TTF_CloseFont (police); SDL_Flip(surfaces->Pecran); ally_team = new_ally_team(surfaces, chr_classes, 3); Fmap(surfaces,positions, ally_team,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 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; }