aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h6
-rw-r--r--inc/cub3d_structs.h2
-rw-r--r--src/ft_exit.c2
-rw-r--r--src/ft_init_sfx.c4
-rw-r--r--src/ft_sfx_trap.c44
-rw-r--r--src/ft_suffer_animation.c2
7 files changed, 60 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 922c6d2..e003d49 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,7 @@ SRCS_NAME += ft_draw_traps_extra.c
SRCS_NAME += ft_draw_life_bar.c
SRCS_NAME += ft_del_extra_sprites.c
SRCS_NAME += ft_init_sfx.c
+SRCS_NAME += ft_sfx_trap.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index b0f91fd..e9a6ddb 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -145,6 +145,12 @@ void ft_floor_cast(t_cub *cl);
void ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl);
/*
+** ====== ARGS ======
+*/
+
+void ft_sfx_trap(t_cub *cl);
+
+/*
** ====== OTHER ======
*/
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 543c5a3..fb0fe15 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -230,6 +230,8 @@ typedef struct s_cub
char errmsg[64];
int32_t key_input[5];
pid_t mpid;
+ pid_t trap_pid;
+ pid_t pain_pid;
int (*key_ptr[6])(struct s_cub*);
int8_t (*get_ptr[14])(char**, struct s_cub*);
char ref[22][3];
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 28a1489..b0d7ada 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -38,6 +38,8 @@ static void
ft_memdel((void**)&clist->mlist.mapl);
ft_free_words(clist->mlist.map);
ft_free_words(clist->mlist.mcmd_words);
+ ft_free_words(clist->sfx.death);
+ ft_free_words(clist->sfx.trap);
ft_free_sprites(clist->mlist.sprite_path);
if (!clist->wlist.inited)
ft_memdel((void**)&clist->wlist.winptr);
diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c
index 1452b5c..2aed165 100644
--- a/src/ft_init_sfx.c
+++ b/src/ft_init_sfx.c
@@ -41,7 +41,9 @@ int8_t
ft_init_sfx(t_sfx *sfx)
{
if (ft_split_sfx(&sfx->death, FT_SFX_DEATH_PATH) < 0 ||
- ft_split_sfx(&sfx->trap, FT_SFX_TRAP_PATH) < 0)
+ ft_split_sfx(&sfx->trap, FT_SFX_TRAP_PATH) < 0 ||
+ ft_split_sfx(&sfx->pain_one, FT_SFX_SCR_ONE_PATH) < 0 ||
+ ft_split_sfx(&sfx->pain_two, FT_SFX_SCR_TWO_PATH) < 0)
return (-1);
return (0);
}
diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c
new file mode 100644
index 0000000..bf9e0b2
--- /dev/null
+++ b/src/ft_sfx_trap.c
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_music.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/24 17:17:54 by rbousset #+# #+# */
+/* Updated: 2020/02/24 17:17:56 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <unistd.h>
+
+static void
+ ft_sfx_pain(t_cub *cl)
+{
+ static uint8_t ref_scr = 0;
+
+ ref_scr += 1;
+ if (ref_scr > 201)
+ ref_scr = 0;
+ if (ref_scr % 2)
+ {
+ cl->pain_pid = fork();
+ if (cl->pain_pid == 0)
+ {
+ if (ref_scr % 3)
+ execve(*(cl->sfx.pain_one + 0), cl->sfx.pain_one, cl->envp);
+ else
+ execve(*(cl->sfx.pain_two + 0), cl->sfx.pain_two, cl->envp);
+ }
+ }
+}
+
+void
+ ft_sfx_trap(t_cub *cl)
+{
+ cl->trap_pid = fork();
+ if (cl->trap_pid == 0)
+ execve(*(cl->sfx.trap + 0), cl->sfx.trap, cl->envp);
+ ft_sfx_pain(cl);
+}
diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c
index 28a0d12..67a557f 100644
--- a/src/ft_suffer_animation.c
+++ b/src/ft_suffer_animation.c
@@ -45,7 +45,9 @@ void
cl->plist.isdead = 1;
ft_warp_level(cl->mlist.filename, cl);
}
+ ft_sfx_trap(cl);
/* TODO death screen here */
+
}
void