diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-08 04:55:31 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-08 05:30:36 +0100 |
commit | 0cc5b8230f7e74db0cb644cfc62bce56e0cd256c (patch) | |
tree | bde7f53d927fe2d0fe973144911f1c8d9fe15ca2 /blits.c | |
parent | 8dea50c02d5b04221488fb8d4b0719e373e7f9d0 (diff) |
update the damages handling
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'blits.c')
-rw-r--r-- | blits.c | 158 |
1 files changed, 36 insertions, 122 deletions
@@ -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) |