aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_key_loop.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 20:24:57 +0100
committerRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 20:24:57 +0100
commitbe34d7c8b2565ac055f9dc77111a1029ebd87d77 (patch)
tree750ceb2402800c855c04c3e66a7294f11c09a7b1 /src/ft_key_loop.c
parentMulti-key in progress (diff)
download42-cub3d-be34d7c8b2565ac055f9dc77111a1029ebd87d77.tar.gz
42-cub3d-be34d7c8b2565ac055f9dc77111a1029ebd87d77.tar.bz2
42-cub3d-be34d7c8b2565ac055f9dc77111a1029ebd87d77.tar.xz
42-cub3d-be34d7c8b2565ac055f9dc77111a1029ebd87d77.tar.zst
42-cub3d-be34d7c8b2565ac055f9dc77111a1029ebd87d77.zip
sex
Diffstat (limited to 'src/ft_key_loop.c')
-rw-r--r--src/ft_key_loop.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
new file mode 100644
index 0000000..b902e33
--- /dev/null
+++ b/src/ft_key_loop.c
@@ -0,0 +1,53 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_key_loop.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */
+/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_collision(float old_y, float old_x, t_player *pl, t_map *ml)
+{
+ const size_t x = pl->pos_x;
+ const size_t y = pl->pos_y;
+
+ if (ml->map[y][x] == '1')
+ {
+ pl->pos_y = old_y;
+ pl->pos_x = old_x;
+ }
+}
+
+int
+ ft_key_loop(t_cub *cl)
+{
+ int (*fun_ptr[6])(t_cub*);
+ uint8_t i;
+ const float old_y = cl->plist->pos_y;
+ const float old_x = cl->plist->pos_x;
+
+ fun_ptr[0] = ft_w_key;
+ fun_ptr[1] = ft_a_key;
+ fun_ptr[2] = ft_s_key;
+ fun_ptr[3] = ft_d_key;
+ fun_ptr[4] = ft_left_key;
+ fun_ptr[5] = ft_right_key;
+ i = 0;
+ while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5)
+ {
+ (*fun_ptr[cl->key_input[i]])(cl);
+ ft_collision(old_y, old_x, cl->plist, cl->mlist);
+ ft_draw_scene(cl);
+ i++;
+ }
+ return (0);
+}