aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h3
-rw-r--r--inc/cub3d_defines.h2
-rw-r--r--inc/cub3d_structs.h2
-rw-r--r--map/lvl_one.cub2
-rw-r--r--map/map_one.cub20
-rw-r--r--src/ft_draw_life_bar.c1
-rw-r--r--src/ft_draw_sprite.c42
-rw-r--r--src/ft_draw_sprite_extra.c50
-rw-r--r--src/ft_draw_traps.c8
-rw-r--r--src/ft_exit.c2
-rw-r--r--src/ft_free_words.c17
-rw-r--r--src/ft_get_skybox.c6
-rw-r--r--src/ft_get_sprite.c105
-rw-r--r--src/ft_get_sprite_spawns.c73
-rw-r--r--src/ft_init_funptr.c14
-rw-r--r--src/ft_init_map.c6
-rw-r--r--src/ft_key_loop.c2
-rw-r--r--src/ft_select_get.c4
-rw-r--r--src/ft_suffer_animation.c2
-rw-r--r--src/ft_warp_level.c42
21 files changed, 224 insertions, 180 deletions
diff --git a/Makefile b/Makefile
index a32a33b..4b27716 100644
--- a/Makefile
+++ b/Makefile
@@ -47,6 +47,7 @@ SRCS_NAME += ft_get_player_spawn.c
SRCS_NAME += ft_get_music.c
SRCS_NAME += ft_get_darkness.c
SRCS_NAME += ft_get_traps.c
+SRCS_NAME += ft_get_sprite_spawns.c
SRCS_NAME += ft_set_minimap_scale.c
SRCS_NAME += ft_check_missing.c
SRCS_NAME += ft_check_not_found.c
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 56736ac..c08a994 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -151,7 +151,8 @@ void ft_music_fork(char **mcmd_words, char *const envp[]);
int8_t ft_save_to_bmp(t_cub *cl);
int ft_error(uint8_t retval, const char *errmsg, t_cub *clist);
uint8_t ft_free_words(char **words);
-int8_t ft_warp_level(t_cub *cl);
+uint8_t ft_free_sprites(char **sprites);
+int8_t ft_warp_level(char *path, t_cub *cl);
int ft_exit(uint8_t exit_code, t_cub *clist);
uint32_t ft_rgb_to_hex(t_rgb rgb);
t_bmp_rgb ft_hex_to_rgb(uint32_t color);
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index bda46fe..b9a82c7 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -115,7 +115,7 @@ enum
*/
# define FT_CHRST_VALID_PARSE "RNSEWFCLMT"
-# define FT_CHRST_MAP_ENTRY "01234NSEWLT "
+# define FT_CHRST_MAP_ENTRY "0123456789NSEWLT "
# define FT_CHRST_SPAWN "NSEW"
# define FT_CHRST_MAP_NON_WALL "02NESWLT"
# define FT_CHRST_COLLISION "123456789 "
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 122ce16..d0e0845 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -165,7 +165,6 @@ typedef struct s_map
char *so_tex_path;
char *ea_tex_path;
char *we_tex_path;
- char **sprite_path;
char *nl_tex_path;
char *fl_tex_path;
char *ce_tex_path;
@@ -175,6 +174,7 @@ typedef struct s_map
char *music_path;
char *music_cmd;
char *mapl;
+ char **sprite_path;
char **map;
char **mcmd_words;
int8_t x_step;
diff --git a/map/lvl_one.cub b/map/lvl_one.cub
index 5a73e65..2996918 100644
--- a/map/lvl_one.cub
+++ b/map/lvl_one.cub
@@ -10,7 +10,7 @@ C ./media/img/BRIQUASSE_3.xpm
F ./media/img/BRIQUASSE_3.xpm
T media/img/spikes.xpm
-SH 4
+SH 1
L ./map/lvl_two.cub
LT ./media/img/crapaud.xpm
diff --git a/map/map_one.cub b/map/map_one.cub
index 353cd94..e9cebca 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -9,19 +9,21 @@ 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
+S3 ./media/img/spikes.xpm
+S4 ./media/img/linus.xpm
+S5 ./media/img/crapaud.xpm
+S6 ./media/img/larry.xpm
+S7 ./media/img/linuz.xpm
+S8 ./media/img/linuz.xpm
T ./media/img/spikes.xpm
+
SH 4
111111111111111111
-100000002200000001
-1000E0003300000001
-100100004400000001
+100000600002000001
+1000E0T00300000001
+100100704000000001
101100000111000001
111111111111110011
1000001 100001
@@ -31,6 +33,6 @@ SH 4
110000001101010111
100020T00000000011
100000T00000000011
-110000T01101010111
+110000T01101050111
111101111111010111
11111 1 1111
diff --git a/src/ft_draw_life_bar.c b/src/ft_draw_life_bar.c
index 501fd71..17c6dc4 100644
--- a/src/ft_draw_life_bar.c
+++ b/src/ft_draw_life_bar.c
@@ -13,7 +13,6 @@
#include <cub3d.h>
#include <stdint.h>
-
static void
ft_draw_green_life(uint16_t h, t_win *wl, t_cub *cl)
{
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c
index effaf78..73f277a 100644
--- a/src/ft_draw_sprite.c
+++ b/src/ft_draw_sprite.c
@@ -43,20 +43,20 @@ void
it = 0;
jt = 0;
- while (jt < cl->mlist.sprite_var)
- {
- while (it < cl->mlist.sprite_nbr)
- {
- dist_tab[it] = ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) *
- (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) +
- (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) *
- (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y));
- cl->mlist.sprite_order[it] = it;
- it++;
- }
- it = 0;
- jt++;
- }
+ while (jt < cl->mlist.sprite_var)
+ {
+ while (it < cl->mlist.sprite_nbr)
+ {
+ dist_tab[it] = ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) *
+ (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) +
+ (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) *
+ (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y));
+ cl->mlist.sprite_order[it] = it;
+ it++;
+ }
+ it = 0;
+ jt++;
+ }
it = 0;
while (it < cl->mlist.sprite_nbr)
{
@@ -77,13 +77,13 @@ static void
calc = (calc < 1) ? (1) : (calc);
cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] =
(uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc;
+ cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc;
cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] =
(uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc;
+ cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc;
cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] =
(uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc;
+ cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc;
cl->img.ptr[sprite->x * 4 + cl->wlist.x_size * sprite->y + 3] = (char)0;
}
@@ -96,7 +96,8 @@ void
while (sprite->x < sprite->drawendx)
{
sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 +
- sprite->spritescreenx)) * cl->tlist[sprite->current_sprite].img_w / sprite->spritewidth);
+ sprite->spritescreenx))
+ * cl->tlist[sprite->current_sprite].img_w / sprite->spritewidth);
sprite->y = sprite->drawstarty;
while (sprite->y < sprite->drawendy)
{
@@ -104,12 +105,11 @@ void
sprite->spriteheight * 128;
sprite->tex_y = ((d * cl->tlist[sprite->current_sprite].img_h / 2) /
sprite->spriteheight) / 128;
- if (sprite->transformy > 0 && cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
+ if (sprite->transformy > 0 &&
+ cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]
&& cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy)
- {
ft_put_sprite(sprite, cl);
- }
sprite->y++;
}
sprite->x++;
diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c
index f6a148c..351ed32 100644
--- a/src/ft_draw_sprite_extra.c
+++ b/src/ft_draw_sprite_extra.c
@@ -42,16 +42,16 @@ void
}
static void
- ft_init_sprite(t_cub *cl, t_sprite *sprite)
+ ft_init_sprite(t_cub *cl, t_sprite *sprite)
{
- sprite->invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y
- - cl->plist.dir_x * cl->plist.plane_y);
- sprite->transformx = sprite->invdet * (cl->plist.dir_y * sprite->spritex
- - cl->plist.dir_x * sprite->spritey);
- sprite->transformy = sprite->invdet * (-cl->plist.plane_y * sprite->spritex
- + cl->plist.plane_x * sprite->spritey);
- sprite->spritescreenx = (int)(cl->wlist.x_size / 2) *
- (1 + sprite->transformx / sprite->transformy);
+ sprite->invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y
+ - cl->plist.dir_x * cl->plist.plane_y);
+ sprite->transformx = sprite->invdet * (cl->plist.dir_y * sprite->spritex
+ - cl->plist.dir_x * sprite->spritey);
+ sprite->transformy = sprite->invdet * (-cl->plist.plane_y * sprite->spritex
+ + cl->plist.plane_x * sprite->spritey);
+ sprite->spritescreenx = (int)(cl->wlist.x_size / 2) *
+ (1 + sprite->transformx / sprite->transformy);
}
void
@@ -64,20 +64,20 @@ void
i = 0;
j = 0;
while (j < cl->mlist.sprite_var - 1)
- {
- while (i < cl->mlist.sprite_nbr)
- {
- sprite = cl->sprites[j][i];
- sprite.current_sprite = (j == 0) ? 4 : j + 7;
- sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5);
- sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5);
- ft_init_sprite(cl, &sprite);
- ft_sprite_height(cl, &sprite);
- ft_sprite_width(cl, &sprite);
- ft_draw_sprite(cl, &sprite);
- i++;
- }
- i = 0;
- j++;
- }
+ {
+ while (i < cl->mlist.sprite_nbr)
+ {
+ sprite = cl->sprites[j][i];
+ sprite.current_sprite = (j == 0) ? 4 : j + 7;
+ sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5);
+ sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5);
+ ft_init_sprite(cl, &sprite);
+ ft_sprite_height(cl, &sprite);
+ ft_sprite_width(cl, &sprite);
+ ft_draw_sprite(cl, &sprite);
+ i++;
+ }
+ i = 0;
+ j++;
+ }
}
diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c
index 42f837b..abde37e 100644
--- a/src/ft_draw_traps.c
+++ b/src/ft_draw_traps.c
@@ -89,7 +89,8 @@ void
while (sprite->x < sprite->drawendx)
{
sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 +
- sprite->spritescreenx)) * cl->tlist[15].img_w / sprite->spritewidth);
+ sprite->spritescreenx))
+ * cl->tlist[15].img_w / sprite->spritewidth);
sprite->y = sprite->drawstarty;
while (sprite->y < sprite->drawendy)
{
@@ -97,12 +98,11 @@ void
sprite->spriteheight * 128;
sprite->tex_y = ((d * cl->tlist[15].img_h / 2) /
sprite->spriteheight) / 128;
- if (sprite->transformy > 0 && cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
+ if (sprite->transformy > 0
+ && cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
cl->tlist[15].img_h * sprite->tex_y]
&& cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy)
- {
ft_put_trap(sprite, cl);
- }
sprite->y++;
}
sprite->x++;
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 7056114..4ed318c 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -27,7 +27,6 @@ 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_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);
@@ -39,6 +38,7 @@ static void
ft_memdel((void**)&clist->mlist.mapl);
ft_free_words(clist->mlist.map);
ft_free_words(clist->mlist.mcmd_words);
+ ft_free_sprites(clist->mlist.sprite_path);
if (!clist->wlist.inited)
ft_memdel((void**)&clist->wlist.winptr);
}
diff --git a/src/ft_free_words.c b/src/ft_free_words.c
index 598a7ac..648706c 100644
--- a/src/ft_free_words.c
+++ b/src/ft_free_words.c
@@ -13,12 +13,27 @@
#include <libft.h>
uint8_t
+ ft_free_sprites(char **sprites)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < 9)
+ {
+ ft_memdel((void**)&sprites[i]);
+ i++;
+ }
+ ft_memdel((void**)&sprites);
+ return (0);
+}
+
+uint8_t
ft_free_words(char **words)
{
size_t i;
i = 0;
- while (words[i])
+ while (words[i] && words[i][0])
{
ft_memdel((void**)&words[i]);
i++;
diff --git a/src/ft_get_skybox.c b/src/ft_get_skybox.c
index 47c395e..d2f1f02 100644
--- a/src/ft_get_skybox.c
+++ b/src/ft_get_skybox.c
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_get_skybox.c :+: :+: :+: */
+/* ft_get_skybox.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/14 17:28:53 by rbousset #+# #+# */
-/* Updated: 2020/02/14 17:28:53 by rbousset ### ########lyon.fr */
+/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */
+/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c
index 902ab87..ed44d9b 100644
--- a/src/ft_get_sprite.c
+++ b/src/ft_get_sprite.c
@@ -15,66 +15,6 @@
#include <stdint.h>
#include <stdio.h>
-void
- ft_get_next_sprite(t_cub *clist, int s_n, char c)
-{
- size_t x;
- size_t y;
- uint8_t i;
-
- x = 0;
- y = 0;
- i = 0;
- while (clist->mlist.map[++y])
- {
- while (clist->mlist.map[y][++x])
- {
- if (clist->mlist.map[y][x] == c)
- {
- clist->mlist.sprite_nbr++;
- clist->sprites[s_n][i].s_pos_x = x;
- clist->sprites[s_n][i].s_pos_y = y;
- i++;
- }
- }
- x = 0;
- }
- if (clist->sprites[s_n][i - 1].s_pos_x != 0)
- {
- ft_get_next_sprite(clist, s_n + 1, c + 1);
- clist->mlist.sprite_var++;
- }
-}
-
-void
- ft_get_sprite_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 (ft_ischarset("2", clist->mlist.map[y][x]))
- {
- clist->mlist.sprite_nbr++;
- clist->sprites[0][i].s_pos_x = x;
- clist->sprites[0][i].s_pos_y = y;
- i++;
- ft_get_next_sprite(clist, 1, '3');
- }
- x++;
- }
- x = 1;
- y++;
- }
-}
-
static int8_t
ft_get_sprite_id(char *word)
{
@@ -82,13 +22,13 @@ static int8_t
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");
+ ft_sprintf(ref[1], "S3");
+ ft_sprintf(ref[2], "S4");
+ ft_sprintf(ref[3], "S5");
+ ft_sprintf(ref[4], "S6");
+ ft_sprintf(ref[5], "S7");
+ ft_sprintf(ref[6], "S8");
+ ft_sprintf(ref[7], "S9");
ret = 0;
while (ft_strncmp(word, ref[ret], 3) && ref[ret][0])
ret++;
@@ -110,6 +50,24 @@ static int8_t
return (0);
}
+static int8_t
+ ft_get_sprite_norme(int8_t id, char **words, t_cub *clist)
+{
+ ft_memdel((void**)&clist->mlist.sprite_path[id]);
+ if (!(clist->mlist.sprite_path[id] = ft_strdup(*(words + 1))))
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
+ return (-1);
+ }
+ if (ft_check_not_found(clist->mlist.sprite_path[id]) < 0)
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_RD_SP);
+ return (-1);
+ }
+ clist->mlist.sprite_var++;
+ return (0);
+}
+
int8_t
ft_get_sprite(char **words, t_cub *clist)
{
@@ -131,16 +89,5 @@ int8_t
ft_sprintf(clist->errmsg, FT_ERR_SPRITE_DUMB);
return (-1);
}
- ft_memdel((void**)&clist->mlist.sprite_path[id]);
- if (!(clist->mlist.sprite_path[id] = ft_strdup(*(words + 1))))
- {
- ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
- return (-1);
- }
- if (ft_check_not_found(clist->mlist.sprite_path[id]) < 0)
- {
- ft_sprintf(clist->errmsg, FT_ERR_RD_SP);
- return (-1);
- }
- return (0);
+ return (ft_get_sprite_norme(id, words, clist));
}
diff --git a/src/ft_get_sprite_spawns.c b/src/ft_get_sprite_spawns.c
new file mode 100644
index 0000000..3a44f56
--- /dev/null
+++ b/src/ft_get_sprite_spawns.c
@@ -0,0 +1,73 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_get_sprite_spawns.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:51 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:51 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+#include <stdio.h>
+
+void
+ ft_get_next_sprite(t_cub *clist, int s_n, char c, size_t x)
+{
+ size_t y;
+ uint8_t i;
+
+ y = 0;
+ i = 0;
+ while (clist->mlist.map[++y])
+ {
+ while (clist->mlist.map[y][++x])
+ {
+ if (clist->mlist.map[y][x] == c)
+ {
+ clist->mlist.sprite_nbr++;
+ clist->sprites[s_n][i].s_pos_x = x;
+ clist->sprites[s_n][i].s_pos_y = y;
+ i++;
+ }
+ }
+ x = 0;
+ }
+ if (clist->sprites[s_n][i - 1].s_pos_x != 0)
+ {
+ ft_get_next_sprite(clist, s_n + 1, c + 1, 0);
+ }
+}
+
+void
+ ft_get_sprite_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 (ft_ischarset("2", clist->mlist.map[y][x]))
+ {
+ clist->mlist.sprite_nbr++;
+ clist->sprites[0][i].s_pos_x = x;
+ clist->sprites[0][i].s_pos_y = y;
+ i++;
+ ft_get_next_sprite(clist, 1, '3', 0);
+ }
+ x++;
+ }
+ x = 1;
+ y++;
+ }
+}
diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c
index 98fae3c..d944778 100644
--- a/src/ft_init_funptr.c
+++ b/src/ft_init_funptr.c
@@ -30,13 +30,13 @@ void
ft_sprintf(clist->ref[11], "SH");
ft_sprintf(clist->ref[12], "SB");
ft_sprintf(clist->ref[13], "T");
- 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_sprintf(clist->ref[14], "S3");
+ ft_sprintf(clist->ref[15], "S4");
+ ft_sprintf(clist->ref[16], "S5");
+ ft_sprintf(clist->ref[17], "S6");
+ ft_sprintf(clist->ref[18], "S7");
+ ft_sprintf(clist->ref[19], "S8");
+ ft_sprintf(clist->ref[20], "S9");
ft_bzero(clist->ref[21], 3);
}
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index 1462ef3..8f6bb3d 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -83,6 +83,8 @@ int8_t
mlist->scale = 0;
mlist->nlx = 0;
mlist->nly = 0;
- ft_calloc_sprites(mlist);
- return (0);
+ mlist->sprite_var = 0;
+ ft_bzero(mlist->sprite_order, 4096);
+ ft_bzero(mlist->traps_order, 512);
+ return (ft_calloc_sprites(mlist));
}
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index 45ed379..66f72ef 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -87,7 +87,7 @@ int
if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&
(uint32_t)cl->plist.pos_y == cl->mlist.nly)
{
- return ((ft_warp_level(cl) < 0) ?
+ return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ?
(ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0));
}
}
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index 745b26d..143dc09 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -57,8 +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);
+ if (ret > 13 && ret < 21 && (clist->mlist.sprite_path[ret - 13][0]))
+ return (-1);
return (ret);
}
diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c
index b800a39..bc8eb12 100644
--- a/src/ft_suffer_animation.c
+++ b/src/ft_suffer_animation.c
@@ -40,7 +40,7 @@ void
}
cl->plist.life -= 20;
if (cl->plist.life <= 0)
- ft_exit(0, cl);
+ ft_warp_level(cl->mlist.filename, cl);
/* TODO death screen here */
cl->doicast = 0;
}
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index 5b1a821..7a04dc9 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -28,7 +28,6 @@ static void
ft_memdel((void**)&ml->so_tex_path);
ft_memdel((void**)&ml->ea_tex_path);
ft_memdel((void**)&ml->we_tex_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);
@@ -38,6 +37,7 @@ static void
ft_memdel((void**)&ml->music_path);
ft_memdel((void**)&ml->music_cmd);
ft_memdel((void**)&ml->mapl);
+ ft_free_sprites(ml->sprite_path);
ft_free_words(ml->map);
ft_free_words(ml->mcmd_words);
}
@@ -52,11 +52,16 @@ static void
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
i = -1;
- while (++i <= 5)
+ while (++i < 5)
{
mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img);
cl->tlist[i].img = NULL;
}
+ if (cl->mlist.isnlvl && cl->tlist[5].img)
+ {
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[5].img);
+ cl->tlist[5].img = NULL;
+ }
if (cl->mlist.isftex && cl->tlist[6].img)
mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img);
if (cl->mlist.isctex && cl->tlist[7].img)
@@ -87,27 +92,26 @@ static void
}
int8_t
- ft_warp_level(t_cub *cl)
+ ft_warp_level(char *path, t_cub *cl)
{
char *next_path;
char *tmp_mup;
uint8_t isoldmus;
- if (!(next_path = (char *)malloc((ft_strlen(
- cl->mlist.nlevel_path) + 1) * sizeof(char))))
- return (-1);
- ft_sprintf(next_path, "%s", cl->mlist.nlevel_path);
- if ((isoldmus = cl->mlist.ismusic))
- tmp_mup = ft_strdup(cl->mlist.music_path);
- ft_del_some(cl);
- ft_del_map(&cl->mlist);
- if (ft_init_map(&cl->mlist) < 0)
- return (-1);
- ft_parse_map(next_path, cl);
- ft_treat_music(isoldmus, tmp_mup, cl);
- if (isoldmus)
- ft_memdel((void**)&tmp_mup);
- ft_wall_tex_init(cl);
- ft_memdel((void**)&next_path);
+ if (!(next_path = (char *)malloc((ft_strlen(path) + 1) * sizeof(char))))
+ return (-1);
+ ft_sprintf(next_path, "%s", path);
+ if ((isoldmus = cl->mlist.ismusic))
+ tmp_mup = ft_strdup(cl->mlist.music_path);
+ ft_del_some(cl);
+ ft_del_map(&cl->mlist);
+ if (ft_init_map(&cl->mlist) < 0)
+ return (-1);
+ ft_parse_map(next_path, cl);
+ ft_treat_music(isoldmus, tmp_mup, cl);
+ if (isoldmus)
+ ft_memdel((void**)&tmp_mup);
+ ft_wall_tex_init(cl);
+ ft_memdel((void**)&next_path);
return (0);
}