diff options
-rw-r--r-- | inc/cub3d_structs.h | 2 | ||||
-rw-r--r-- | src/ft_draw_life_bar.c | 54 | ||||
-rw-r--r-- | src/ft_init_lists.c | 2 |
3 files changed, 39 insertions, 19 deletions
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 44b8827..259cf05 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -240,6 +240,8 @@ typedef struct s_cub pthread_t mtid; int8_t isdead; uint8_t moves; + uint16_t h; + uint16_t w; int (*key_ptr[6])(struct s_cub*); int8_t (*get_ptr[14])(char**, struct s_cub*); char ref[22][3]; 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); } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index d1b589e..7bf716b 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -111,5 +111,7 @@ int8_t ft_sprintf(clist->fps_count, "fps: 60"); clist->isdead = 0; clist->moves = 0; + clist->h = 0; + clist->w = 0; return (0); } |