From 0e9a1403546b510b3c05a218a87afd29c99ee434 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 6 Jul 2023 22:19:15 +0100 Subject: Add tracker enemy (Mr Bones) --- data/stage.json | 4 ++-- src/bones.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/bones.h | 7 +++++++ src/map.c | 2 ++ tools/map.py | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/bones.c create mode 100644 src/bones.h diff --git a/data/stage.json b/data/stage.json index 5276e5d..5758a5b 100644 --- a/data/stage.json +++ b/data/stage.json @@ -150,7 +150,7 @@ "type":"", "visible":true, "width":16, - "x":96, + "x":192, "y":152 }, { @@ -184,7 +184,7 @@ { "height":16, "id":9, - "name":"Snake", + "name":"Bones", "properties":[ { "name":"dir", diff --git a/src/bones.c b/src/bones.c new file mode 100644 index 0000000..f5d7f42 --- /dev/null +++ b/src/bones.c @@ -0,0 +1,45 @@ +#include +#include + +#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) + { + 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); +} diff --git a/src/bones.h b/src/bones.h new file mode 100644 index 0000000..b0e8d7e --- /dev/null +++ b/src/bones.h @@ -0,0 +1,7 @@ +#ifndef _BONES_H +#define _BONES_H + +void bones_init(Entity *e); +void bones_update(Entity *e); + +#endif /* _BONES_H */ diff --git a/src/map.c b/src/map.c index bc7b283..e5e67d1 100644 --- a/src/map.c +++ b/src/map.c @@ -11,6 +11,7 @@ #include "snake.h" #include "bat.h" #include "old.h" +#include "bones.h" #include "pickup.h" #include "map.h" @@ -25,6 +26,7 @@ static void (* const init[])(Entity *) = snake_init, bat_init, old_init, + bones_init, pickup_time_init, pickup_bonus_init, pickup_pickaxe_init, diff --git a/tools/map.py b/tools/map.py index 64d2063..6c18e82 100755 --- a/tools/map.py +++ b/tools/map.py @@ -10,7 +10,7 @@ __version__ = "1.0" ld = os.environ.get("LD", "i586-pc-msdosdjgpp-ld") strip = os.environ.get("STRIP", "i586-pc-msdosdjgpp-strip") -entity_types = ("Player", "Snake", "Bat", "Old", "Time", "Bonus", "Pickaxe") +entity_types = ("Player", "Snake", "Bat", "Old", "Bones", "Time", "Bonus", "Pickaxe") def get_layer(data, name): -- cgit v1.2.3