summaryrefslogtreecommitdiff
path: root/character.c
blob: 4a3a260fa082b73d724fb32bba177e0a63aa60c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <SDL/SDL.h>
#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);
}