/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_key_events.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: joelecle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:55 by joelecle #+# #+# */ /* Updated: 2020/02/14 17:28:55 by joelecle ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include static void ft_insert_key(uint16_t keycode, t_cub *clist) { uint8_t i; i = 0; while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1) i++; clist->key_input[i] = keycode; } int ft_key_event(int keycode, t_cub *clist) { const int32_t tmp_code = keycode; keycode = ft_convert_keycode(tmp_code); if (keycode == FT_ESC_KEY) return (ft_exit(0, (clist))); else if (keycode == FT_F1_KEY || keycode == FT_TAB_KEY) return (ft_f1_key(clist)); else if (keycode == FT_SPC_KEY && clist->plist.handles_weapon > -1) return (ft_space_key(clist)); else if (keycode == FT_ONE_KEY && clist->plist.fire == 0 && clist->plist.has_weapon[0] == 1 && clist->plist.handles_weapon != 0) return (ft_switch_weap_one(clist)); else if (keycode == FT_TWO_KEY && clist->plist.fire == 0 && clist->plist.has_weapon[1] == 1 && clist->plist.handles_weapon != 2) return (ft_switch_weap_two(clist)); else if (keycode == FT_THREE_KEY && clist->plist.fire == 0 && clist->plist.has_weapon[2] == 1 && clist->plist.handles_weapon != 4) return (ft_switch_weap_three(clist)); ft_insert_key(keycode, clist); return (0); }