diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-22 15:44:28 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-22 15:44:28 +0100 |
commit | 227bd9d88a5428179dd12a2c2c3432ca6505a505 (patch) | |
tree | fdde4d60c6a8c0310c7c2b863d6569a8f0c39a1f /src/ft_key_loop.c | |
parent | More norm (diff) | |
download | 42-cub3d-227bd9d88a5428179dd12a2c2c3432ca6505a505.tar.gz 42-cub3d-227bd9d88a5428179dd12a2c2c3432ca6505a505.tar.bz2 42-cub3d-227bd9d88a5428179dd12a2c2c3432ca6505a505.tar.xz 42-cub3d-227bd9d88a5428179dd12a2c2c3432ca6505a505.tar.zst 42-cub3d-227bd9d88a5428179dd12a2c2c3432ca6505a505.zip |
key_loop normed
Diffstat (limited to 'src/ft_key_loop.c')
-rw-r--r-- | src/ft_key_loop.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index 77f2d7d..22975f8 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -72,6 +72,29 @@ static void cl->plist.pos_y = old_y; } +static int + ft_handle_keys(uint8_t i, float old_y, float old_x, t_cub *cl) +{ + cl->key_ptr[cl->key_input[i]](cl); + if (cl->key_input[i] >= 0 && cl->key_input[i] <= 3) + { + cl->sfx[1].sfx_play(cl->sfx); + ft_collision(old_y, old_x, cl->key_input[i], cl); + ft_find_item(&cl->plist, &cl->mlist, cl); + if (cl->mlist.isnlvl) + { + if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && + (uint32_t)cl->plist.pos_y == cl->mlist.nly) + { + cl->sfx[2].sfx_play(cl->sfx); + return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ? + (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0)); + } + } + } + return (0); +} + int ft_key_loop(t_cub *cl) { @@ -83,23 +106,7 @@ int i = 0; while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5) { - cl->key_ptr[cl->key_input[i]](cl); - if (cl->key_input[i] >= 0 && cl->key_input[i] <= 3) - { - cl->sfx[1].sfx_play(cl->sfx); - ft_collision(old_y, old_x, cl->key_input[i], cl); - ft_find_item(&cl->plist, &cl->mlist, cl); - if (cl->mlist.isnlvl) - { - if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && - (uint32_t)cl->plist.pos_y == cl->mlist.nly) - { - cl->sfx[2].sfx_play(cl->sfx); - return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ? - (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0)); - } - } - } + ft_handle_keys(i, old_y, old_x, cl); i++; } cl->moves = (cl->key_input[0] == -1) ? (0) : (cl->moves); |