aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_life_bar.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-21 18:01:19 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-21 18:01:19 +0100
commitacbc6a4eb3cb2662f3f36efed90cc3e534013c9d (patch)
treeb939bd0410866fd57d9c1282d197eaf06903a9a6 /src/ft_draw_life_bar.c
parentWe got percent (diff)
download42-cub3d-acbc6a4eb3cb2662f3f36efed90cc3e534013c9d.tar.gz
42-cub3d-acbc6a4eb3cb2662f3f36efed90cc3e534013c9d.tar.bz2
42-cub3d-acbc6a4eb3cb2662f3f36efed90cc3e534013c9d.tar.xz
42-cub3d-acbc6a4eb3cb2662f3f36efed90cc3e534013c9d.tar.zst
42-cub3d-acbc6a4eb3cb2662f3f36efed90cc3e534013c9d.zip
Nice
Diffstat (limited to 'src/ft_draw_life_bar.c')
-rw-r--r--src/ft_draw_life_bar.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/ft_draw_life_bar.c b/src/ft_draw_life_bar.c
index 28a7110..f429b43 100644
--- a/src/ft_draw_life_bar.c
+++ b/src/ft_draw_life_bar.c
@@ -34,12 +34,27 @@ static void
}
/* static void */
-/* ft_put_image_from_number(char *num, t_cub *cl) */
+/* ft_put_next_number(char n, int16_t x_offset, t_cub *cl); */
+
+/* static void */
+/* ft_put_image_from_number(char *num, uint16_t h, uint16_t w, t_cub *cl) */
/* { */
+/* const size_t len = ft_strlen(num); */
+
+/* (void)num; */
+/* (void)h; */
+/* (void)w; */
+/* (void)cl; */
+/* if (len == 3) */
+/* { */
+/* ft_put_next_number(num[0], 0, cl); */
+/* ft_put_next_number(num[1], 0, cl); */
+/* ft_put_next_number(num[2], 0, cl); */
+/* } */
/* } */
static void
- ft_put_percent_image(uint16_t h, uint16_t w, t_cub *cl)
+ ft_put_percent_image(char n, uint16_t x_offset, t_cub *cl)
{
int32_t x_ratio;
int32_t y_ratio;
@@ -47,21 +62,19 @@ static void
int16_t y;
const int16_t scl = cl->mlist.scale;
- x_ratio = (int)(((cl->tnum[10].img_w) << 16) / w) + 1;
- y_ratio = (int)(((cl->tnum[10].img_h) << 16) / h) + 1;
+ x_ratio = (int)(((cl->tnum[n - 48].img_w) << 16) / cl->w) + 1;
+ y_ratio = (int)(((cl->tnum[n - 48].img_h) << 16) / cl->h) + 1;
y = 0;
- while (y < h)
+ while (y < cl->h)
{
- cl->tnum[10].tex_y = ((y * y_ratio) >> 16);
- x = ((cl->mlist.map_w * scl) + 20) + (32 * scl) - ((32 * scl) / 4);
- while (x < (int32_t)((cl->mlist.map_w * scl) + 10 + ((32 * scl))))
+ cl->tnum[n - 48].tex_y = ((y * y_ratio) >> 16);
+ x = ((cl->mlist.map_w * scl) + 20) + x_offset;
+ while (x < (int16_t)((cl->mlist.map_w * scl) + 10 + ((32 * scl) / 4) + x_offset))
{
- cl->tnum[10].tex_x = ((x * x_ratio) >> 16);
- if (cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 *
- cl->tnum[10].img_h * cl->tnum[10].tex_y])
- {
- ft_draw_tnum(10, y, x, cl);
- }
+ cl->tnum[n - 48].tex_x = ((x * x_ratio) >> 16);
+ if (cl->tnum[n - 48].ptr[cl->tnum[n - 48].tex_x * 4 + 4 *
+ cl->tnum[n - 48].img_h * cl->tnum[n - 48].tex_y])
+ ft_draw_tnum(n - 48, y, x, cl);
x++;
}
y++;
@@ -85,19 +98,22 @@ static void
}
y -= cl->wlist.y_size - (cl->mlist.map_h * scl) - 10;
x -= ((cl->mlist.map_w * scl) + 20) + (32 * scl) - ((32 * scl) / 4);
- ft_put_percent_image(y, x, cl);
+ cl->h = y;
+ cl->w = x;
}
void
ft_draw_life_bar(t_cub *cl)
{
- char *num;
- float calc;
+ char *num;
+ float calc;
+ const int16_t scl = cl->mlist.scale;
- ft_get_hw(cl);
calc = ((float)cl->plist.life / (float)FT_STRT_LIFE) * 100.0;
if (!(num = ft_itoa((int64_t)calc)))
ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl);
- ft_put_image_from_number(num, cl);
+ ft_get_hw(cl);
+ ft_put_percent_image(58, (3 * (32 * scl) / 4), cl);
+ /* ft_put_image_from_number(num, y, x, cl); */
ft_memdel((void*)&num);
}