diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-07-06 22:19:15 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-07-06 22:19:15 +0100 |
commit | 0e9a1403546b510b3c05a218a87afd29c99ee434 (patch) | |
tree | 4be6a276808664251ccdcdc1bf47256fa3a50cac | |
parent | 752b8c4b4703a5bc43d32b815aa713fab12e653c (diff) | |
download | gold-mine-run-0e9a1403546b510b3c05a218a87afd29c99ee434.tar.gz gold-mine-run-0e9a1403546b510b3c05a218a87afd29c99ee434.zip |
Add tracker enemy (Mr Bones)
-rw-r--r-- | data/stage.json | 4 | ||||
-rw-r--r-- | src/bones.c | 45 | ||||
-rw-r--r-- | src/bones.h | 7 | ||||
-rw-r--r-- | src/map.c | 2 | ||||
-rwxr-xr-x | tools/map.py | 2 |
5 files changed, 57 insertions, 3 deletions
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 <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) + { + 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 */ @@ -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): |