#include #include #include #include #include #include #include "constantes.h" #include "players.h" #include "entry.h" 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 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]); } } } } static 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); } static 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); } 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 update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected) { SDL_Color color = {0, 0, 0, 0}; TTF_Font *font; SDL_Surface *surf; int off; if (selected == -1) { SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositioncadreactions, surfaces->Pecran, &positions->Vpositioncadreactions); SDL_Flip(surfaces->Pecran); return; } SDL_BlitSurface(surfaces->Pcadreactions, NULL, surfaces->Pecran, &positions->Vpositioncadreactions); font = TTF_OpenFont("TIMESBI.TTF", 20); off = selected / 3 * 3; /* display at most three actions */ for (int i = 0; i < 3; ++i) { if (off + i >= cnt) { SDL_BlitSurface(surfaces->Pactiondesactivee, NULL, surfaces->Pecran, &positions->Vpositionactionselectionnee[i]); continue; } /* if the current entry is the selected one */ if (selected == off + i) { SDL_BlitSurface(surfaces->Pactionselectionnee, NULL, surfaces->Pecran, &positions->Vpositionactionselectionnee[i]); } surf = TTF_RenderText_Blended(font, entries[off + i].name, color); SDL_BlitSurface(surf, NULL, surfaces->Pecran, &positions->Vpositionnomactions[i]); SDL_FreeSurface(surf); } TTF_CloseFont(font); SDL_Flip(surfaces->Pecran); } 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); }