From ced2be0469537a5d21043325c9bc54762197ec30 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Sat, 7 Mar 2020 20:30:07 +0100 Subject: qwe --- src/ft_darken_rgb.c | 33 +++++++++++++++++++++++---------- src/ft_draw_scene.c | 19 ++++++++----------- src/ft_draw_verline.c | 6 ++++-- src/ft_rgb_to_hex.c | 6 ++++++ 4 files changed, 41 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c index 3587d72..fe69fa2 100644 --- a/src/ft_darken_rgb.c +++ b/src/ft_darken_rgb.c @@ -15,20 +15,33 @@ #include uint32_t - ft_darken_rgb(t_rgb rgb, t_cub *cl) + ft_darken_ceil(t_rgb rgb, t_cub *cl) { t_rgb darker; - float dist; float calc; - if ((dist = cl->rlist.wall_dist) <= 0) - dist = 0.0001; - calc = (dist * 0.2); - calc = (calc >= 255) ? (255) : (calc); - calc = (calc < 1) ? (1) : (calc); darker = rgb; - darker.r /= calc; - darker.g /= calc; - darker.b /= calc; + calc = ((float)(cl->y - (75000.0 / cl->wlist.y_size)) + / (cl->wlist.y_size / 2)); + calc = (calc < 0) ? (0) : (calc); + darker.r *= 1 - calc; + darker.g *= 1 - calc; + darker.b *= 1 - calc; + return (ft_rgb_to_hex(darker)); +} + +uint32_t + ft_darken_floor(t_rgb rgb, t_cub *cl) +{ + t_rgb darker; + float calc; + + calc = ((float)(cl->y + (75000.0 / cl->wlist.y_size)) + / (cl->wlist.y_size / 2)) - 1.0; + calc = (calc < 0) ? (0) : (calc); + darker = rgb; + darker.r *= calc; + darker.g *= calc; + darker.b *= calc; return (ft_rgb_to_hex(darker)); } diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index f96eae6..e7895f5 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -21,20 +21,18 @@ static int8_t const uint32_t x = 15; const uint32_t y = clist->wlist.y_size - (clist->mlist.map_h * clist->mlist.scale) - 20; - const uint8_t len = 6 + ft_uintlen(clist->currlvl); + uint8_t len; char *str; + len = 6 + ft_uintlen(clist->currlvl); if (!(str = (char*)malloc((len + 1) * sizeof(char)))) return (-1); ft_sprintf(str, "Stage %hd", clist->currlvl); - if (clist->mlist.isnlvl) - { - mlx_string_put(clist->wlist.wlx, - clist->wlist.winptr, - x, y, - 0x00ff0000, - str); - } + mlx_string_put(clist->wlist.wlx, + clist->wlist.winptr, + x, y, + 0x00ff0000, + str); ft_memdel((void**)&str); return (0); } @@ -50,11 +48,10 @@ void if (clist->ishud) { ft_draw_hud(clist); - ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); } mlx_put_image_to_window(clist->wlist.wlx, clist->wlist.winptr, clist->img.img, 0, 0); - if (clist->ishud) + if (clist->ishud && clist->mlist.isnlvl) { if (ft_put_stage(clist) < 0) { diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 3198357..8621668 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -18,9 +18,10 @@ static void { while ((uint32_t)y < cl->wlist.y_size) { + cl->y = y; *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) - = ft_rgb_to_hex(cl->f_rgb); + = ft_darken_floor(cl->f_rgb, cl); y++; } } @@ -33,9 +34,10 @@ static void i = 0; while (i <= y) { + cl->y = i; *(int*)(cl->img.ptr + (x * 4 + (i * cl->img.sizeline))) - = ft_darken_rgb(cl->c_rgb, cl); + = ft_darken_ceil(cl->c_rgb, cl); i++; } } diff --git a/src/ft_rgb_to_hex.c b/src/ft_rgb_to_hex.c index a25d3e0..e101dcf 100644 --- a/src/ft_rgb_to_hex.c +++ b/src/ft_rgb_to_hex.c @@ -18,6 +18,12 @@ uint32_t { uint32_t res; + rgb.r = (rgb.r > 255) ? (255) : (rgb.r); + rgb.g = (rgb.g > 255) ? (255) : (rgb.g); + rgb.b = (rgb.b > 255) ? (255) : (rgb.b); + rgb.r = (rgb.r < 0) ? (0) : (rgb.r); + rgb.g = (rgb.g < 0) ? (0) : (rgb.g); + rgb.b = (rgb.b < 0) ? (0) : (rgb.b); res = 0; res += ((rgb.r << 16) + (rgb.g << 8) + rgb.b); return (res); -- cgit v1.2.3