diff options
-rw-r--r-- | inc/cub3d.h | 4 | ||||
-rw-r--r-- | src/ft_darken_rgb.c | 9 | ||||
-rw-r--r-- | src/ft_draw_hud.c | 4 | ||||
-rw-r--r-- | src/ft_draw_scene.c | 34 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 2 |
5 files changed, 46 insertions, 7 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index 6078801..692822a 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -65,7 +65,7 @@ void ft_calc_tex(t_cub *clist); void ft_draw_square(int a, int b, int rgb, t_cub *clist); void ft_draw_map(char **map, t_cub *clist); void ft_draw_texture(t_cub *cl, int x, int y, int tex_y); -void ft_draw_hud(t_cub *clist); +int8_t ft_draw_hud(t_cub *clist); void ft_draw_scene(t_cub *clist); void ft_draw_scene_bmp(t_cub *clist); void ft_draw_sprite(t_cub *cl, int i); @@ -130,7 +130,7 @@ uint8_t ft_free_words(char **words); int8_t ft_warp_level(t_cub *cl); int ft_exit(uint8_t exit_code, t_cub *clist); uint32_t ft_rgb_to_hex(t_rgb rgb); -uint32_t ft_darken_rgb(t_rgb rgb, int32_t y, t_cub *cl); +uint32_t ft_darken_rgb(t_rgb rgb, t_cub *cl); t_bmp_rgb ft_hex_to_rgb(uint32_t color); # endif diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c index 97d0c0e..3587d72 100644 --- a/src/ft_darken_rgb.c +++ b/src/ft_darken_rgb.c @@ -15,12 +15,15 @@ #include <stdio.h> uint32_t - ft_darken_rgb(t_rgb rgb, int32_t y, t_cub *cl) + ft_darken_rgb(t_rgb rgb, t_cub *cl) { t_rgb darker; - uint8_t calc; + float dist; + float calc; - calc = (((cl->wlist.y_size / 2) + y)), + 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; diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c index f807714..fe73af8 100644 --- a/src/ft_draw_hud.c +++ b/src/ft_draw_hud.c @@ -10,6 +10,7 @@ /* */ /* ************************************************************************** */ +#include <libft.h> #include <cub3d.h> #include <mlx.h> #include <stdint.h> @@ -43,10 +44,11 @@ static void } } -void +int8_t ft_draw_hud(t_cub *clist) { ft_draw_minimap_back(clist->mlist.map_h, clist->mlist.map_w, &clist->wlist, clist); ft_draw_map(clist->mlist.map, clist); + return (0); } diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 9461eef..f96eae6 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -15,6 +15,30 @@ #include <mlx.h> #include <stdint.h> +static int8_t + ft_put_stage(t_cub *clist) +{ + 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); + char *str; + + 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); + } + ft_memdel((void**)&str); + return (0); +} + void ft_draw_scene(t_cub *clist) { @@ -24,9 +48,19 @@ void &clist->img.sizeline, &clist->img.endian); ft_castray(clist); 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 (ft_put_stage(clist) < 0) + { + ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); + } + } mlx_destroy_image(clist->wlist.wlx, clist->img.img); } diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 5250dc7..3198357 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -35,7 +35,7 @@ static void { *(int*)(cl->img.ptr + (x * 4 + (i * cl->img.sizeline))) - = ft_rgb_to_hex(cl->c_rgb); + = ft_darken_rgb(cl->c_rgb, cl); i++; } } |