aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/cub3d_defines.h3
-rw-r--r--inc/cub3d_structs.h4
-rw-r--r--map/map_one.cub8
-rw-r--r--src/ft_exit.c2
-rw-r--r--src/ft_get_sprite.c57
-rw-r--r--src/ft_init_funptr.c9
-rw-r--r--src/ft_init_map.c18
-rw-r--r--src/ft_select_get.c8
-rw-r--r--src/ft_tex_init.c29
-rw-r--r--src/ft_warp_level.c2
10 files changed, 108 insertions, 32 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 457f121..bda46fe 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -118,7 +118,7 @@ enum
# define FT_CHRST_MAP_ENTRY "01234NSEWLT "
# define FT_CHRST_SPAWN "NSEW"
# define FT_CHRST_MAP_NON_WALL "02NESWLT"
-# define FT_CHRST_COLLISION "12 "
+# define FT_CHRST_COLLISION "123456789 "
# define FT_CHRST_DETECT "1L"
/*
@@ -146,6 +146,7 @@ enum
# define FT_ERR_COLOR_ALPHA "colors should be digits only"
# define FT_ERR_COLOR_MAX "colors should be maximum 255"
# define FT_ERR_COLOR_ARGS "colors should be three numbers with commas"
+# define FT_ERR_SPRITE_DUMB "bad sprite order"
# define FT_ERR_UNFINISHED "no map"
# define FT_ERR_MAP_LEN "map length inconsistency"
# define FT_ERR_ILL_ENTRY "illegal map entry"
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 8fba623..122ce16 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -165,7 +165,7 @@ typedef struct s_map
char *so_tex_path;
char *ea_tex_path;
char *we_tex_path;
- char *sprite_path;
+ char **sprite_path;
char *nl_tex_path;
char *fl_tex_path;
char *ce_tex_path;
@@ -219,7 +219,7 @@ typedef struct s_cub
pid_t mpid;
int (*key_ptr[6])(struct s_cub*);
int8_t (*get_ptr[14])(char**, struct s_cub*);
- char ref[15][3];
+ char ref[22][3];
struct s_win wlist;
struct s_player plist;
struct s_map mlist;
diff --git a/map/map_one.cub b/map/map_one.cub
index a158afa..353cd94 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -9,9 +9,15 @@ S ./media/img/pillar.xpm
C ./media/img/arrow1.xpm
F ./media/img/arrow2.xpm
+S2 ./media/img/spikes.xpm
+S3 ./media/img/linus.xpm
+S4 ./media/img/crapaud.xpm
+S5 ./media/img/larry.xpm
+S6 ./media/img/linuz.xpm
+
+
T ./media/img/spikes.xpm
SH 4
-
111111111111111111
100000002200000001
1000E0003300000001
diff --git a/src/ft_exit.c b/src/ft_exit.c
index e0093da..7056114 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -27,7 +27,7 @@ static void
ft_memdel((void**)&clist->mlist.so_tex_path);
ft_memdel((void**)&clist->mlist.ea_tex_path);
ft_memdel((void**)&clist->mlist.we_tex_path);
- ft_memdel((void**)&clist->mlist.sprite_path);
+ ft_free_words(clist->mlist.sprite_path);
ft_memdel((void**)&clist->mlist.nl_tex_path);
ft_memdel((void**)&clist->mlist.fl_tex_path);
ft_memdel((void**)&clist->mlist.ce_tex_path);
diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c
index a158940..902ab87 100644
--- a/src/ft_get_sprite.c
+++ b/src/ft_get_sprite.c
@@ -75,28 +75,71 @@ void
}
}
+static int8_t
+ ft_get_sprite_id(char *word)
+{
+ int8_t ret;
+ char ref[8][3];
+
+ ft_sprintf(ref[0], "S");
+ ft_sprintf(ref[1], "S2");
+ ft_sprintf(ref[2], "S3");
+ ft_sprintf(ref[3], "S4");
+ ft_sprintf(ref[4], "S5");
+ ft_sprintf(ref[5], "S6");
+ ft_sprintf(ref[6], "S7");
+ ft_sprintf(ref[7], "S8");
+ ret = 0;
+ while (ft_strncmp(word, ref[ret], 3) && ref[ret][0])
+ ret++;
+ return (ret);
+}
+
+static int8_t
+ ft_check_sprite_amount(int8_t id, t_cub *clist)
+{
+ int8_t i;
+
+ i = 0;
+ while (i < id)
+ {
+ if (!clist->mlist.sprite_path[i][0])
+ return (-1);
+ i++;
+ }
+ return (0);
+}
+
int8_t
ft_get_sprite(char **words, t_cub *clist)
{
+ int8_t id;
+
if (!(*words) || !words[1] || words[2])
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS);
+ ft_sprintf(clist->errmsg, FT_ERR_ARGS);
return (-1);
}
if (ft_check_ext(*(words + 1), ".xpm") < 0)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);
+ ft_sprintf(clist->errmsg, FT_ERR_NOT_A_XPM);
+ return (-1);
+ }
+ id = ft_get_sprite_id(words[0]);
+ if (ft_check_sprite_amount(id, clist) < 0)
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_SPRITE_DUMB);
return (-1);
}
- ft_memdel((void**)&clist->mlist.sprite_path);
- if (!(clist->mlist.sprite_path = ft_strdup(*(words + 1))))
+ ft_memdel((void**)&clist->mlist.sprite_path[id]);
+ if (!(clist->mlist.sprite_path[id] = ft_strdup(*(words + 1))))
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);
+ ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
return (-1);
}
- if (ft_check_not_found(clist->mlist.sprite_path) < 0)
+ if (ft_check_not_found(clist->mlist.sprite_path[id]) < 0)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_SP);
+ ft_sprintf(clist->errmsg, FT_ERR_RD_SP);
return (-1);
}
return (0);
diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c
index c299336..98fae3c 100644
--- a/src/ft_init_funptr.c
+++ b/src/ft_init_funptr.c
@@ -30,7 +30,14 @@ void
ft_sprintf(clist->ref[11], "SH");
ft_sprintf(clist->ref[12], "SB");
ft_sprintf(clist->ref[13], "T");
- ft_bzero(clist->ref[14], 3);
+ ft_sprintf(clist->ref[14], "S2");
+ ft_sprintf(clist->ref[15], "S3");
+ ft_sprintf(clist->ref[16], "S4");
+ ft_sprintf(clist->ref[17], "S5");
+ ft_sprintf(clist->ref[18], "S6");
+ ft_sprintf(clist->ref[19], "S7");
+ ft_sprintf(clist->ref[20], "S8");
+ ft_bzero(clist->ref[21], 3);
}
void
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index 867a5b0..1462ef3 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -23,7 +23,7 @@ static int8_t
!(mlist->so_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->ea_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->we_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
- !(mlist->sprite_path = (char*)ft_calloc(1, sizeof(char))) ||
+ !(mlist->sprite_path = (char**)ft_calloc(9, sizeof(char*))) ||
!(mlist->nl_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->fl_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->ce_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
@@ -41,6 +41,21 @@ static int8_t
return (0);
}
+static int8_t
+ ft_calloc_sprites(t_map *mlist)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < 9)
+ {
+ if (!(mlist->sprite_path[i] = (char*)ft_calloc(1, sizeof(char))))
+ return (-1);
+ i++;
+ }
+ return (0);
+}
+
int8_t
ft_init_map(t_map *mlist)
{
@@ -68,5 +83,6 @@ int8_t
mlist->scale = 0;
mlist->nlx = 0;
mlist->nly = 0;
+ ft_calloc_sprites(mlist);
return (0);
}
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index f748721..745b26d 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -31,7 +31,7 @@ static int8_t
return (-1);
else if (ret == 4 && (clist->mlist.we_tex_path[0]))
return (-1);
- else if (ret == 5 && (clist->mlist.sprite_path[0]))
+ else if (ret == 5 && (clist->mlist.sprite_path[0][0]))
return (-1);
else if (ret == 6 && ((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1)
|| (clist->f_rgb.b != -1)))
@@ -57,6 +57,8 @@ static int8_t
return (-1);
if (ret == 13 && (clist->mlist.traps_path[0]))
return (-1);
+ if (ret > 13 && ret < 21 && (clist->mlist.sprite_path[ret - 13][0]))
+ return (-1);
return (ret);
}
@@ -70,10 +72,12 @@ static int8_t
ret = 0;
while (ft_strncmp(words[0], clist->ref[ret], 3) && clist->ref[ret][0])
ret++;
- if (ret == 14)
+ if (ret == 21)
ret = FT_PARSE_END_RET;
ret = ft_check_exists(ret, clist);
ret = ft_check_exists_two(ret, clist);
+ if (ret > 13 && ret < 21)
+ ret = 5;
return (ret);
}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 0290a0c..cae07bd 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -38,18 +38,17 @@
static void
ft_next_sprite_init(t_cub *cl)
{
- uint16_t i;
+ uint8_t i;
- i = 8;
- cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- "./media/img/larry.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h);
- cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img,
- &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian);
- i++;
- cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- "./media/img/crapaud.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h);
- cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img,
- &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian);
+ i = 1;
+ while (cl->mlist.sprite_path[i][0])
+ {
+ cl->tlist[i + 7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ cl->mlist.sprite_path[i], &cl->tlist[i + 7].img_w, &cl->tlist[i + 7].img_h);
+ cl->tlist[i + 7].ptr = mlx_get_data_addr(cl->tlist[i + 7].img,
+ &cl->tlist[i + 7].bpp, &cl->tlist[i + 7].sizeline, &cl->tlist[i + 7].endian);
+ i++;
+ }
}
static void
@@ -71,9 +70,9 @@ static void
}
cl->walltexgood = 1;
if (cl->mlist.sprite_var > 1)
- {
- ft_next_sprite_init(cl);
- }
+ {
+ ft_next_sprite_init(cl);
+ }
}
static void
@@ -123,7 +122,7 @@ void
cl->tlist[3].ptr = mlx_get_data_addr(cl->tlist[3].img,
&cl->tlist[3].bpp, &cl->tlist[3].sizeline, &cl->tlist[3].endian);
cl->tlist[4].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- cl->mlist.sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h);
+ cl->mlist.sprite_path[0], &cl->tlist[4].img_w, &cl->tlist[4].img_h);
cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img,
&cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian);
ft_wall_tex_init_norme(cl);
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index faaf322..5b1a821 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -28,7 +28,7 @@ static void
ft_memdel((void**)&ml->so_tex_path);
ft_memdel((void**)&ml->ea_tex_path);
ft_memdel((void**)&ml->we_tex_path);
- ft_memdel((void**)&ml->sprite_path);
+ ft_free_words(ml->sprite_path);
ft_memdel((void**)&ml->nl_tex_path);
ft_memdel((void**)&ml->fl_tex_path);
ft_memdel((void**)&ml->ce_tex_path);