]> git.lizzy.rs Git - dungeon_game.git/blob - plugins/healthbar/healthbar.c
5651051b4b572dd5b8dc9019481475469f503d08
[dungeon_game.git] / plugins / healthbar / healthbar.c
1 #include <stdio.h>
2 #include "../game/game.h"
3
4 static struct color red = {255, 0, 0};
5 static struct color gray;
6
7 static void render_healthbar(struct winsize ws)
8 {
9         int y = max(ws.ws_row - 2, 0);
10         int x = max(ws.ws_col / 2 - player.max_health, 0);
11
12         printf("\e[%u;%uH", y, x);
13
14         set_color(red, false);
15
16         int health = max(player.health, 0);
17
18         for (int i = 0; i < player.max_health; i++) {
19                 if (i == health)
20                         set_color(gray, false);
21                 printf("♥ ");
22         }
23 }
24
25 __attribute__ ((constructor)) static void init()
26 {
27         gray = get_color("#5A5A5A");
28
29         register_render_component(&render_healthbar);
30 }