aboutsummaryrefslogtreecommitdiff
path: root/src/bones.c
blob: 8891534b0043a9576541de6a5c69016d52bda8c4 (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
#include <stdint.h>
#include <stdlib.h>

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

#include "player.h"
#include "old.h"

#include "bones.h"

static const Rect frames[2 * 4] =
{
    /* right */
    { 0, 96, 144, 144 },
    { 16, 96, 144, 144 },
    { 0, 96, 144, 144 },
    { 32, 96, 144, 144 },

    /* left */
    { 48, 96, 144, 144 },
    { 64, 96, 144, 144 },
    { 48, 96, 144, 144 },
    { 80, 96, 144, 144 },
};

void bones_init(Entity *e)
{
    e->frames = (const Rect *)frames;
    e->update = bones_update;
}

void bones_update(Entity *e)
{
    if (abs(player_y() - e->y) < 8 && e->flags < ENEMY_JUMP_DELAY)
    {
        if (player_x() > e->x && e->dir != DIR_RIGHT)
            e->dir = DIR_RIGHT;
        if (player_x() < e->x && e->dir != DIR_LEFT)
            e->dir = DIR_LEFT;
    }

    old_update(e);
}