#include #include #include #include #include #include "constantes.h" #include "players.h" #include "entry.h" #include "rpg.h" static void blit_chr_infos(struct chr_t *chr) { SDL_Color fg={132,215,107,0},bg={100,0,0,0}; char string[256]; SDL_Surface *surf_hp; SDL_Surface *surf_mp; sprintf(string, "PV %d/%d ", chr->hp, chr->max_hp); surf_hp = TTF_RenderText_Shaded(rpg_g.font, string, fg, bg); sprintf(string, "PM %d/%d ", chr->mp, chr->max_mp); surf_mp = TTF_RenderText_Shaded(rpg_g.font, 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, rpg_g.screen, &chr->pos_hp); SDL_BlitSurface(surf_mp, NULL, rpg_g.screen, &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); } void blit_character(struct chr_t *chr) { SDL_BlitSurface(chr->surf, NULL, rpg_g.screen, &chr->pos); if (!chr->alive) { SDL_Rect pos_dead; pos_dead.x = chr->pos.x + chr->surf->w / 2 - rpg_g.surfaces.Pmort->w / 2; pos_dead.y = chr->pos.y + chr->surf->h / 2 - rpg_g.surfaces.Pmort->h / 2; SDL_BlitSurface(rpg_g.surfaces.Pmort, NULL, rpg_g.screen, &pos_dead); } blit_chr_infos(chr); } void blit_team(struct team_t *team) { for (int i = 0; i < team->chr_cnt; i++) { blit_character(&team->chrs[i]); } } static void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct chr_t *chr) { static const enum affinity_t affinities[] = { AFFIN_SENSITIVE, AFFIN_RESISTANCE, AFFIN_INVULN, AFFIN_ABSORPTION, }; for (int i = 0; i < countof(affinities); ++i) { for (enum element_t elmt = 0; elmt < ELEM_COUNT; ++elmt) { SDL_Surface *surf; SDL_Rect *rect; if (chr->affinities[elmt] == affinities[i]) { surf = surfaces->Pactive; } else { surf = surfaces->Pdesactive; } rect = &positions->activedesactive[i * ELEM_COUNT + elmt]; SDL_BlitSurface(surf, NULL, surfaces->screen, rect); } } } static void Fblitterpvcible(SURFACES *surfaces, POSITIONS *positions, const struct chr_t *chr) { SDL_Color couleur = {132,215,107,0}; char chaine[50]; SDL_Surface *surf; sprintf (chaine,"%d/%d", chr->hp, chr->max_hp); surf = TTF_RenderText_Blended(rpg_g.font, chaine, couleur); SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->pvcible); SDL_FreeSurface(surf); } static void Fblitterpmcible(SURFACES *surfaces, POSITIONS *positions, const struct chr_t *chr) { SDL_Color couleur = {132,215,107,0}; char chaine[50]; SDL_Surface *surf; sprintf (chaine,"%d/%d", chr->mp, chr->max_mp); surf = TTF_RenderText_Blended(rpg_g.font, chaine, couleur); SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->pmcible); SDL_FreeSurface(surf); } static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct target_t *target) { SDL_Color color = {0x8a, 0x00, 0x00, 0x00}; SDL_Surface *surf_name; SDL_Rect pos_name; const char *name; /* display the information frame */ SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->screen, &positions->cadrecible); if (target->is_chr) { /* display the name of the character */ name = target->chr->name; /* display the affinities of the character */ blit_character_affinities(surfaces, positions, target->chr); /* display its HP / MP */ Fblitterpvcible (surfaces,positions, target->chr); Fblitterpmcible (surfaces,positions, target->chr); } else { name = target->team->name; } surf_name = TTF_RenderText_Blended(rpg_g.font, name, color); pos_name.x = positions->cadrecible.x + surfaces->Pcadrecible->w / 2 - surf_name->w / 2; pos_name.y = positions->cadrecible.y + 10; SDL_BlitSurface(surf_name, NULL, surfaces->Pecran, &pos_name); SDL_FreeSurface(surf_name); } void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct target_t *target) { /* clear cursor */ SDL_BlitSurface(surfaces->background, &positions->last_cursor, surfaces->screen, &positions->last_cursor); if (target == NULL) { /* clear the target informations frame */ SDL_BlitSurface(surfaces->background, &positions->cadrecible, surfaces->screen, &positions->cadrecible); } else { /* display the new cursor */ if (target->is_chr) { positions->last_cursor.x = target->chr->pos_curs.x; positions->last_cursor.y = target->chr->pos_curs.y; positions->last_cursor.w = target->chr->curs->w; positions->last_cursor.h = target->chr->curs->h; SDL_BlitSurface(target->chr->curs, NULL, surfaces->screen, &target->chr->pos_curs); } else { for (int i = 0; i < target->team->chr_cnt; ++i) { struct chr_t *chr = &target->team->chrs[i]; 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->screen, &chr->pos_curs); } } display_target_infos(surfaces, positions, target); } } void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected) { SDL_Color color = {0, 0, 0, 0}; SDL_Surface *surf; int off; if (selected == -1) { SDL_BlitSurface(surfaces->background, &positions->cadreactions, surfaces->screen, &positions->cadreactions); SDL_Flip(surfaces->Pecran); return; } SDL_BlitSurface(surfaces->Pcadreactions, NULL, surfaces->screen, &positions->cadreactions); off = selected / 3 * 3; /* display at most three actions */ for (int i = 0; i < 3; ++i) { const char *string; char buffer[256]; if (off + i >= cnt) { SDL_BlitSurface(surfaces->Pactiondesactivee, NULL, surfaces->screen, &positions->actionselectionnee[i]); continue; } /* if the current entry is the selected one */ if (selected == off + i) { SDL_BlitSurface(surfaces->Pactionselectionnee, NULL, surfaces->screen, &positions->actionselectionnee[i]); } if (entries[off + i].children_cnt) { snprintf(buffer, sizeof(buffer), "+ %s", entries[off + i].name); string = buffer; } else { string = entries[off + i].name; } surf = TTF_RenderText_Blended(rpg_g.font, string, color); SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->nomactions[i]); SDL_FreeSurface(surf); } SDL_Flip(surfaces->Pecran); } void display_incr(SURFACES *surfaces, POSITIONS *positions, struct chr_t *target, unsigned int incr, SDL_Color color) { char string[256]; SDL_Surface *surf; sprintf(string, "%d", incr); surf = TTF_RenderText_Blended(rpg_g.font, string, color); blit_character(target); SDL_BlitSurface(surf, NULL, surfaces->Pecran, &target->pos_curs); positions->degats.x = target->pos_curs.x; positions->degats.y = target->pos_curs.y; positions->degats.w = surf->w; positions->degats.h = surf->h; SDL_FreeSurface(surf); }