aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_exit.c1
-rw-r--r--src/ft_get_music.c38
-rw-r--r--src/ft_get_path_nl.c8
-rw-r--r--src/ft_init_funptr.c34
-rw-r--r--src/ft_init_lists.c7
-rw-r--r--src/ft_init_map.c2
-rw-r--r--src/ft_select_get.c22
-rw-r--r--src/ft_warp_level.c22
8 files changed, 97 insertions, 37 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 837c6aa..423350d 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -27,6 +27,7 @@ static void
ft_memdel((void**)&clist->mlist->sprite_path);
ft_memdel((void**)&clist->mlist->nl_tex_path);
ft_memdel((void**)&clist->mlist->nlevel_path);
+ ft_memdel((void**)&clist->mlist->music_path);
ft_memdel((void**)&clist->mlist->mapl);
ft_free_words(clist->mlist->map);
ft_memdel((void**)&clist->mlist);
diff --git a/src/ft_get_music.c b/src/ft_get_music.c
new file mode 100644
index 0000000..c9119c9
--- /dev/null
+++ b/src/ft_get_music.c
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_get_music.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/28 18:30:18 by rbousset #+# #+# */
+/* Updated: 2020/02/28 18:30:19 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+int8_t
+ ft_get_music(char **words, t_cub *clist)
+{
+ if (!(*words) || !(*(words + 1)) || (*(words + 2)))
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_ARGS);
+ return (-1);
+ }
+ if (ft_check_ext(*(words + 1), ".wav") < 0)
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_NOT_A_WAV);
+ return (-1);
+ }
+ ft_memdel((void**)&clist->mlist->music_path);
+ if (!(clist->mlist->music_path = ft_strdup(*(words + 1))))
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);
+ return (-1);
+ }
+ if (ft_check_not_found(clist->mlist->nlevel_path) < 0)
+ {
+ ft_sprintf(clist->errmsg, FT_ERR_RD_MUSIC);
+ return (-1);
+ }
+ return (0);
+}
diff --git a/src/ft_get_path_nl.c b/src/ft_get_path_nl.c
index f826070..b14595f 100644
--- a/src/ft_get_path_nl.c
+++ b/src/ft_get_path_nl.c
@@ -19,23 +19,23 @@ int8_t
{
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), ".cub") < 0)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_CUB);
+ ft_sprintf(clist->errmsg, FT_ERR_NOT_A_CUB);
return (-1);
}
ft_memdel((void**)&clist->mlist->nlevel_path);
if (!(clist->mlist->nlevel_path = 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->nlevel_path) < 0)
{
- ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_NL_MAP);
+ ft_sprintf(clist->errmsg, FT_ERR_RD_NL_MAP);
return (-1);
}
return (0);
diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c
new file mode 100644
index 0000000..7721381
--- /dev/null
+++ b/src/ft_init_funptr.c
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_init_funptr.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 */
+/* */
+/* ************************************************************************** */
+
+#include <cub3.d>
+void
+ ft_init_funptr(t_cub *clist)
+{
+ clist->key_ptr[0] = ft_w_key;
+ clist->key_ptr[1] = ft_a_key;
+ clist->key_ptr[2] = ft_s_key;
+ clist->key_ptr[3] = ft_d_key;
+ clist->key_ptr[4] = ft_left_key;
+ clist->key_ptr[5] = ft_right_key;
+ fun_ptr[0] = ft_get_res;
+ fun_ptr[1] = ft_get_tex_no;
+ fun_ptr[2] = ft_get_tex_so;
+ fun_ptr[3] = ft_get_tex_ea;
+ fun_ptr[4] = ft_get_tex_we;
+ fun_ptr[5] = ft_get_sprite;
+ fun_ptr[6] = ft_get_f_color;
+ fun_ptr[7] = ft_get_c_color;
+ fun_ptr[8] = ft_get_path_nl;
+ fun_ptr[9] = ft_get_tex_nl;
+ fun_ptr[10] = ft_get_music;
+}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 65c28d8..fd8c75d 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -86,12 +86,7 @@ static t_cub
clist->rlist = ft_init_s_ray();
clist->currlvl = 0;
clist->walltexgood = 0;
- clist->key_ptr[0] = ft_w_key;
- clist->key_ptr[1] = ft_a_key;
- clist->key_ptr[2] = ft_s_key;
- clist->key_ptr[3] = ft_d_key;
- clist->key_ptr[4] = ft_left_key;
- clist->key_ptr[5] = ft_right_key;
+ ft_init_funptr(clist);
return (clist);
}
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index eac9366..13448c6 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -25,6 +25,7 @@ static int8_t
!(mlist->sprite_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->nl_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->nlevel_path = (char*)ft_calloc(1, sizeof(char))) ||
+ !(mlist->music_path = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) ||
!(mlist->map = (char**)ft_calloc(2, sizeof(char*))) ||
!(mlist->map[0] = (char*)ft_calloc(1, sizeof(char))))
@@ -50,6 +51,7 @@ t_map
mlist->map_start = 0;
mlist->isspawn = 0;
mlist->isnlvl = 0;
+ mlist->ismusic = 0;
mlist->scale = 0;
mlist->nlx = 0;
mlist->nly = 0;
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index c6251c2..9d97748 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -51,6 +51,8 @@ static int8_t
return (-1);
if (ret == 9 && (clist->mlist->nl_tex_path[0]))
return (-1);
+ if (ret == 10 && (clist->mlist->music_path[0]))
+ return (-1);
return (ret);
}
@@ -58,7 +60,7 @@ static int8_t
ft_get_id(char **words, t_cub *clist)
{
int8_t ret;
- char ref[11][3];
+ char ref[12][3];
ft_memcpy(ref[0], "R\0", 3);
ft_memcpy(ref[1], "NO", 3);
@@ -69,12 +71,13 @@ static int8_t
ft_memcpy(ref[6], "F\0", 3);
ft_memcpy(ref[7], "C\0", 3);
ft_memcpy(ref[8], "L\0", 3);
- ft_memcpy(ref[9], "LT\0", 3);
- ft_memcpy(ref[10], "", 1);
+ ft_memcpy(ref[9], "LT", 3);
+ ft_memcpy(ref[9], "MU", 3);
+ ft_memcpy(ref[11], "", 1);
ret = 0;
while (ft_strncmp(words[0], ref[ret], 3) && ref[ret][0])
ret++;
- if (ret == 10)
+ if (ret == 11)
ret = 12;
ret = ft_check_exists(ret, clist);
ret = ft_check_exists_two(ret, clist);
@@ -84,19 +87,8 @@ static int8_t
int8_t
ft_select_get(char **words, t_cub *clist)
{
- int8_t (*fun_ptr[10])(char**, t_cub*);
int8_t id;
- fun_ptr[0] = ft_get_res;
- fun_ptr[1] = ft_get_tex_no;
- fun_ptr[2] = ft_get_tex_so;
- fun_ptr[3] = ft_get_tex_ea;
- fun_ptr[4] = ft_get_tex_we;
- fun_ptr[5] = ft_get_sprite;
- fun_ptr[6] = ft_get_f_color;
- fun_ptr[7] = ft_get_c_color;
- fun_ptr[8] = ft_get_path_nl;
- fun_ptr[9] = ft_get_tex_nl;
if ((id = ft_get_id(words, clist)) == 12)
{
ft_free_words(words);
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index cfacd81..9a61484 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -27,6 +27,7 @@ static void
ft_memdel((void**)&ml->sprite_path);
ft_memdel((void**)&ml->nl_tex_path);
ft_memdel((void**)&ml->nlevel_path);
+ ft_memdel((void**)&ml->music_path);
ft_memdel((void**)&ml->mapl);
ft_free_words(ml->map);
ft_memdel((void**)&ml);
@@ -35,6 +36,8 @@ static void
static void
ft_del_some(t_cub *cl)
{
+ uint8_t i;
+
cl->plist->pos_x = 0;
cl->plist->pos_y = 0;
cl->plist->start_x = 0;
@@ -47,18 +50,13 @@ static void
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
- mlx_destroy_image(cl->wlist->wlx, cl->tlist[0].img);
- mlx_destroy_image(cl->wlist->wlx, cl->tlist[1].img);
- mlx_destroy_image(cl->wlist->wlx, cl->tlist[2].img);
- mlx_destroy_image(cl->wlist->wlx, cl->tlist[3].img);
- mlx_destroy_image(cl->wlist->wlx, cl->tlist[4].img);
- mlx_destroy_image(cl->wlist->wlx, cl->tlist[5].img);
- cl->tlist[0].img = NULL;
- cl->tlist[1].img = NULL;
- cl->tlist[2].img = NULL;
- cl->tlist[3].img = NULL;
- cl->tlist[4].img = NULL;
- cl->tlist[5].img = NULL;
+ i = 0;
+ while (i < 5)
+ {
+ mlx_destroy_image(cl->wlist->wlx, cl->tlist[i].img);
+ cl->tlist[i].img = NULL;
+ i++;
+ }
}
int8_t