aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_key_events.c
diff options
context:
space:
mode:
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);
}