diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-22 23:42:05 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-22 23:42:05 +0100 |
commit | 1e84a8792302f0446e8eb838f478b4a6564d1011 (patch) | |
tree | 1968ab8d402596dc710afa4cf70335687e64637b /src | |
parent | Cleaner (diff) | |
download | 42-cub3d-1e84a8792302f0446e8eb838f478b4a6564d1011.tar.gz 42-cub3d-1e84a8792302f0446e8eb838f478b4a6564d1011.tar.bz2 42-cub3d-1e84a8792302f0446e8eb838f478b4a6564d1011.tar.xz 42-cub3d-1e84a8792302f0446e8eb838f478b4a6564d1011.tar.zst 42-cub3d-1e84a8792302f0446e8eb838f478b4a6564d1011.zip |
I think we good
Diffstat (limited to '')
-rw-r--r-- | src/ft_check_missing_defines.c | 14 | ||||
-rw-r--r-- | src/ft_del_tex.c | 4 | ||||
-rw-r--r-- | src/ft_draw_health_caption.c | 95 | ||||
-rw-r--r-- | src/ft_draw_hud.c | 1 | ||||
-rw-r--r-- | src/ft_draw_life_bar.c | 24 | ||||
-rw-r--r-- | src/ft_get_topsp.c | 18 | ||||
-rw-r--r-- | src/ft_init_lists.c | 4 | ||||
-rw-r--r-- | src/ft_tex_init.c | 28 | ||||
-rw-r--r-- | src/ft_tex_sprites_extra_init.c | 35 |
9 files changed, 185 insertions, 38 deletions
diff --git a/src/ft_check_missing_defines.c b/src/ft_check_missing_defines.c index d5d56b9..e32d7f7 100644 --- a/src/ft_check_missing_defines.c +++ b/src/ft_check_missing_defines.c @@ -42,6 +42,18 @@ static int return (ft_check_missing_sfx(clist)); } +static int + ft_check_missing_more_tex_defines(t_cub *clist) +{ + if (ft_check_not_found(FT_CAP_HEALTH_PATH) < 0 || + ft_check_ext(FT_CAP_HEALTH_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_H_CAPTION, clist)); + if (ft_check_not_found(FT_CAP_AMMO_PATH) < 0 || + ft_check_ext(FT_CAP_AMMO_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_A_CAPTION, clist)); + return (ft_check_missing_number_defines(clist)); +} + int ft_check_missing_tex_defines(t_cub *clist) { @@ -69,5 +81,5 @@ int if (ft_check_not_found(FT_WEAPON_THREE_FIRE_PATH) < 0 || ft_check_ext(FT_WEAPON_THREE_FIRE_PATH, ".xpm") < 0) return (ft_missing_error(FT_ERR_MISS_W_THREE_FIRE, clist)); - return (ft_check_missing_number_defines(clist)); + return (ft_check_missing_more_tex_defines(clist)); } diff --git a/src/ft_del_tex.c b/src/ft_del_tex.c index 55eff72..07265fa 100644 --- a/src/ft_del_tex.c +++ b/src/ft_del_tex.c @@ -77,6 +77,10 @@ static void mlx_destroy_image(cl->wlist.wlx, cl->tlist[19].img); if (cl->tlist[20].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[20].img); + if (cl->tlist[21].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[21].img); + if (cl->tlist[22].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[22].img); } void diff --git a/src/ft_draw_health_caption.c b/src/ft_draw_health_caption.c new file mode 100644 index 0000000..b2cb675 --- /dev/null +++ b/src/ft_draw_health_caption.c @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_health_caption.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */ +/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <stdint.h> + +static void + ft_draw_caption(uint16_t y, uint16_t x, t_cub *cl) +{ + const int16_t scl = cl->mlist.scale; + + cl->img.ptr[(x + (cl->mlist.map_w * scl) + 20) * 4 + + (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl) + - 5))] = + (uint8_t)cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 * + cl->tlist[21].img_w * cl->tlist[21].tex_y]; + cl->img.ptr[(x + (cl->mlist.map_w * scl) + 20) * 4 + + (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl) + - 5)) + 1] = + (uint8_t)cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 * + cl->tlist[21].img_w * cl->tlist[21].tex_y + 1]; + cl->img.ptr[(x + (cl->mlist.map_w * scl) + 20) * 4 + + (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl) + - 5)) + 2] = + (uint8_t)cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 * + cl->tlist[21].img_w * cl->tlist[21].tex_y + 2]; +} + +static void + ft_put_health_caption(t_cub *cl) +{ + int32_t x_ratio; + int32_t y_ratio; + int16_t x; + int16_t y; + + x_ratio = (int)(((cl->tlist[21].img_w) << 16) / cl->life_cap_w) + 1; + y_ratio = (int)(((cl->tlist[21].img_h) << 16) / cl->life_cap_h) + 1; + y = 0; + while (y < cl->life_cap_h) + { + cl->tlist[21].tex_y = ((y * y_ratio) >> 16); + x = 0; + while (x < cl->life_cap_w) + { + cl->tlist[21].tex_x = ((x * x_ratio) >> 16); + if (cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 * + cl->tlist[21].img_h * cl->tlist[21].tex_y]) + ft_draw_caption(y, x, cl); + x++; + } + y++; + } +} + +static void + ft_get_hw(t_cub *cl) +{ + int16_t x; + int16_t y; + const int16_t scl = cl->mlist.scale; + + x = (cl->mlist.map_w * scl) + 20; + y = cl->wlist.y_size - (cl->mlist.map_h * scl) - 10; + while (y < (int16_t)((cl->wlist.y_size - 10) + - ((cl->mlist.map_h * scl) / 1.3))) + { + x = (cl->mlist.map_w * scl) + 20; + while (x < (int16_t)((cl->mlist.map_w * scl) + 10 + ((24 * scl)))) + x++; + y++; + } + y -= cl->wlist.y_size - (cl->mlist.map_h * scl) - 10; + x -= (cl->mlist.map_w * scl) + 20; + y = (y <= 0) ? (1) : (y); + x = (x <= 0) ? (1) : (x); + cl->life_cap_h = y; + cl->life_cap_w = x; +} + +void + ft_draw_health_caption(t_cub *cl) +{ + ft_get_hw(cl); + ft_put_health_caption(cl); +} diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c index 868d149..75498d8 100644 --- a/src/ft_draw_hud.c +++ b/src/ft_draw_hud.c @@ -108,6 +108,7 @@ int8_t clist->mlist.map_w, &clist->wlist, clist); ft_draw_map(clist->mlist.map, clist); ft_draw_life_bar(clist); + ft_draw_health_caption(clist); if (clist->mlist.isnlvl) { ft_draw_stage_back(clist); diff --git a/src/ft_draw_life_bar.c b/src/ft_draw_life_bar.c index c2aa68f..955f20d 100644 --- a/src/ft_draw_life_bar.c +++ b/src/ft_draw_life_bar.c @@ -21,17 +21,17 @@ static void cl->img.ptr[(x + (int16_t)((cl->mlist.map_w * scl) + 10)) * 4 + (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl) - - 10))] = + + 40))] = (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 + (int16_t)((cl->mlist.map_w * scl) + 10)) * 4 + (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl) - - 10)) + 1] = + + 40)) + 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 + (int16_t)((cl->mlist.map_w * scl) + 10)) * 4 + (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl) - - 10)) + 2] = + + 40)) + 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]; } @@ -44,14 +44,14 @@ static void int16_t x; int16_t y; - 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; + x_ratio = (int)(((cl->tnum[n - 48].img_w) << 16) / cl->life_num_w) + 1; + y_ratio = (int)(((cl->tnum[n - 48].img_h) << 16) / cl->life_num_h) + 1; y = 0; - while (y < cl->h) + while (y < cl->life_num_h) { cl->tnum[n - 48].tex_y = ((y * y_ratio) >> 16); x = 0; - while (x < cl->w) + while (x < cl->life_num_w) { cl->tnum[n - 48].tex_x = ((x * x_ratio) >> 16); if (cl->tnum[n - 48].ptr[cl->tnum[n - 48].tex_x * 4 + 4 * @@ -94,7 +94,7 @@ static void x = ((cl->mlist.map_w * scl) + 20) + (24 * scl) - ((24 * scl) / 4); y = cl->wlist.y_size - (cl->mlist.map_h * scl) - 10; - while (y < (int16_t)(cl->wlist.y_size - 10)) + while (y < (int16_t)(cl->wlist.y_size - 50)) { x = ((cl->mlist.map_w * scl) + 20) + (24 * scl) - ((24 * scl) / 4); while (x < (int16_t)((cl->mlist.map_w * scl) + 10 + ((24 * scl)))) @@ -103,10 +103,10 @@ static void } y -= cl->wlist.y_size - (cl->mlist.map_h * scl) - 10; x -= ((cl->mlist.map_w * scl) + 20) + (24 * scl) - ((24 * scl) / 4); - y = (y == 0) ? (1) : (y); - x = (x == 0) ? (1) : (x); - cl->h = y; - cl->w = x; + y = (y <= 0) ? (1) : (y); + x = (x <= 0) ? (1) : (x); + cl->life_num_h = y; + cl->life_num_w = x; } void diff --git a/src/ft_get_topsp.c b/src/ft_get_topsp.c index ee16714..84339c3 100644 --- a/src/ft_get_topsp.c +++ b/src/ft_get_topsp.c @@ -18,13 +18,15 @@ void ft_get_topsp(char c, t_cub *clist) { - int8_t x; + (void)c; + (void)clist; + /* int8_t x; */ - if ((x = ft_strlchr(FT_CHRST_SPRITES, c)) > 0) - { - if ((x + 2) > clist->mlist.topsp) - { - clist->mlist.topsp = x + 2; - } - } + /* if ((x = ft_strlchr(FT_CHRST_SPRITES, c)) > 0) */ + /* { */ + /* if ((x + 2) > clist->mlist.topsp) */ + /* { */ + /* clist->mlist.topsp = x + 2; */ + /* } */ + /* } */ } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index dbf944d..d9a2ad2 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -117,7 +117,7 @@ int8_t ft_sprintf(clist->fps_count, "fps: 60"); clist->isdead = 0; clist->moves = 0; - clist->h = 0; - clist->w = 0; + clist->life_num_h = 0; + clist->life_num_w = 0; return (0); } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index effe6a1..a6eec43 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -38,25 +38,22 @@ ** 17: heal pack ** 18: weapon one sprite ** 19: weapon two sprite -** 20: weapon two sprite +** 20: weapon three sprite +** 21: health caption +** 22: ammo caption */ static void - ft_next_sprite_init(t_cub *cl) + ft_wall_tex_init_even_more_bonus(t_cub *cl) { - uint8_t i; - - i = 1; - while (cl->mlist.sprite_path[i][0]) - { - cl->tlist[i + 7].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.sprite_path[i], &cl->tlist[i + 7].img_w, - &cl->tlist[i + 7].img_h); - cl->tlist[i + 7].ptr = mlx_get_data_addr(cl->tlist[i + 7].img, - &cl->tlist[i + 7].bpp, &cl->tlist[i + 7].sizeline, - &cl->tlist[i + 7].endian); - i++; - } + cl->tlist[21].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_CAP_HEALTH_PATH, &cl->tlist[21].img_w, &cl->tlist[21].img_h); + cl->tlist[21].ptr = mlx_get_data_addr(cl->tlist[21].img, + &cl->tlist[21].bpp, &cl->tlist[21].sizeline, &cl->tlist[21].endian); + cl->tlist[22].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_CAP_AMMO_PATH, &cl->tlist[22].img_w, &cl->tlist[22].img_h); + cl->tlist[22].ptr = mlx_get_data_addr(cl->tlist[22].img, + &cl->tlist[22].bpp, &cl->tlist[22].sizeline, &cl->tlist[22].endian); } static void @@ -78,6 +75,7 @@ static void FT_WEAPON_THREE_SPR_PATH, &cl->tlist[20].img_w, &cl->tlist[20].img_h); cl->tlist[20].ptr = mlx_get_data_addr(cl->tlist[20].img, &cl->tlist[20].bpp, &cl->tlist[20].sizeline, &cl->tlist[20].endian); + ft_wall_tex_init_even_more_bonus(cl); cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) ft_next_sprite_init(cl); diff --git a/src/ft_tex_sprites_extra_init.c b/src/ft_tex_sprites_extra_init.c new file mode 100644 index 0000000..9ff7612 --- /dev/null +++ b/src/ft_tex_sprites_extra_init.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tex_sprites_extra_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fmoenne- <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:43:55 by fmoenne- #+# #+# */ +/* Updated: 2020/02/14 17:43:56 by fmoenne- ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <mlx.h> + +void + ft_next_sprite_init(t_cub *cl) +{ + uint8_t i; + + i = 1; + while (cl->mlist.sprite_path[i][0]) + { + cl->tlist[i + 7].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.sprite_path[i], &cl->tlist[i + 7].img_w, + &cl->tlist[i + 7].img_h); + cl->tlist[i + 7].ptr = mlx_get_data_addr(cl->tlist[i + 7].img, + &cl->tlist[i + 7].bpp, &cl->tlist[i + 7].sizeline, + &cl->tlist[i + 7].endian); + i++; + } + cl->mlist.topsp = i + 1; +} |