summaryrefslogtreecommitdiff
path: root/src/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/input.c')
-rw-r--r--src/input.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/input.c b/src/input.c
new file mode 100644
index 0000000..2fcdc4e
--- /dev/null
+++ b/src/input.c
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* input.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/05/09 15:37:40 by dkaiser #+# #+# */
+/* Updated: 2024/05/09 17:48:20 by dkaiser ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "so_long.h"
+
+int on_key_down(int keycode, t_game *game)
+{
+ if (keycode == 13)
+ game->input_direction |= UP;
+ else if (keycode == 0)
+ game->input_direction |= LEFT;
+ else if (keycode == 1)
+ game->input_direction |= DOWN;
+ else if (keycode == 2)
+ game->input_direction |= RIGHT;
+ return (0);
+}
+
+int on_key_up(int keycode, t_game *game)
+{
+ if (keycode == 13)
+ game->input_direction &= ~UP;
+ else if (keycode == 0)
+ game->input_direction &= ~LEFT;
+ else if (keycode == 1)
+ game->input_direction &= ~DOWN;
+ else if (keycode == 2)
+ game->input_direction &= ~RIGHT;
+ return (0);
+}