aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/cub3d.h4
-rw-r--r--src/ft_get_player_spawn.c4
-rw-r--r--src/ft_key_events.c39
3 files changed, 39 insertions, 8 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 8d3b39a..6c9d380 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -45,8 +45,8 @@ typedef struct s_win
/*
** view_side:
** 1: North
-** 2: South
-** 3: East
+** 2: East
+** 3: South
** 4: West
*/
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);
}