diff options
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); |