aboutsummaryrefslogtreecommitdiff
path: root/plugins/healthbar/healthbar.c
blob: c66d3f13c2333093d1c61efd649b63f2f566f95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 / 2, 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);
}