aboutsummaryrefslogtreecommitdiff
path: root/src/bones.c
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/bones.c
parent752b8c4b4703a5bc43d32b815aa713fab12e653c (diff)
downloadgold-mine-run-0e9a1403546b510b3c05a218a87afd29c99ee434.tar.gz
gold-mine-run-0e9a1403546b510b3c05a218a87afd29c99ee434.zip
Add tracker enemy (Mr Bones)
Diffstat (limited to 'src/bones.c')
-rw-r--r--src/bones.c45
1 files changed, 45 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);
+}