aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_life_bar.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-21 17:37:49 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-21 17:37:49 +0100
commit95a0b87d392c994bcde74ddbcf34f9f520efd13f (patch)
tree4365de8448c90ee94a65af64e3960cebddd0370a /src/ft_draw_life_bar.c
parentTrying the malloc method (diff)
download42-cub3d-95a0b87d392c994bcde74ddbcf34f9f520efd13f.tar.gz
42-cub3d-95a0b87d392c994bcde74ddbcf34f9f520efd13f.tar.bz2
42-cub3d-95a0b87d392c994bcde74ddbcf34f9f520efd13f.tar.xz
42-cub3d-95a0b87d392c994bcde74ddbcf34f9f520efd13f.tar.zst
42-cub3d-95a0b87d392c994bcde74ddbcf34f9f520efd13f.zip
We got percent
Diffstat (limited to 'src/ft_draw_life_bar.c')
-rw-r--r--src/ft_draw_life_bar.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/ft_draw_life_bar.c b/src/ft_draw_life_bar.c
index 4fd8a84..28a7110 100644
--- a/src/ft_draw_life_bar.c
+++ b/src/ft_draw_life_bar.c
@@ -14,10 +14,24 @@
#include <cub3d.h>
#include <stdint.h>
-/* static void */
-/* ft_draw_tnum(int8_t id, int16_t y, int16_t x, t_cub *cl) */
-/* { */
-/* } */
+static void
+ ft_draw_tnum(int8_t id, int16_t y, int16_t x, t_cub *cl)
+{
+ const int16_t scl = cl->mlist.scale;
+
+ cl->img.ptr[x * 4 + (cl->img.sizeline * (y +
+ cl->wlist.y_size - (cl->mlist.map_h * scl) - 10))] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y];
+ cl->img.ptr[x * 4 + (cl->img.sizeline * (y +
+ cl->wlist.y_size - (cl->mlist.map_h * scl) - 10)) + 1] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y + 1];
+ cl->img.ptr[x * 4 + (cl->img.sizeline * (y +
+ cl->wlist.y_size - (cl->mlist.map_h * scl) - 10)) + 2] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y + 2];
+}
/* static void */
/* ft_put_image_from_number(char *num, t_cub *cl) */
@@ -35,9 +49,8 @@ static void
x_ratio = (int)(((cl->tnum[10].img_w) << 16) / w) + 1;
y_ratio = (int)(((cl->tnum[10].img_h) << 16) / h) + 1;
- /* y = cl->wlist.y_size - (cl->mlist.map_h * scl) - 10; */
y = 0;
- while (y < (int32_t)(cl->wlist.y_size - 10))
+ while (y < h)
{
cl->tnum[10].tex_y = ((y * y_ratio) >> 16);
x = ((cl->mlist.map_w * scl) + 20) + (32 * scl) - ((32 * scl) / 4);
@@ -47,15 +60,7 @@ static void
if (cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 *
cl->tnum[10].img_h * cl->tnum[10].tex_y])
{
- cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
- (uint8_t)cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 *
- cl->tnum[10].img_w * cl->tnum[10].tex_y];
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
- (uint8_t)cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 *
- cl->tnum[10].img_w * cl->tnum[10].tex_y + 1];
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
- (uint8_t)cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 *
- cl->tnum[10].img_w * cl->tnum[10].tex_y + 2];
+ ft_draw_tnum(10, y, x, cl);
}
x++;
}
@@ -80,7 +85,6 @@ 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_printf("h %hu | w %hu\n", y, x);
ft_put_percent_image(y, x, cl);
}
@@ -94,6 +98,6 @@ void
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_put_image_from_number(num, cl);
ft_memdel((void*)&num);
}