aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_player_spawn.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-02-02 19:07:38 +0100
committerRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-02-02 19:07:38 +0100
commit8c3b79c41048539d01f689d2fd3262b9b08ed00b (patch)
tree8caf2d580961f59d35dd7df70a7825c79f1a6706 /src/ft_get_player_spawn.c
parentAdded player list (diff)
download42-cub3d-8c3b79c41048539d01f689d2fd3262b9b08ed00b.tar.gz
42-cub3d-8c3b79c41048539d01f689d2fd3262b9b08ed00b.tar.bz2
42-cub3d-8c3b79c41048539d01f689d2fd3262b9b08ed00b.tar.xz
42-cub3d-8c3b79c41048539d01f689d2fd3262b9b08ed00b.tar.zst
42-cub3d-8c3b79c41048539d01f689d2fd3262b9b08ed00b.zip
Parsed player spawn
Diffstat (limited to 'src/ft_get_player_spawn.c')
-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++;
+ }
+}