diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-20 16:51:31 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-20 16:51:31 +0100 |
commit | d99126692d9eefd345b4756017f4b7fb9cd75ba7 (patch) | |
tree | 61f72fda5b99804dea1ef0ca0f7ddc6e4ec6200b | |
parent | Added number images (diff) | |
download | 42-cub3d-d99126692d9eefd345b4756017f4b7fb9cd75ba7.tar.gz 42-cub3d-d99126692d9eefd345b4756017f4b7fb9cd75ba7.tar.bz2 42-cub3d-d99126692d9eefd345b4756017f4b7fb9cd75ba7.tar.xz 42-cub3d-d99126692d9eefd345b4756017f4b7fb9cd75ba7.tar.zst 42-cub3d-d99126692d9eefd345b4756017f4b7fb9cd75ba7.zip |
in progress
-rw-r--r-- | inc/cub3d_defines.h | 5 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 3 | ||||
-rw-r--r-- | src/ft_draw_hud.c | 6 | ||||
-rw-r--r-- | src/ft_draw_life_bar.c | 26 | ||||
-rw-r--r-- | src/ft_exit.c | 6 | ||||
-rw-r--r-- | src/ft_find_item.c | 4 | ||||
-rw-r--r-- | src/ft_get_fps_count.c | 2 | ||||
-rw-r--r-- | src/ft_init_lists.c | 2 | ||||
-rw-r--r-- | src/ft_tex_init.c | 20 | ||||
-rw-r--r-- | src/ft_warp_level.c | 4 |
10 files changed, 67 insertions, 11 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index c3739e4..7a86115 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -268,7 +268,8 @@ enum */ # define FT_PARSE_END_RET 25 -# define FT_TRAP_DAMAGE_AMOUNT 20 -# define FT_HEAL_PACK_AMOUNT 10 +# define FT_STRT_LIFE 200 +# define FT_TRAP_DAMAGE_AMOUNT 27 +# define FT_HEAL_PACK_AMOUNT 19 # endif diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 4532a3d..cd711ba 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -132,7 +132,7 @@ typedef struct s_player float plane_x; float plane_y; uint8_t fire; - int8_t life; + int16_t life; uint8_t has_weapon[2]; int8_t handles_weapon; } t_player; @@ -252,6 +252,7 @@ typedef struct s_cub struct s_rgb c_rgb; struct s_img tlist[20]; struct s_img tweap[4]; + struct s_img tnum[11]; struct s_sprite **sprites; struct s_sprite traps[512]; struct s_sprite heals[64]; diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c index 03e6d14..31d5021 100644 --- a/src/ft_draw_hud.c +++ b/src/ft_draw_hud.c @@ -45,7 +45,7 @@ static void x = 0; cl->tlist[16].tex_y = (y * y_ratio) >> 16; while (x < (uint16_t)((cl->mlist.map_w - * cl->mlist.scale) + 20 + (3 * cl->mlist.scale))) + * cl->mlist.scale) + 20 + (27 * cl->mlist.scale))) { cl->tlist[16].tex_x = (x * x_ratio) >> 16; ft_put_image_back_to_ptr(y, x, cl); @@ -64,7 +64,7 @@ static void x = 0; y = wl->y_size - (map_h * scl) - 20; - while (x < (map_w * scl) + 20 + (3 * scl)) + while (x < (map_w * scl) + 20 + (27 * scl)) { while (y < wl->y_size) y++; @@ -107,7 +107,7 @@ int8_t ft_draw_minimap_back(clist->mlist.map_h, clist->mlist.map_w, &clist->wlist, clist); ft_draw_map(clist->mlist.map, clist); - /* ft_draw_life_bar(&clist->wlist, clist); */ + ft_draw_life_bar(&clist->wlist, 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 153a71e..f9d5227 100644 --- a/src/ft_draw_life_bar.c +++ b/src/ft_draw_life_bar.c @@ -10,12 +10,36 @@ /* */ /* ************************************************************************** */ +#include <libft.h> #include <cub3d.h> #include <stdint.h> +/* static void */ +/* ft_put_image_from_number(char *num, t_cub *cl) */ +/* { */ +/* } */ + +static void + ft_put_percent_image(t_cub *cl) +{ + int32_t x_ratio; + int32_t y_ratio; + + x_ratio = (int)((cl->tnum[10].img_w << 16) / (7 * cl->mlist.scale)) + 1; + y_ratio = (int)((cl->tnum[10].img_h << 16) / + ((cl->mlist.map_h * cl->mlist.scale) - 20)) + 1; +} + void ft_draw_life_bar(t_win *wl, t_cub *cl) { + char *num; + float calc; + 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); (void)wl; - (void)cl; + ft_put_percent_image(cl); + /* ft_put_image_from_number(num, cl); */ + ft_memdel((void*)&num); } diff --git a/src/ft_exit.c b/src/ft_exit.c index f753f84..b9e68d0 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -80,6 +80,8 @@ static void static void ft_del_tex(t_cub *clist) { + int8_t i; + if (clist->tlist[0].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[0].img); if (clist->tlist[1].img) @@ -102,6 +104,10 @@ static void mlx_destroy_image(clist->wlist.wlx, clist->tlist[16].img); if (clist->mlist.isheals && clist->tlist[17].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[17].img); + i = -1; + while (++i < 11) + if (clist->tnum[i].img) + mlx_destroy_image(clist->wlist.wlx, clist->tnum[i].img); ft_del_extra_sprites(clist); } diff --git a/src/ft_find_item.c b/src/ft_find_item.c index b55e9d9..56e1351 100644 --- a/src/ft_find_item.c +++ b/src/ft_find_item.c @@ -54,10 +54,10 @@ void if (ft_ischarset(FT_CHRST_ITEM, map_char)) { - if (map_char == '+' && pl->life < 100) + if (map_char == '+' && pl->life < FT_STRT_LIFE) { pl->life += FT_HEAL_PACK_AMOUNT; - pl->life = (pl->life > 100) ? (100) : (pl->life); + pl->life = (pl->life > FT_STRT_LIFE) ? (FT_STRT_LIFE) : (pl->life); ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0'; id = ft_fetch_heals_id((uint64_t)pl->pos_y, (uint64_t)pl->pos_x, cl); diff --git a/src/ft_get_fps_count.c b/src/ft_get_fps_count.c index 7ed1163..63bf08e 100644 --- a/src/ft_get_fps_count.c +++ b/src/ft_get_fps_count.c @@ -29,7 +29,7 @@ static void static clock_t curr_time = 0; curr_time += dt; - if (dt > 0 && ft_clock_to_ms(curr_time) > 400.0) + if (dt > 0 && ft_clock_to_ms(curr_time) > 300.0) { cl->plist.fire = 0; curr_time -= CLOCKS_PER_SEC; diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index efb243b..5e862ce 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -53,7 +53,7 @@ t_player plist.has_weapon[0] = 0; plist.has_weapon[1] = 0; plist.handles_weapon = -1; - plist.life = 100; + plist.life = FT_STRT_LIFE; plist.fire = 0; return (plist); } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 34f9fb9..5c0bed3 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -41,6 +41,15 @@ */ static void + ft_init_number(t_img *tnum, const char *path, t_cub *cl) +{ + tnum->img = mlx_xpm_file_to_image(cl->wlist.wlx, + path, &tnum->img_w, &tnum->img_h); + tnum->ptr = mlx_get_data_addr(tnum->img, + &tnum->bpp, &tnum->sizeline, &tnum->endian); +} + +static void ft_next_sprite_init(t_cub *cl) { uint8_t i; @@ -87,6 +96,17 @@ static void FT_WEAPON_TWO_SPR_PATH, &cl->tlist[19].img_w, &cl->tlist[19].img_h); cl->tlist[19].ptr = mlx_get_data_addr(cl->tlist[19].img, &cl->tlist[19].bpp, &cl->tlist[19].sizeline, &cl->tlist[19].endian); + ft_init_number(&cl->tnum[0], FT_ZER_PATH, cl); + ft_init_number(&cl->tnum[1], FT_ONE_PATH, cl); + ft_init_number(&cl->tnum[2], FT_TWO_PATH, cl); + ft_init_number(&cl->tnum[3], FT_THR_PATH, cl); + ft_init_number(&cl->tnum[4], FT_FOU_PATH, cl); + ft_init_number(&cl->tnum[5], FT_FIV_PATH, cl); + ft_init_number(&cl->tnum[6], FT_SIX_PATH, cl); + ft_init_number(&cl->tnum[7], FT_SEV_PATH, cl); + ft_init_number(&cl->tnum[8], FT_EIG_PATH, cl); + ft_init_number(&cl->tnum[9], FT_NIN_PATH, cl); + ft_init_number(&cl->tnum[10], FT_PER_PATH, cl); cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) ft_next_sprite_init(cl); diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index ca7801b..107e709 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -98,6 +98,10 @@ static void mlx_destroy_image(cl->wlist.wlx, cl->tweap[3].img); ft_del_extra_sprites(cl); i = -1; + while (++i < 11) + if (cl->tnum[i].img) + mlx_destroy_image(cl->wlist.wlx, cl->tnum[i].img); + i = -1; while (++i < 8) ft_memdel((void*)&cl->sprites[i]); ft_memdel((void*)&cl->sprites); |