From 8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 22:21:29 +0100 Subject: ok bav --- src/ft_find_item.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/ft_find_item.c (limited to 'src/ft_find_item.c') diff --git a/src/ft_find_item.c b/src/ft_find_item.c new file mode 100644 index 0000000..782a24a --- /dev/null +++ b/src/ft_find_item.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_item.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ +/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +static uint16_t + ft_fetch_heals_id(uint64_t pos_y, uint64_t pos_x, t_cub *cl) +{ + uint16_t id; + + id = 0; + while (id <= 64) + { + if (cl->heals[id].s_pos_y == pos_y && cl->heals[id].s_pos_x == pos_x) + return (id); + id++; + } + return (0); +} + +void + ft_find_item(t_player *pl, t_map *ml, t_cub *cl) +{ + uint16_t id; + if (ft_ischarset(FT_CHRST_ITEM, + ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x])) + { + if (ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] == '+' + && pl->life < 100) + { + pl->life += FT_HEAL_PACK_AMOUNT; + pl->life = (pl->life > 100) ? (100) : (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); + cl->heals[id].s_pos_x = 0; + cl->heals[id].s_pos_y = 0; + /* TODO: ft_sfx_heal(3) */ + } + } +} -- cgit v1.2.3 From 5be59b518283b4737949bcbea597068df43487dc Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 22:34:45 +0100 Subject: Bug fix --- src/ft_find_item.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ft_find_item.c') diff --git a/src/ft_find_item.c b/src/ft_find_item.c index 782a24a..d00b62d 100644 --- a/src/ft_find_item.c +++ b/src/ft_find_item.c @@ -33,6 +33,7 @@ void ft_find_item(t_player *pl, t_map *ml, t_cub *cl) { uint16_t id; + if (ft_ischarset(FT_CHRST_ITEM, ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x])) { @@ -43,7 +44,7 @@ void pl->life = (pl->life > 100) ? (100) : (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); + (uint64_t)pl->pos_x, cl); cl->heals[id].s_pos_x = 0; cl->heals[id].s_pos_y = 0; /* TODO: ft_sfx_heal(3) */ -- cgit v1.2.3