aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_player_spawn.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_get_player_spawn.c56
1 files changed, 56 insertions, 0 deletions
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++;
+ }
+}