aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_check_map_line.c1
-rw-r--r--src/ft_check_missing.c2
-rw-r--r--src/ft_get_map.c1
-rw-r--r--src/ft_get_player_spawn.c56
-rw-r--r--src/ft_init_lists.c26
-rw-r--r--src/ft_parse_map.c1
-rw-r--r--src/ft_print_list.c1
7 files changed, 76 insertions, 12 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c
index 13baaef..1368b63 100644
--- a/src/ft_check_map_line.c
+++ b/src/ft_check_map_line.c
@@ -13,6 +13,7 @@
#include <libft.h>
#include <cub3d.h>
+#include <stddef.h>
#include <stdint.h>
size_t
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
index 4d7713d..9f3698b 100644
--- a/src/ft_check_missing.c
+++ b/src/ft_check_missing.c
@@ -41,5 +41,7 @@ int
return (ft_missing_error("floor color", clist));
else if (clist->c_color < 0)
return (ft_missing_error("ceiling color", clist));
+ else if (clist->plist->pos_x == 0 || clist->plist->pos_y == 0)
+ return (ft_missing_error("player spawn", clist));
return (0);
}
diff --git a/src/ft_get_map.c b/src/ft_get_map.c
index 00de520..b64da72 100644
--- a/src/ft_get_map.c
+++ b/src/ft_get_map.c
@@ -51,6 +51,7 @@ static int8_t
int
ft_get_map_first_line(char *line, t_cub *clist)
{
+ clist->map_start = clist->line_chk;
if (!line[0])
{
ft_memdel((void**)&line);
diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c
new file mode 100644
index 0000000..cb6dfcf
--- /dev/null
+++ b/src/ft_get_player_spawn.c
@@ -0,0 +1,56 @@
+/* ************************************************************************** */
+/* LE - / */
+/* / */
+/* ft_get_player_spawn.c .:: .:/ . .:: */
+/* +:+:+ +: +: +:+:+ */
+/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
+/* #+# #+ #+ #+# */
+/* Created: 2020/02/02 19:07:18 by rbousset #+# ## ## #+# */
+/* Updated: 2020/02/02 19:07:19 by rbousset ### #+. /#+ ###.fr */
+/* / */
+/* / */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+static uint8_t
+ ft_get_view_side(char c)
+{
+ if (c == 'N')
+ return (1);
+ else if (c == 'S')
+ return (2);
+ else if (c == 'E')
+ return (3);
+ else if (c == 'W')
+ return (4);
+ return (1);
+}
+
+void
+ ft_get_player_spawn(t_player *plist, t_cub *clist)
+{
+ size_t x;
+ size_t y;
+
+ x = 1;
+ y = 1;
+ while (clist->map[y])
+ {
+ while (clist->map[y][x])
+ {
+ if (ft_ischarset("NSEW", clist->map[y][x]))
+ {
+ plist->pos_x = x + 1;
+ plist->pos_y = y + 1;
+ plist->view_side = ft_get_view_side(clist->map[y][x]);
+ return ;
+ }
+ x++;
+ }
+ x = 1;
+ y++;
+ }
+}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index b7602ab..74c1b3d 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -17,18 +17,6 @@
#include <stddef.h>
#include <stdlib.h>
-t_player
- *ft_init_player(void)
-{
- t_player *plist;
-
- if (!(plist = (t_player*)malloc(sizeof(t_player))))
- return (NULL);
- plist->pos_x = 0;
- plist->pos_y = 0;
- return (plist);
-}
-
t_win
*ft_init_win(void)
{
@@ -45,6 +33,19 @@ t_win
return (wlist);
}
+static t_player
+ *ft_init_player(void)
+{
+ t_player *plist;
+
+ if (!(plist = (t_player*)malloc(sizeof(t_player))))
+ return (NULL);
+ plist->pos_x = 0;
+ plist->pos_y = 0;
+ plist->view_side = 0;
+ return (plist);
+}
+
t_cub
*ft_init_cub(void)
{
@@ -67,6 +68,7 @@ t_cub
clist->c_color = -1;
clist->map_w = 0;
clist->line_chk = 0;
+ clist->map_start = 0;
clist->isspawn = 0;
return (clist);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 41cab3d..29f2c43 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -116,6 +116,7 @@ void
if (ft_get_map_core(fd, clist) < 0)
ft_map_error(clist);
ft_check_map_last_line(clist);
+ ft_get_player_spawn(clist->plist, clist);
ft_check_missing(clist);
ft_print_list(clist);
close(fd);
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
index 45ef1fe..5f59bc0 100644
--- a/src/ft_print_list.c
+++ b/src/ft_print_list.c
@@ -39,5 +39,6 @@ void
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");
}