aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-07-06 22:19:15 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-07-06 22:19:15 +0100
commit0e9a1403546b510b3c05a218a87afd29c99ee434 (patch)
tree4be6a276808664251ccdcdc1bf47256fa3a50cac /src
parent752b8c4b4703a5bc43d32b815aa713fab12e653c (diff)
downloadgold-mine-run-0e9a1403546b510b3c05a218a87afd29c99ee434.tar.gz
gold-mine-run-0e9a1403546b510b3c05a218a87afd29c99ee434.zip
Add tracker enemy (Mr Bones)
Diffstat (limited to 'src')
-rw-r--r--src/bones.c45
-rw-r--r--src/bones.h7
-rw-r--r--src/map.c2
3 files changed, 54 insertions, 0 deletions
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 */
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,