From bfdf279cac51fe8945e59cd566cba2cb2efcffce Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 8 Jan 2015 19:45:03 +0100 Subject: move some functions and headers so that the compilation is quicker Signed-off-by: Olivier Gayot --- character.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 character.c (limited to 'character.c') diff --git a/character.c b/character.c new file mode 100644 index 0000000..4a3a260 --- /dev/null +++ b/character.c @@ -0,0 +1,58 @@ +#include +#include "players.h" +#include "blits.h" + +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); +} -- cgit v1.2.3