aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_find_item.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-01 17:23:03 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-01 17:23:03 +0200
commit623c6af72b22aca4bc43009b7039640595521b2e (patch)
treeb3a9896b06552f385c9bc2f536588e31b609fdcb /src/ft_find_item.c
parentKilling skeltons gives ammo, but still segv (diff)
download42-cub3d-623c6af72b22aca4bc43009b7039640595521b2e.tar.gz
42-cub3d-623c6af72b22aca4bc43009b7039640595521b2e.tar.bz2
42-cub3d-623c6af72b22aca4bc43009b7039640595521b2e.tar.xz
42-cub3d-623c6af72b22aca4bc43009b7039640595521b2e.tar.zst
42-cub3d-623c6af72b22aca4bc43009b7039640595521b2e.zip
Still segv but solved invalid read
Diffstat (limited to 'src/ft_find_item.c')
-rw-r--r--src/ft_find_item.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/ft_find_item.c b/src/ft_find_item.c
index 394e060..6d795c3 100644
--- a/src/ft_find_item.c
+++ b/src/ft_find_item.c
@@ -36,7 +36,7 @@ static uint16_t
uint16_t id;
id = 0;
- while (id <= 64)
+ while (id <= 32)
{
if (cl->sprites[10 + weap_id][id].s_pos_y == pos_y &&
cl->sprites[10 + weap_id][id].s_pos_x == pos_x)
@@ -72,17 +72,22 @@ static void
weap_id = 1;
else if (map_char == '#')
weap_id = 2;
+ else if (map_char == 'x')
+ weap_id = 3;
cl->mlist.map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0';
- that_id = ft_fetch_weaps_id(weap_id, (uint64_t)pl->pos_y,
+ if (weap_id != 3)
+ {
+ 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;
+ 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 == 3) ? (2) : (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);
- cl->sfx[6 + (weap_id * 2)].sfx_play(cl->sfx);
+ ft_set_ammo((weap_id == 3) ? (2) : (weap_id), pl);
+ cl->sfx[6 + (((weap_id == 3) ? (2) : (weap_id)) * 2)].sfx_play(cl->sfx);
}
}