diff options
Diffstat (limited to '')
-rw-r--r-- | inc/cub3d_defines.h | 1 | ||||
-rw-r--r-- | src/ft_find_item.c | 27 |
2 files changed, 23 insertions, 5 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index c423ac7..89af3c3 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -151,6 +151,7 @@ enum # define FT_CHRST_COLLISION "123456789 " # define FT_CHRST_DETECT "1L" # define FT_CHRST_ITEM "!@+" +# define FT_CHRST_WEAPONS "!@" /* ** ====== BMP ====== diff --git a/src/ft_find_item.c b/src/ft_find_item.c index d00b62d..1c3e9a0 100644 --- a/src/ft_find_item.c +++ b/src/ft_find_item.c @@ -29,16 +29,32 @@ static uint16_t return (0); } +static void + ft_weapon_check(const char map_char, t_player *pl, t_cub *cl) +{ + uint8_t weap_id; + + if (ft_ischarset(FT_CHRST_WEAPONS, map_char)) + { + weap_id = (map_char == '!') ? (0) : (1); + cl->mlist.map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0'; + cl->weaps[weap_id][0].s_pos_x = 0; + cl->weaps[weap_id][0].s_pos_y = 0; + pl->has_weapon[weap_id] = 1; + pl->handles_weapon = weap_id; + /* TODO: ft_sfx_weapon(3) */ + } +} + void ft_find_item(t_player *pl, t_map *ml, t_cub *cl) { - uint16_t id; + uint16_t id; + const char map_char = ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x]; - if (ft_ischarset(FT_CHRST_ITEM, - ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x])) + if (ft_ischarset(FT_CHRST_ITEM, map_char)) { - if (ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] == '+' - && pl->life < 100) + if (map_char == '+' && pl->life < 100) { pl->life += FT_HEAL_PACK_AMOUNT; pl->life = (pl->life > 100) ? (100) : (pl->life); @@ -49,5 +65,6 @@ void cl->heals[id].s_pos_y = 0; /* TODO: ft_sfx_heal(3) */ } + ft_weapon_check(map_char, pl, cl); } } |