aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_key_events.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-02-11 15:32:21 +0100
committerRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-02-11 15:32:21 +0100
commit3f41d0eee51caff2f162098799932decf1ea72a8 (patch)
treea4cab1b701224a0aafac0c697eb4ecc719a9118e /src/ft_key_events.c
parentMap update (diff)
download42-cub3d-3f41d0eee51caff2f162098799932decf1ea72a8.tar.gz
42-cub3d-3f41d0eee51caff2f162098799932decf1ea72a8.tar.bz2
42-cub3d-3f41d0eee51caff2f162098799932decf1ea72a8.tar.xz
42-cub3d-3f41d0eee51caff2f162098799932decf1ea72a8.tar.zst
42-cub3d-3f41d0eee51caff2f162098799932decf1ea72a8.zip
On the way
Diffstat (limited to 'src/ft_key_events.c')
-rw-r--r--src/ft_key_events.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 5ca3d36..fe9f287 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -15,58 +15,52 @@
#include <cub3d.h>
#include <stdlib.h>
-static int
+static int8_t
ft_w_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
- if ((pl->pos_y -= 0.3) < 0.4)
- pl->pos_y = 0.4;
- ft_drawmap(clist);
+ pl->pos_y += 0.3 * (-1);
+ pl->pos_x += 0;
return (0);
}
-static int
+static int8_t
ft_a_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
- if ((pl->pos_x -= 0.3) < 0.4)
- pl->pos_x = 0.4;
- ft_drawmap(clist);
+ pl->pos_x -= 0.3;
return (0);
}
-static int
+static int8_t
ft_s_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
- if ((pl->pos_y += 0.3) > clist->map_h - 0.4)
- pl->pos_y = clist->map_h - 0.4;
- ft_drawmap(clist);
+ pl->pos_y += 0.3;
return (0);
}
-static int
+static int8_t
ft_d_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
- if ((pl->pos_x += 0.3) > clist->map_w - 0.4)
- pl->pos_x = clist->map_w - 0.4;
- ft_drawmap(clist);
+ pl->pos_x += 0.3;
return (0);
}
int
ft_key_event(int keycode, t_cub *clist)
{
- int (*fun_ptr[4])(t_cub*);
+ t_player *pl;
+ int8_t (*fun_ptr[4])(t_cub*);
const int8_t tmp_code = keycode;
fun_ptr[0] = ft_w_key;
@@ -78,9 +72,18 @@ int
(tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
(tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
(tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
+ pl = clist->plist;
if (keycode <= 3)
- return (*fun_ptr[keycode])(clist);
- if (keycode == FT_ESC_KEY)
+ {
+ (*fun_ptr[keycode])(clist);
+ (pl->pos_y < 0.4) ? (pl->pos_y = 0.4) : 0;
+ (pl->pos_x < 0.4) ? (pl->pos_x = 0.4) : 0;
+ (pl->pos_y > clist->map_h - 0.4) ? (pl->pos_y = clist->map_h - 0.4) : 0;
+ (pl->pos_x > clist->map_w - 0.4) ? (pl->pos_x = clist->map_w - 0.4) : 0;
+ ft_drawmap(clist);
+ return (0);
+ }
+ else if (keycode == FT_ESC_KEY)
return (ft_exit(0, (clist)));
return (0);
}