3 #include "../game/game.h"
5 static double recharge_full_timer = 0.0;
6 static double recharge_timer = 0.0;
8 static const char *recharge_icon;
12 return recharge_timer <= 0;
15 void recharge(double timer, const char *icon)
17 recharge_full_timer = recharge_timer = timer;
21 static void render_recharge_meter(struct winsize ws)
23 int y = ws.ws_row - 1;
24 int x = ws.ws_col - 14;
26 if (recharge_timer <= 0.0)
29 double frac = (recharge_full_timer - recharge_timer) / recharge_full_timer;
31 printf("\e[%d;%dH", y, x);
33 printf("%s[", recharge_icon);
35 struct color color = {
41 set_color(color, true);
44 sprintf(bar, "%9d%%", (int) (frac * 100));
48 for (int i = 0; i < 10; i++) {
50 set_color(black, true);
54 set_color(black, true);
59 static void recharge_globalstep(double dtime)
61 if (recharge_timer > 0.0)
62 recharge_timer -= dtime;
65 __attribute__ ((constructor)) static void init()
67 register_render_component(&render_recharge_meter);
68 register_globalstep((struct globalstep) {
70 .callback = &recharge_globalstep,