aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-11 10:16:48 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-11 10:16:48 +0100
commitc581c7e3543058f015bddf96d76ac2d771ea40a0 (patch)
treeb3c8fe72a65ac834fcd7edaef4e2887f49d53c90
parentParsed traps (diff)
download42-cub3d-c581c7e3543058f015bddf96d76ac2d771ea40a0.tar.gz
42-cub3d-c581c7e3543058f015bddf96d76ac2d771ea40a0.tar.bz2
42-cub3d-c581c7e3543058f015bddf96d76ac2d771ea40a0.tar.xz
42-cub3d-c581c7e3543058f015bddf96d76ac2d771ea40a0.tar.zst
42-cub3d-c581c7e3543058f015bddf96d76ac2d771ea40a0.zip
Nice parse
-rw-r--r--inc/cub3d.h3
-rw-r--r--inc/cub3d_structs.h2
-rw-r--r--map/map_one.cub1
-rw-r--r--src/ft_check_map_line.c2
-rw-r--r--src/ft_exit.c2
-rw-r--r--src/ft_get_traps.c28
-rw-r--r--src/ft_init_funptr.c2
-rw-r--r--src/ft_init_map.c4
-rw-r--r--src/ft_select_get.c4
-rw-r--r--src/ft_tex_init.c2
-rw-r--r--src/ft_warp_level.c2
11 files changed, 45 insertions, 7 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index bb30122..9487883 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -77,7 +77,6 @@ void ft_sprite_width(t_cub *cl, t_sprite *sprite);
void ft_sprite_height(t_cub *cl, t_sprite *sprite);
void ft_calc_sprite(t_cub *cl);
void ft_draw_sprite(t_cub *cl, t_sprite *sprite);
-void ft_get_sprite_spawn(t_cub *cl);
void ft_draw_skybox(t_cub *cl);
/*
@@ -107,6 +106,8 @@ int8_t ft_get_tex_nl(char **words, t_cub *clist);
int8_t ft_get_music(char **words, t_cub *clist);
size_t ft_get_map_h(char **map);
size_t ft_get_map_w(char **map);
+void ft_get_sprite_spawn(t_cub *clist);
+void ft_get_trap_spawn(t_cub *clist);
int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist);
int8_t ft_check_ext(const char *filep, const char *ext);
int8_t ft_check_not_found(const char *path);
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 89e531a..5ba3b38 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -192,7 +192,7 @@ typedef struct s_map
uint8_t isftex;
uint8_t isctex;
uint8_t isskybox;
- uint8_t istrap;
+ uint8_t istraps;
uint8_t darklvl;
uint8_t scale;
uint32_t nlx;
diff --git a/map/map_one.cub b/map/map_one.cub
index 1f7a92c..540e7c2 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -9,6 +9,7 @@ S ./media/img/pillar.xpm
C 50,100,200
F 50,190,124
+T ./media/img/linus.xpm
SH 4
111111111111111111
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c
index 7fa68b7..c88e1f5 100644
--- a/src/ft_check_map_line.c
+++ b/src/ft_check_map_line.c
@@ -37,6 +37,8 @@ static int8_t
ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL);
return (-1);
}
+ if (line[i] == 'T')
+ clist->mlist.istraps = 1;
return (0);
}
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 4125567..4a131c8 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -62,7 +62,7 @@ static void
mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img);
if (clist->mlist.isctex && clist->tlist[7].img)
mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img);
- if (clist->mlist.istrap && clist->tlist[15].img)
+ if (clist->mlist.istraps && clist->tlist[15].img)
mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img);
}
diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c
index cdc05de..0235bb5 100644
--- a/src/ft_get_traps.c
+++ b/src/ft_get_traps.c
@@ -14,6 +14,34 @@
#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)
{
diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c
index c74b2c8..c299336 100644
--- a/src/ft_init_funptr.c
+++ b/src/ft_init_funptr.c
@@ -55,5 +55,5 @@ void
clist->get_ptr[10] = ft_get_music;
clist->get_ptr[11] = ft_get_darkness;
clist->get_ptr[12] = ft_get_skybox;
- clist->get_ptr[14] = ft_get_traps;
+ clist->get_ptr[13] = ft_get_traps;
}
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index f2b0726..867a5b0 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -61,7 +61,9 @@ int8_t
mlist->isnlvl = 0;
mlist->ismusic = 0;
mlist->isskybox = 0;
- mlist->istrap = 0;
+ mlist->istraps = 0;
+ mlist->sprite_nbr = 0;
+ mlist->traps_nbr = 0;
mlist->darklvl = 0;
mlist->scale = 0;
mlist->nlx = 0;
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index 2a95309..f748721 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -53,6 +53,10 @@ static int8_t
return (-1);
if (ret == 10 && (clist->mlist.music_path[0]))
return (-1);
+ if (ret == 12 && (clist->mlist.skybox_path[0]))
+ return (-1);
+ if (ret == 13 && (clist->mlist.traps_path[0]))
+ return (-1);
return (ret);
}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 32bfb66..30b738e 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -71,7 +71,7 @@ static void
cl->tlist[6].ptr = mlx_get_data_addr(cl->tlist[6].img,
&cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian);
}
- if (cl->mlist.istrap)
+ if (cl->mlist.istraps)
{
cl->tlist[15].img = mlx_xpm_file_to_image(cl->wlist.wlx,
cl->mlist.traps_path, &cl->tlist[15].img_w, &cl->tlist[15].img_h);
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index a4f705b..faaf322 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -61,7 +61,7 @@ static void
mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img);
if (cl->mlist.isctex && cl->tlist[7].img)
mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img);
- if (cl->mlist.istrap && cl->tlist[15].img)
+ if (cl->mlist.istraps && cl->tlist[15].img)
mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img);
}