summaryrefslogtreecommitdiff
path: root/character.c
blob: 2b4be4e1d48324e7f72f5c6bd487a97909cf9214 (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
59
60
61
62
63
64
65
66
#include <SDL/SDL.h>
#include "players.h"
#include "blits.h"

static void
incr_hp(SURFACES *surfaces, POSITIONS *positions, struct chr_t *chr, int incr)
{
    SDL_Color color;

    chr->hp += incr;

    if (chr->hp <= 0) {
        chr->hp = 0;
        chr->alive = false;
    } else if (chr->hp > chr->max_hp) {
        chr->hp = chr->max_hp;
    }

    if (incr < 0) {
        color = (SDL_Color){0xe0, 0x00, 0x00, 0x00};
    } else {
        color = (SDL_Color){0x00, 0xe0, 0x00, 0x00};
    }

    display_incr(surfaces, positions, chr, (incr >= 0) ? incr : -incr, color);
}

static void
incr_mp(SURFACES *surfaces, POSITIONS *positions, struct chr_t *chr, int incr)
{
    SDL_Color color;

    chr->hp += incr;

    if (chr->mp <= 0) {
        chr->mp = 0;
    } else if (chr->mp > chr->max_mp) {
        chr->mp = chr->max_mp;
    }

    display_incr(surfaces, positions, chr, (incr >= 0) ? incr : -incr, color);
}

void damage_target_hp(SURFACES *surfaces, POSITIONS *positions,
        struct chr_t *target, int damages)
{
    incr_hp(surfaces, positions, target, -damages);
}

void cure_target_hp(SURFACES *surfaces, POSITIONS *positions,
        struct chr_t *target, int cure)
{
    incr_hp(surfaces, positions, target, cure);
}

void damage_target_mp(SURFACES *surfaces, POSITIONS *positions,
        struct chr_t *target, int damages)
{
    incr_mp(surfaces, positions, target, -damages);
}

void cure_target_mp(SURFACES *surfaces, POSITIONS *positions,
        struct chr_t *target, int cure)
{
    incr_mp(surfaces, positions, target, cure);
}