42_cub3d/input.c
2024-10-17 16:10:54 +02:00

52 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */
/* Updated: 2024/10/17 16:05:50 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "input.h"
#include <X11/keysym.h>
#include "algo.h"
t_input_actions g_input_actions;
static void set_action(int keycode, bool value)
{
if (keycode == XK_Up || keycode == XK_z || keycode == XK_w)
g_input_actions.up = value;
if (keycode == XK_Down || keycode == XK_s)
g_input_actions.down = value;
if (keycode == XK_Right || keycode == XK_d)
g_input_actions.right = value;
if (keycode == XK_Left || keycode == XK_q || keycode == XK_a)
g_input_actions.left = value;
if (keycode == XK_Escape)
g_input_actions.quit = value;
}
int keypress(int keycode)
{
set_action(keycode, true);
return (0);
}
int keyrelease(int keycode)
{
set_action(keycode, false);
return (0);
}
void input_init(void)
{
g_input_actions.down = false;
g_input_actions.up = false;
g_input_actions.left = false;
g_input_actions.right = false;
g_input_actions.quit = false;
}