summaryrefslogtreecommitdiff
path: root/src/input.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-09 17:49:54 +0200
committerDominik Kaiser2024-05-09 17:49:54 +0200
commit14ffe0479dc33cb5ed96f85535f84fa91d56c48b (patch)
tree1b052671c87cdd54bef9d6b9e9e8fab39039fc45 /src/input.c
parent8cec16bdb6f980565b29d5b55379e481018753f6 (diff)
downloadso_long-14ffe0479dc33cb5ed96f85535f84fa91d56c48b.tar.gz
so_long-14ffe0479dc33cb5ed96f85535f84fa91d56c48b.zip
Add input to direction handling
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);
+}