aboutsummaryrefslogtreecommitdiff
path: root/plugins/healthbar
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-06-10 21:28:01 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-06-10 21:28:01 +0200
commit76d78db55969fa0a3ca92376e5cc9d0b266b4d1e (patch)
tree631273574db6582b3839158308a7f696ee3b7e46 /plugins/healthbar
parent149848dbfa136f828b09253f402de59c00a5a1cf (diff)
downloaddungeon_game-76d78db55969fa0a3ca92376e5cc9d0b266b4d1e.tar.xz
Modularize rendering
Diffstat (limited to 'plugins/healthbar')
-rw-r--r--plugins/healthbar/Makefile4
-rw-r--r--plugins/healthbar/dependencies.txt1
-rw-r--r--plugins/healthbar/healthbar.c30
3 files changed, 35 insertions, 0 deletions
diff --git a/plugins/healthbar/Makefile b/plugins/healthbar/Makefile
new file mode 100644
index 0000000..91c65d4
--- /dev/null
+++ b/plugins/healthbar/Makefile
@@ -0,0 +1,4 @@
+plugins/healthbar/healthbar.so: plugins/healthbar/healthbar.c plugins/game/game.h
+ cc -g -shared -fpic -o plugins/healthbar/healthbar.so plugins/healthbar/healthbar.c
+
+PLUGINS := ${PLUGINS} plugins/healthbar/healthbar.so
diff --git a/plugins/healthbar/dependencies.txt b/plugins/healthbar/dependencies.txt
new file mode 100644
index 0000000..dc22e61
--- /dev/null
+++ b/plugins/healthbar/dependencies.txt
@@ -0,0 +1 @@
+game
diff --git a/plugins/healthbar/healthbar.c b/plugins/healthbar/healthbar.c
new file mode 100644
index 0000000..5651051
--- /dev/null
+++ b/plugins/healthbar/healthbar.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include "../game/game.h"
+
+static struct color red = {255, 0, 0};
+static struct color gray;
+
+static void render_healthbar(struct winsize ws)
+{
+ int y = max(ws.ws_row - 2, 0);
+ int x = max(ws.ws_col / 2 - player.max_health, 0);
+
+ printf("\e[%u;%uH", y, x);
+
+ set_color(red, false);
+
+ int health = max(player.health, 0);
+
+ for (int i = 0; i < player.max_health; i++) {
+ if (i == health)
+ set_color(gray, false);
+ printf("♥ ");
+ }
+}
+
+__attribute__ ((constructor)) static void init()
+{
+ gray = get_color("#5A5A5A");
+
+ register_render_component(&render_healthbar);
+}