diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:38:46 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:38:46 +0200 |
commit | a07392fc219afc45000201d2f495694ad9b82763 (patch) | |
tree | 0eb3f2b9003ad7ceae4692242e46de56e55053b0 /src/ft_find_item.c | |
parent | Removed skybox shit (diff) | |
parent | Norm (diff) | |
download | 42-cub3d-a07392fc219afc45000201d2f495694ad9b82763.tar.gz 42-cub3d-a07392fc219afc45000201d2f495694ad9b82763.tar.bz2 42-cub3d-a07392fc219afc45000201d2f495694ad9b82763.tar.xz 42-cub3d-a07392fc219afc45000201d2f495694ad9b82763.tar.zst 42-cub3d-a07392fc219afc45000201d2f495694ad9b82763.zip |
Merge branch 'fix-details'
Diffstat (limited to 'src/ft_find_item.c')
-rw-r--r-- | src/ft_find_item.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/ft_find_item.c b/src/ft_find_item.c index 59b4a4f..394e060 100644 --- a/src/ft_find_item.c +++ b/src/ft_find_item.c @@ -22,7 +22,24 @@ static uint16_t id = 0; while (id <= 64) { - if (cl->heals[id].s_pos_y == pos_y && cl->heals[id].s_pos_x == pos_x) + if (cl->sprites[9][id].s_pos_y == pos_y && + cl->sprites[9][id].s_pos_x == pos_x) + return (id); + id++; + } + return (0); +} + +static uint16_t + ft_fetch_weaps_id(int8_t weap_id, uint64_t pos_y, uint64_t pos_x, t_cub *cl) +{ + uint16_t id; + + id = 0; + while (id <= 64) + { + if (cl->sprites[10 + weap_id][id].s_pos_y == pos_y && + cl->sprites[10 + weap_id][id].s_pos_x == pos_x) return (id); id++; } @@ -46,6 +63,7 @@ static void ft_weapon_check(const char map_char, t_player *pl, t_cub *cl) { uint8_t weap_id; + uint8_t that_id; if (ft_ischarset(FT_CHRST_WEAPONS, map_char)) { @@ -55,19 +73,16 @@ static void else if (map_char == '#') weap_id = 2; 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; + that_id = ft_fetch_weaps_id(weap_id, (uint64_t)pl->pos_y, + (uint64_t)pl->pos_x, cl); + cl->sprites[10 + weap_id][that_id].s_pos_x = 0; + cl->sprites[10 + weap_id][that_id].s_pos_y = 0; pl->has_weapon[weap_id] = 1; pl->handles_weapon = (weap_id == 0) ? (0) : (pl->handles_weapon); pl->handles_weapon = (weap_id == 1) ? (2) : (pl->handles_weapon); pl->handles_weapon = (weap_id == 2) ? (4) : (pl->handles_weapon); ft_set_ammo(weap_id, pl); - if (weap_id == 0) - cl->sfx[6].sfx_play(cl->sfx); - else if (weap_id == 1) - cl->sfx[8].sfx_play(cl->sfx); - else if (weap_id == 2) - cl->sfx[10].sfx_play(cl->sfx); + cl->sfx[6 + (weap_id * 2)].sfx_play(cl->sfx); } } @@ -86,8 +101,8 @@ void 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; + cl->sprites[9][id].s_pos_x = 0; + cl->sprites[9][id].s_pos_y = 0; cl->sfx[5].sfx_play(cl->sfx); } ft_weapon_check(map_char, pl, cl); |