From 0cc5b8230f7e74db0cb644cfc62bce56e0cd256c Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 8 Jan 2015 04:55:31 +0100 Subject: update the damages handling Signed-off-by: Olivier Gayot --- actions.c | 6 +-- blits.c | 158 ++++++++++++++--------------------------------------------- magies.c | 4 +- prototypes.h | 10 ++-- 4 files changed, 45 insertions(+), 133 deletions(-) diff --git a/actions.c b/actions.c index 59c3b5c..9f22dc8 100644 --- a/actions.c +++ b/actions.c @@ -54,7 +54,7 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_PHYSICAL, ELEMENT_NONE); - damage_target_hp(surfaces, target, degats); + damage_target_hp(surfaces, positions, target, degats); SDL_Flip(surfaces->Pecran); @@ -398,7 +398,7 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team else if (type == POTIONPLUS) soins = 4000; - cure_target_hp(surfaces, target, soins); + cure_target_hp(surfaces, positions, target, soins); SDL_Flip(surfaces->Pecran); @@ -481,7 +481,7 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_ else if (type == ETHERPLUS) soins = 40; - cure_target_mp(surfaces, target, soins); + cure_target_mp(surfaces, positions, target, soins); SDL_Flip (surfaces->Pecran); diff --git a/blits.c b/blits.c index e432359..24bdd93 100644 --- a/blits.c +++ b/blits.c @@ -207,168 +207,82 @@ void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int sel TTF_CloseFont (police); } -static void incr_hp(SURFACES *surfaces, struct character_t *target, int incr) +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_Color color; SDL_Surface *surf; - SDL_Rect pos; - int incr_abs; - - target->hp -= incr; - if (target->hp <= 0) { - target->hp = 0; - target->alive = true; - } 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}; - - incr_abs = (incr >= 0) ? incr : -incr; - - sprintf(string, "%d", incr_abs); + sprintf(string, "%d", incr); TTF_SetFontStyle(font, TTF_STYLE_BOLD); surf = TTF_RenderText_Blended(font, string, color); - pos.x = target->pos.x + target->surf->w + 20; - pos.y = target->pos.y + target->surf->h / 2 - surf->h / 2; - blit_character(surfaces, target); - SDL_BlitSurface(surf, NULL, surfaces->Pecran, &pos); + 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_mp(SURFACES *surfaces, struct character_t *target, int incr) +static void incr_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) { - TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30); - char string[256]; SDL_Color color; - SDL_Surface *surf; - SDL_Rect pos; - int incr_abs; - target->hp -= incr; + target->hp += incr; - if (target->mp <= 0) { - target->mp = 0; - } else if (target->mp > target->max_mp) { - target->mp = target->max_mp; + 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}; - incr_abs = (incr >= 0) ? incr : -incr; - - sprintf(string, "%d", incr_abs); - - TTF_SetFontStyle(font, TTF_STYLE_BOLD); - surf = TTF_RenderText_Blended(font, string, color); + display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); +} - pos.x = target->pos.x + target->surf->w + 20; - pos.y = target->pos.y + target->surf->h / 2 - surf->h / 2; +static void incr_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) +{ + SDL_Color color; - blit_character(surfaces, target); - SDL_BlitSurface(surf, NULL, surfaces->Pecran, &pos); + target->hp += incr; - SDL_FreeSurface(surf); - TTF_CloseFont(font); -} + if (target->mp <= 0) { + target->mp = 0; + } else if (target->mp > target->max_mp) { + target->mp = target->max_mp; + } -void damage_target_hp(SURFACES *surfaces, struct character_t *target, int damages) -{ - incr_hp(surfaces, target, -damages); -} + color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; -void cure_target_hp(SURFACES *surfaces, struct character_t *target, int cure) -{ - incr_hp(surfaces, target, cure); + display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); } -void damage_target_mp(SURFACES *surfaces, struct character_t *target, int damages) +void damage_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) { - incr_mp(surfaces, target, -damages); + incr_hp(surfaces, positions, target, -damages); } -void cure_target_mp(SURFACES *surfaces, struct character_t *target, int cure) +void cure_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) { - incr_mp(surfaces, target, cure); + incr_hp(surfaces, positions, target, cure); } -void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally) +void damage_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) { - char chaine[10]; - TTF_Font *police = NULL; - SDL_Color fg = {210,0,0,0}; - if(surfaces->Pnbdegats != NULL) - { - SDL_FreeSurface (surfaces->Pnbdegats); - surfaces->Pnbdegats=NULL; - } - sprintf (chaine,"%d ", degats); - police = TTF_OpenFont ("TIMES.TTF", 30 -); - TTF_SetFontStyle(police,TTF_STYLE_BOLD); - surfaces->Pnbdegats = TTF_RenderText_Blended(police,chaine,fg); - if(clan==ENNEMI) - { - positions->Vpositiondegats.x=positions->Vpositionennemis[cible].x-30-surfaces->Pnbdegats->w; - positions->Vpositiondegats.y=positions->Vpositionennemis[cible].y+surfaces->Tennemi[cible]->h/2-surfaces->Pnbdegats->h/2; - } - else - { - positions->Vpositiondegats.x=positions->Vpositionpersos[cible].x+surfaces->Tperso[cible]->w+30; - positions->Vpositiondegats.y=positions->Vpositionpersos[cible].y+surfaces->Tperso[cible]->h/2-surfaces->Pnbdegats->h/2; - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositionpvpersos[cible],surfaces->Pecran,&positions->Vpositionpvpersos[cible]); - blit_team(surfaces, ally); - } - positions->Vpositiondegats.w=surfaces->Pnbdegats->w; - positions->Vpositiondegats.h=surfaces->Pnbdegats->h; - SDL_BlitSurface (surfaces->Pnbdegats,NULL,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip (surfaces->Pecran); - TTF_CloseFont (police); + incr_mp(surfaces, positions, target, -damages); } -void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally) +void cure_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) { - char chaine[10]; - - (void) ally; - - TTF_Font *police = NULL; - SDL_Color fg = {80,255,80,0}; - - if (surfaces->Pnbdegats != NULL) - { - SDL_FreeSurface (surfaces->Pnbdegats); - surfaces->Pnbdegats=NULL; - } - sprintf (chaine,"%d", degats); - police = TTF_OpenFont ("TIMES.TTF", 30); - TTF_SetFontStyle(police,TTF_STYLE_BOLD); - surfaces->Pnbdegats = TTF_RenderText_Blended (police,chaine,fg); - if(clan==ENNEMI) - { - positions->Vpositiondegats.x=positions->Vpositionennemis[cible].x-30-surfaces->Pnbdegats->w; - positions->Vpositiondegats.y=positions->Vpositionennemis[cible].y+surfaces->Tennemi[cible]->h/2-surfaces->Pnbdegats->h/2; - } - else - { - positions->Vpositiondegats.x=positions->Vpositionpersos[cible].x+surfaces->Tperso[cible]->w+30; - positions->Vpositiondegats.y=positions->Vpositionpersos[cible].y+surfaces->Tperso[cible]->h/2-surfaces->Pnbdegats->h/2; - - } - positions->Vpositiondegats.w=surfaces->Pnbdegats->w; - positions->Vpositiondegats.h=surfaces->Pnbdegats->h; - SDL_BlitSurface (surfaces->Pnbdegats,NULL,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip (surfaces->Pecran); - - TTF_CloseFont (police); + incr_mp(surfaces, positions, target, cure); } void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct character_t *chr) diff --git a/magies.c b/magies.c index c17f569..13c98eb 100644 --- a/magies.c +++ b/magies.c @@ -53,8 +53,8 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, stru degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_MAGICAL, element); - damage_target_hp(surfaces, target, degats); + damage_target_hp(surfaces, positions, target, degats); SDL_Flip(surfaces->Pecran); ret = ACTION_PERFORMED; @@ -121,7 +121,7 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct t soins = compute_cure(&ally->chrs[ally->chr_cur], target); - cure_target_hp(surfaces, target, soins); + cure_target_hp(surfaces, positions, target, soins); SDL_Flip (surfaces->Pecran); diff --git a/prototypes.h b/prototypes.h index 3e7fc16..4e00d01 100644 --- a/prototypes.h +++ b/prototypes.h @@ -35,16 +35,15 @@ int Fcalculernbennemis (); int compute_damages(const struct character_t *src, const struct character_t *target, enum damages_type_t, enum element_t); int compute_cure(const struct character_t *src, const struct character_t *target); -void damage_target_hp(SURFACES *surfaces, struct character_t *target, int damages); -void cure_target_hp(SURFACES *surfaces, struct character_t *target, int cure); +void damage_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int damages); +void cure_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure); -void damage_target_mp(SURFACES *surfaces, struct character_t *target, int damages); -void cure_target_mp(SURFACES *surfaces, struct character_t *target, int cure); +void damage_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int damages); +void cure_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure); void Fchangercurseur (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]); void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct character_t *); void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection); -void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int camp, int cible, struct team_t *ally); void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); void blit_character_affinities(SURFACES *, POSITIONS *, const struct character_t *); void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets); @@ -52,7 +51,6 @@ void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct char void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *); void Fchangermagienoireselectionnee(SURFACES *surfaces,POSITIONS *positions,int selection,int page,int nbactions); void Fchangermagieblancheselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions); -void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally); void Fremplirobjets(OBJET *objets); void Fblitterfond(SURFACES* surfaces); -- cgit v1.2.3