aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_traps.c
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2020-03-11 18:59:58 +0100
committersalaaad2 <arthurdurant263@gmail.com>2020-03-11 18:59:58 +0100
commitb6388b5101d8187f746f91c89842e932a1d01cb6 (patch)
tree70bd9ba7012f5906db01b485ec8f58f5a4697240 /src/ft_get_traps.c
parentclose but no cigar (diff)
parentca tue (diff)
download42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.gz
42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.bz2
42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.xz
42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.zst
42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.zip
get merged
Diffstat (limited to 'src/ft_get_traps.c')
-rw-r--r--src/ft_get_traps.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c
new file mode 100644
index 0000000..0235bb5
--- /dev/null
+++ b/src/ft_get_traps.c
@@ -0,0 +1,70 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_get_tex_nl.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/28 18:24:52 by rbousset #+# #+# */
+/* Updated: 2020/02/28 18:24:56 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+void
+ ft_get_trap_spawn(t_cub *clist)
+{
+ size_t x;
+ size_t y;
+ uint8_t i;
+
+ x = 1;
+ y = 1;
+ i = 0;
+ while (clist->mlist.map[y])
+ {
+ while (clist->mlist.map[y][x])
+ {
+ if (clist->mlist.map[y][x] == 'T')
+ {
+ clist->mlist.traps_nbr++;
+ clist->traps[i].s_pos_x = x;
+ clist->traps[i].s_pos_y = y;
+ i++;
+ }
+ x++;
+ }
+ x = 1;
+ y++;
+ }
+}
+
+int8_t
+ ft_get_traps(char **words, t_cub *clist)
+{
+ if (!(*words) || !(*(words + 1)) || (*(words + 2)))
+ {
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS);
+ return (-1);
+ }
+ if (ft_check_ext(*(words + 1), ".xpm") < 0)
+ {
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
+ return (-1);
+ }
+ ft_memdel((void**)&clist->mlist.traps_path);
+ if (!(clist->mlist.traps_path = ft_strdup(*(words + 1))))
+ {
+ ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
+ return (-1);
+ }
+ if (ft_check_not_found(clist->mlist.traps_path) < 0)
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_RD_TRAP);
+ return (-1);
+ }
+ return (0);
+}