aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_life_bar.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-20 17:09:47 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-20 17:09:47 +0100
commit213f65da05db9129957c2295d680d449cdace274 (patch)
treeeba710537b7748c12d5bd260a230dcad56af0490 /src/ft_draw_life_bar.c
parentin progress (diff)
download42-cub3d-213f65da05db9129957c2295d680d449cdace274.tar.gz
42-cub3d-213f65da05db9129957c2295d680d449cdace274.tar.bz2
42-cub3d-213f65da05db9129957c2295d680d449cdace274.tar.xz
42-cub3d-213f65da05db9129957c2295d680d449cdace274.tar.zst
42-cub3d-213f65da05db9129957c2295d680d449cdace274.zip
Ok almost
Diffstat (limited to 'src/ft_draw_life_bar.c')
-rw-r--r--src/ft_draw_life_bar.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/ft_draw_life_bar.c b/src/ft_draw_life_bar.c
index f9d5227..06ecf70 100644
--- a/src/ft_draw_life_bar.c
+++ b/src/ft_draw_life_bar.c
@@ -14,6 +14,20 @@
#include <cub3d.h>
#include <stdint.h>
+static void
+ ft_draw_tnum(t_img num, int16_t y, int16_t x, t_cub *cl)
+{
+ *(cl->img.ptr + x * 4 + (cl->img.sizeline * y)) =
+ (uint8_t)*(num.ptr + num.tex_x * 4 + 4 *
+ num.img_w * num.tex_y);
+ *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 1) =
+ (uint8_t)*(num.ptr + num.tex_x * 4 + 4 *
+ num.img_w * num.tex_y + 1);
+ *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 2) =
+ (uint8_t)*(num.ptr + num.tex_x * 4 + 4 *
+ num.img_w * num.tex_y + 2);
+}
+
/* static void */
/* ft_put_image_from_number(char *num, t_cub *cl) */
/* { */
@@ -24,21 +38,39 @@ static void
{
int32_t x_ratio;
int32_t y_ratio;
+ int16_t x;
+ int16_t y;
x_ratio = (int)((cl->tnum[10].img_w << 16) / (7 * cl->mlist.scale)) + 1;
y_ratio = (int)((cl->tnum[10].img_h << 16) /
((cl->mlist.map_h * cl->mlist.scale) - 20)) + 1;
+ y = cl->wlist.y_size - (cl->mlist.map_h * cl->mlist.scale) + 10;
+ while (y < (int16_t)cl->wlist.y_size - 10)
+ {
+ cl->tnum[10].tex_y = (y * y_ratio) >> 16;
+ x = ((cl->mlist.map_w * cl->mlist.scale) + 20 + ((28 * cl->mlist.scale)
+ - ((28 * cl->mlist.scale) / 4)));
+ while (x < (int16_t)((cl->mlist.map_w * cl->mlist.scale)
+ + 10 + ((28 * cl->mlist.scale))))
+ {
+ 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(cl->tnum[10], y, x, cl);
+ x++;
+ }
+ y++;
+ }
}
void
- ft_draw_life_bar(t_win *wl, t_cub *cl)
+ ft_draw_life_bar(t_cub *cl)
{
char *num;
float calc;
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);
- (void)wl;
ft_put_percent_image(cl);
/* ft_put_image_from_number(num, cl); */
ft_memdel((void*)&num);