From b5db3b2ddc383fe66c4d7d00fd7cd1cfb5a9fe9c Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Sun, 2 Feb 2020 20:53:04 +0100 Subject: I can't turn --- inc/cub3d.h | 6 +++--- src/ft_drawmap.c | 4 ++-- src/ft_key_events.c | 30 +++++++++++++++--------------- src/ft_print_list.c | 4 ---- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/inc/cub3d.h b/inc/cub3d.h index 6c9d380..6dcd67b 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -52,9 +52,9 @@ typedef struct s_win typedef struct s_player { - size_t pos_x; - size_t pos_y; - uint8_t view_side; + float pos_x; + float pos_y; + float view_side; } t_player; typedef struct s_cub diff --git a/src/ft_drawmap.c b/src/ft_drawmap.c index eac41ba..d5c545a 100644 --- a/src/ft_drawmap.c +++ b/src/ft_drawmap.c @@ -46,8 +46,8 @@ static void static void ft_draw_player(t_player *plist, t_cub *clist) { - const size_t x = plist->pos_x; - const size_t y = plist->pos_y; + const float x = plist->pos_x; + const float y = plist->pos_y; ft_drawsquare(40 + (x * 41), 40 + (y * 41), 0x009843fa, clist); } diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 3fbfc6f..da24f7e 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -22,13 +22,13 @@ static int pl = clist->plist; if (pl->view_side == 1) - pl->pos_y -= 1; + pl->pos_y -= 0.4; else if (pl->view_side == 2) - pl->pos_x += 1; + pl->pos_x += 0.4; else if (pl->view_side == 3) - pl->pos_y += 1; + pl->pos_y += 0.4; else if (pl->view_side == 4) - pl->pos_x -= 1; + pl->pos_x -= 0.4; ft_drawmap(clist); return (0); } @@ -39,9 +39,9 @@ static int t_player *pl; pl = clist->plist; - pl->view_side -= 1; - if (pl->view_side == 0) - pl->view_side = 4; + pl->view_side -= 1.0; + if (pl->view_side < 1.0) + pl->view_side = 4.0; return (0); } @@ -51,14 +51,14 @@ static int t_player *pl; pl = clist->plist; - if (pl->view_side == 1) - pl->pos_y += 1; + if (pl->view_side >= 1) + pl->pos_y += 0.4; else if (pl->view_side == 2) - pl->pos_x -= 1; + pl->pos_x -= 0.4; else if (pl->view_side == 3) - pl->pos_y -= 1; + pl->pos_y -= 0.4; else if (pl->view_side == 4) - pl->pos_x += 1; + pl->pos_x += 0.4; ft_drawmap(clist); return (0); } @@ -69,9 +69,9 @@ static int t_player *pl; pl = clist->plist; - pl->view_side += 1; - if (pl->view_side == 5) - pl->view_side = 1; + pl->view_side += 1.0; + if (pl->view_side > 4.0) + pl->view_side = 1.0; return (0); } diff --git a/src/ft_print_list.c b/src/ft_print_list.c index 5f59bc0..601a498 100644 --- a/src/ft_print_list.c +++ b/src/ft_print_list.c @@ -36,9 +36,5 @@ void i++; } ft_printf("Map width -- [%zu]\n", clist->map_w); - ft_printf("----\n"); - ft_printf("Player pos X [%zu]\n", clist->plist->pos_x); - ft_printf("Player pos Y [%zu]\n", clist->plist->pos_y); - ft_printf("Player view [%hhu]\n", clist->plist->view_side); ft_printf("----------------------\n"); } -- cgit v1.2.3