diff options
author | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2020-02-02 20:29:00 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2020-02-02 20:29:00 +0100 |
commit | b7261229b7b83ebeae7384fd1a6d0cc3ee9eb50e (patch) | |
tree | 22581da209cf6e78c962eaeea4093f1156f706b1 /src | |
parent | It moves (diff) | |
download | 42-cub3d-b7261229b7b83ebeae7384fd1a6d0cc3ee9eb50e.tar.gz 42-cub3d-b7261229b7b83ebeae7384fd1a6d0cc3ee9eb50e.tar.bz2 42-cub3d-b7261229b7b83ebeae7384fd1a6d0cc3ee9eb50e.tar.xz 42-cub3d-b7261229b7b83ebeae7384fd1a6d0cc3ee9eb50e.tar.zst 42-cub3d-b7261229b7b83ebeae7384fd1a6d0cc3ee9eb50e.zip |
Cool
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_get_player_spawn.c | 4 | ||||
-rw-r--r-- | src/ft_key_events.c | 39 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 7b37d23..cc41955 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -20,9 +20,9 @@ static uint8_t { if (c == 'N') return (1); - else if (c == 'S') - return (2); else if (c == 'E') + return (2); + else if (c == 'S') return (3); else if (c == 'W') return (4); diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 697670c..0f3cbe2 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -18,8 +18,18 @@ static int ft_w_key(t_cub *clist) { + t_player *pl; + + pl = clist->plist; ft_printf("[W]\n"); - clist->plist->pos_y -= 1; + if (pl->view_side == 1) + pl->pos_y -= 1; + else if (pl->view_side == 2) + pl->pos_x += 1; + else if (pl->view_side == 3) + pl->pos_y += 1; + else if (pl->view_side == 4) + pl->pos_x -= 1; ft_drawmap(clist); return (0); } @@ -27,24 +37,45 @@ static int static int ft_a_key(t_cub *clist) { - (void)clist; + t_player *pl; + + pl = clist->plist; ft_printf("[A]\n"); + pl->view_side -= 1; + if (pl->view_side == 0) + pl->view_side = 4; return (0); } static int ft_s_key(t_cub *clist) { - (void)clist; + t_player *pl; + + pl = clist->plist; ft_printf("[S]\n"); + if (pl->view_side == 1) + pl->pos_y += 1; + else if (pl->view_side == 2) + pl->pos_x -= 1; + else if (pl->view_side == 3) + pl->pos_y -= 1; + else if (pl->view_side == 4) + pl->pos_x += 1; + ft_drawmap(clist); return (0); } static int ft_d_key(t_cub *clist) { - (void)clist; + t_player *pl; + + pl = clist->plist; ft_printf("[D]\n"); + pl->view_side += 1; + if (pl->view_side == 5) + pl->view_side = 1; return (0); } |