aboutsummaryrefslogtreecommitdiff
path: root/src/entities.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-25 22:44:23 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-25 22:44:23 +0100
commit6bd6757583510ba3edf75451309e4b8ec8c9b0f1 (patch)
treee63f401238e4118ff6d1670ea86508f0181c19ea /src/entities.c
parent2d7fbc07acf0c5766d662d2629e72600b65f744b (diff)
downloadgold-mine-run-6bd6757583510ba3edf75451309e4b8ec8c9b0f1.tar.gz
gold-mine-run-6bd6757583510ba3edf75451309e4b8ec8c9b0f1.zip
Add entity system, add new enemy (snake)
Diffstat (limited to 'src/entities.c')
-rw-r--r--src/entities.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/entities.c b/src/entities.c
new file mode 100644
index 0000000..be976ea
--- /dev/null
+++ b/src/entities.c
@@ -0,0 +1,72 @@
+#include <stdint.h>
+#include <string.h>
+
+#include "vga.h"
+#include "map.h"
+#include "data.h"
+
+#include "entities.h"
+
+#define MAX_ENTITY 32
+
+static Entity entities[MAX_ENTITY];
+static uint8_t last;
+
+void entities_init()
+{
+ memset(entities, 0, sizeof(Entity) * MAX_ENTITY);
+ last = 0;
+}
+
+Entity *entities_new()
+{
+ for (uint8_t i = 0; i < MAX_ENTITY; i++)
+ {
+ if (entities[i].used == 0)
+ {
+ memset(&entities[i], 0, sizeof(Entity));
+ entities[i].used = 1;
+
+ if (i >= last)
+ last = i + 1;
+
+ return &entities[i];
+ }
+ }
+
+ return NULL;
+}
+
+void entities_update()
+{
+ Entity *e = entities;
+
+ for (uint8_t i = 0; i < last; i++, e++)
+ if (e->used)
+ e->update(e);
+}
+
+void entities_erase()
+{
+ Entity *e = entities + last - 1;
+
+ for (uint8_t i = 0; i < last; i++, e--)
+ if (e->used)
+ {
+ Rect dst = { e->x, e->y + MAP_OFFS_Y, 16, 16 };
+ blit(e->bg, &dst);
+ }
+}
+
+void entities_draw()
+{
+ Entity *e = entities;
+
+ for (uint8_t i = 0; i < last; i++, e++)
+ if (e->used)
+ {
+ Rect dst = { e->x, e->y + MAP_OFFS_Y, 16, 16 };
+ read_buffer(e->bg, &dst);
+ blitrc(binary_sprites_start, &e->frames[e->dir * 4 + e->frame], &dst);
+ }
+}