aboutsummaryrefslogtreecommitdiff
path: root/src/effect.c
blob: e9ee55e8ae36b046a5ba0412058c5af75aeef4e6 (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
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "vga.h"
#include "entities.h"

#include "effect.h"

#define MAX_FRAME 3

static const Rect frames[2 * 4] =
{
    { 96, 16, 144, 144 },
    { 112, 16, 144, 144 },
    { 128, 16, 144, 144 },

    /* not used */
    { 0, 0, 144, 144 },
    { 0, 0, 144, 144 },
    { 0, 0, 144, 144 },
    { 0, 0, 144, 144 },
    { 0, 0, 144, 144 }
};

void effect_out_new(uint16_t x, uint16_t y)
{
    Entity *e = entities_new();
#ifdef DEBUG
    if (!e)
    {
        set_mode(3);
        fprintf(stderr, "ERROR: run out of entities\n");
        exit(1);
    }
#endif

    e->x = x;
    e->y = y;

    effect_out_init(e);
}

void effect_out_init(Entity *e)
{
    e->frames = (const Rect *)frames;
    e->dir = DIR_RIGHT;
    e->frame = 1;
    e->delay = 0;
    e->update = effect_out_update;
}

void effect_out_update(Entity *e)
{
    if (e->delay++ == WALK_DELAY - 2)
    {
        e->delay = 0;
        e->frame++;
        if (e->frame == MAX_FRAME)
            e->used = USED_FREE;
    }
}