diff options
Diffstat (limited to 'plugins/healthbar')
-rw-r--r-- | plugins/healthbar/Makefile | 4 | ||||
-rw-r--r-- | plugins/healthbar/dependencies.txt | 1 | ||||
-rw-r--r-- | plugins/healthbar/healthbar.c | 30 |
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); +} |