#include #include #include #include "structures.h" #include "constantes.h" #include "prototypes.h" #include #include #include static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr) { TTF_Font *police=NULL; SDL_Color fg={132,215,107,0},bg={100,0,0,0}; char string[256]; SDL_Surface *surf_hp; SDL_Surface *surf_mp; police=TTF_OpenFont("TIMESBI.TTF",18); sprintf(string, "PV %d/%d ", chr->hp, chr->max_hp); surf_hp = TTF_RenderText_Shaded(police, string, fg, bg); sprintf(string, "PM %d/%d ", chr->mp, chr->max_mp); surf_mp = TTF_RenderText_Shaded(police, string, fg, bg); chr->pos_hp.x = chr->pos.x + chr->def_surf->w / 2 - surf_hp->w / 2; chr->pos_mp.x = chr->pos.x + chr->def_surf->w / 2 - surf_mp->w / 2; chr->pos_hp.y = chr->pos.y + chr->def_surf->h - surf_hp->h - surf_mp->h; chr->pos_mp.y = chr->pos_hp.y + surf_mp->h; SDL_BlitSurface(surf_hp, NULL, surfaces->Pecran, &chr->pos_hp); SDL_BlitSurface(surf_mp, NULL, surfaces->Pecran, &chr->pos_mp); chr->pos_hp.w = surf_hp->w; chr->pos_hp.h = surf_hp->h; chr->pos_mp.w = surf_mp->w; chr->pos_mp.h = surf_mp->h; SDL_FreeSurface(surf_hp); SDL_FreeSurface(surf_mp); TTF_CloseFont(police); } void blit_character(SURFACES *surfaces, struct character_t *chr) { SDL_BlitSurface(chr->surf, NULL, surfaces->Pecran, &chr->pos); if (!chr->alive) { SDL_Rect pos_dead; pos_dead.x = chr->pos.x + chr->surf->w / 2 - surfaces->Pmort->w / 2; pos_dead.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pmort->h / 2; SDL_BlitSurface(surfaces->Pmort, NULL, surfaces->Pecran, &pos_dead); } blit_chr_infos(surfaces, chr); } void blit_team(SURFACES *surfaces, struct team_t *team) { for (int i = 0; i < team->chr_cnt; i++) { blit_character(surfaces, &team->chrs[i]); } } static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) { SDL_Color color = {0x8a, 0x00, 0x00, 0x00}; TTF_Font *font = TTF_OpenFont("times.ttf", 20); SDL_Surface *surf_name; SDL_Rect pos_name;; /* display the information frame */ SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->Pecran, &positions->Vpositioncadrecible); /* display the name of the character */ surf_name = TTF_RenderText_Blended(font, chr->name, color); pos_name.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surf_name->w / 2; pos_name.y = positions->Vpositioncadrecible.y + 10; /* display the affinities of the character */ blit_character_affinities(surfaces, positions, chr); /* display its HP / MP */ Fblitterpvcible (surfaces,positions, chr); Fblitterpmcible (surfaces,positions, chr); SDL_BlitSurface(surf_name, NULL, surfaces->Pecran, &pos_name); SDL_FreeSurface(surf_name); TTF_CloseFont(font); } void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) { /* clear cursor */ SDL_BlitSurface(surfaces->Pfondjeu, &positions->last_cursor, surfaces->Pecran, &positions->last_cursor); if (chr == NULL) { /* clear the target informations frame */ SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositioncadrecible, surfaces->Pecran, &positions->Vpositioncadrecible); } else { /* display the new cursor */ positions->last_cursor.x = chr->pos_curs.x; positions->last_cursor.y = chr->pos_curs.y; positions->last_cursor.w = chr->curs->w; positions->last_cursor.h = chr->curs->h; SDL_BlitSurface(chr->curs, NULL, surfaces->Pecran, &chr->pos_curs); display_target_infos(surfaces, positions, chr); } } void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) { SDL_Color couleur={120,0,0,0}; TTF_Font *police=NULL; const char *string; if (surfaces->Pnomcible!=NULL) { SDL_FreeSurface (surfaces->Pnomcible); surfaces->Pnomcible=NULL; } police=TTF_OpenFont("times.ttf",20); SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->Pecran, &positions->Vpositioncadrecible); positions->Vpositioncurseurallies.x = chr->pos.x + 20 + chr->surf->w; positions->Vpositioncurseurallies.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pcurseurallies->h / 2; SDL_BlitSurface(surfaces->Pcurseurallies, NULL, surfaces->Pecran, &positions->Vpositioncurseurallies); string = (chr->name) ? chr->name : "NO NAME"; surfaces->Pnomcible = TTF_RenderText_Blended (police, string, couleur); positions->Vpositionnomcible.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surfaces->Pnomcible->w / 2; positions->Vpositionnomcible.y = positions->Vpositioncadrecible.y + 10; blit_character_affinities(surfaces, positions, chr); Fblitterpvcible (surfaces,positions, chr); Fblitterpmcible (surfaces,positions, chr); SDL_BlitSurface (surfaces->Pnomcible,NULL,surfaces->Pecran,&positions->Vpositionnomcible); SDL_Flip (surfaces->Pecran); TTF_CloseFont(police); } void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets) { int i; TTF_Font *police=NULL; SDL_Color couleur={0,0,0,0}; char chaine[3][50]; police=TTF_OpenFont ("TIMESBI.TTF",20); SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); SDL_BlitSurface (surfaces->Pcadreactions,NULL,surfaces->Pecran,&positions->Vpositioncadreactions); for(i=0;iPactionselectionnee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[selection-page*3]); } for(i=0;i<3;i++) { if(surfaces->Pnomactions[i]!=NULL) { SDL_FreeSurface(surfaces->Pnomactions[i]); surfaces->Pnomactions[i]=NULL; } } if(type==ACTIONS) { if(page==0) { ECRIRE("ATTAQUE",0); ECRIRE("MAGIE BLANCHE",1); ECRIRE("MAGIE NOIRE",2); } else if(page==1) { ECRIRE("TECHNIQUES",0); ECRIRE("OBJETS",1); } } else if(type==MAGIE_BLANCHE) { if (page==0) { ECRIRE("SOIN",0); } } else if(type==MAGIE_NOIRE) { if(page==0) { ECRIRE("FEU",0); ECRIRE("GLACE",1); ECRIRE("EAU",2); } else if(page==1) { ECRIRE("TONNERRE",0); ECRIRE("CHOC",1); } } else if(type==OBJETS) { if(page==0) { ECRIRE("POTION",0); ECRIRE("ETHER",1); ECRIRE("POTION +",2); sprintf(chaine[0],"%d",objets->potions); surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur); sprintf(chaine[1],"%d",objets->ethers); surfaces->Pquantite[1]=TTF_RenderText_Blended(police,chaine[1],couleur); sprintf(chaine[2],"%d",objets->potionsplus); surfaces->Pquantite[2]=TTF_RenderText_Blended(police,chaine[2],couleur); SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]); SDL_BlitSurface(surfaces->Pquantite[1],NULL,surfaces->Pecran,&positions->Vpositionquantite[1]); SDL_BlitSurface(surfaces->Pquantite[2],NULL,surfaces->Pecran,&positions->Vpositionquantite[2]); } else if(page==1) { ECRIRE("ETHER +",0); sprintf(chaine[0],"%d",objets->ethersplus); surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur); SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]); } } if (page==nbactions/3) { if(3*(page+1)-nbactions==1) SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]); if(3*(page+1)-nbactions==2) { SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]); SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[1]); } } SDL_Flip(surfaces->Pecran); TTF_CloseFont (police); } static void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, unsigned int incr, SDL_Color color) { TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30); char string[256]; SDL_Surface *surf; sprintf(string, "%d", incr); TTF_SetFontStyle(font, TTF_STYLE_BOLD); surf = TTF_RenderText_Blended(font, string, color); blit_character(surfaces, target); SDL_BlitSurface(surf, NULL, surfaces->Pecran, &target->pos_curs); positions->Vpositiondegats.x = target->pos_curs.x; positions->Vpositiondegats.y = target->pos_curs.y; positions->Vpositiondegats.w = surf->w; positions->Vpositiondegats.h = surf->h; SDL_FreeSurface(surf); TTF_CloseFont(font); } static void incr_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) { SDL_Color color; target->hp += incr; if (target->hp <= 0) { target->hp = 0; target->alive = false; } else if (target->hp > target->max_hp) { target->hp = target->max_hp; } color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); } static void incr_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) { SDL_Color color; target->hp += incr; if (target->mp <= 0) { target->mp = 0; } else if (target->mp > target->max_mp) { target->mp = target->max_mp; } color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); } void damage_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) { incr_hp(surfaces, positions, target, -damages); } void cure_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) { incr_hp(surfaces, positions, target, cure); } void damage_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) { incr_mp(surfaces, positions, target, -damages); } void cure_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) { incr_mp(surfaces, positions, target, cure); } void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct character_t *chr) { static const enum affinity_t affinities[] = { AFFINITY_SENSITIVE, AFFINITY_RESISTANCE, AFFINITY_INVULNERABILITY, AFFINITY_ABSORPTION, }; for (int i = 0; i < countof(affinities); ++i) { for (enum element_t elmt = 0; elmt < ELEMENT_COUNT; ++elmt) { if (chr->affinities[elmt] == affinities[i]) { SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i * ELEMENT_COUNT + elmt]); } else { SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i * ELEMENT_COUNT + elmt]); } } } } void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr) { TTF_Font *police = NULL; SDL_Color couleur = {132,215,107,0}; char chaine[50]; if (surfaces->Ppvcible != NULL) { SDL_FreeSurface (surfaces->Ppvcible); surfaces->Ppvcible=NULL; } sprintf (chaine,"%d/%d", chr->hp, chr->max_hp); police=TTF_OpenFont ("TIMESBI.TTF",18); surfaces->Ppvcible=TTF_RenderText_Blended (police,chaine,couleur); SDL_BlitSurface (surfaces->Ppvcible,NULL,surfaces->Pecran,&positions->Vpositionpvcible); TTF_CloseFont (police); } void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr) { TTF_Font *police = NULL; SDL_Color couleur = {132,215,107,0}; char chaine[50]; if (surfaces->Ppmcible != NULL) { SDL_FreeSurface (surfaces->Ppmcible); surfaces->Ppmcible=NULL; } sprintf (chaine,"%d/%d", chr->mp, chr->max_mp); police=TTF_OpenFont ("TIMESBI.TTF",18); surfaces->Ppmcible=TTF_RenderText_Blended (police,chaine,couleur); SDL_BlitSurface (surfaces->Ppmcible,NULL,surfaces->Pecran,&positions->Vpositionpmcible); TTF_CloseFont (police); } void Fblitterfond(SURFACES* surfaces) { SDL_Rect position; position.x=0; position.y=0; surfaces->Pfondjeu=IMG_Load("images/jeu/textures/background.jpg"); SDL_BlitSurface(surfaces->Pfondjeu,NULL,surfaces->Pecran,&position); SDL_Flip(surfaces->Pecran); }