aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h3
-rw-r--r--inc/cub3d_structs.h8
-rw-r--r--src/ft_exit.c27
-rw-r--r--src/ft_init_sfx.c8
-rw-r--r--src/ft_key_loop.c4
-rw-r--r--src/ft_sfx_death.c4
-rw-r--r--src/ft_sfx_footstep.c46
-rw-r--r--src/ft_sfx_trap.c21
-rw-r--r--src/ft_suffer_animation.c2
10 files changed, 95 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index d888ae1..32fc614 100644
--- a/Makefile
+++ b/Makefile
@@ -93,6 +93,7 @@ SRCS_NAME += ft_del_extra_sprites.c
SRCS_NAME += ft_init_sfx.c
SRCS_NAME += ft_sfx_trap.c
SRCS_NAME += ft_sfx_death.c
+SRCS_NAME += ft_sfx_footstep.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 3cea604..8148561 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -148,8 +148,9 @@ void ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl);
** ====== ARGS ======
*/
-void ft_sfx_trap(t_cub *cl);
void ft_sfx_death(t_cub *cl);
+void ft_sfx_footstep(t_cub *cl);
+void ft_sfx_trap(t_cub *cl);
/*
** ====== OTHER ======
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 2f10f29..04ee59c 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -64,6 +64,11 @@ typedef struct s_sfx
char **pain_one;
char **pain_two;
char **trap;
+ pid_t death_pid;
+ pid_t footstep_pid;
+ pid_t new_lvl_pid;
+ pid_t pain_pid;
+ pid_t trap_pid;
} t_sfx;
typedef struct s_bmp_rgb
@@ -230,9 +235,6 @@ typedef struct s_cub
char errmsg[64];
int32_t key_input[5];
pid_t mpid;
- pid_t death_pid;
- pid_t pain_pid;
- pid_t trap_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 5bcc653..6a92dac 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -16,6 +16,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <signal.h>
+#include <sys/types.h>
#include <sys/wait.h>
#include <stdint.h>
@@ -39,6 +40,8 @@ static void
ft_free_words(clist->mlist.map);
ft_free_words(clist->mlist.mcmd_words);
ft_free_words(clist->sfx.death);
+ ft_free_words(clist->sfx.pain_one);
+ ft_free_words(clist->sfx.pain_two);
ft_free_words(clist->sfx.trap);
ft_free_sprites(clist->mlist.sprite_path);
if (!clist->wlist.inited)
@@ -76,15 +79,21 @@ static void
if (!(tmp = waitpid(clist->mpid, NULL, WNOHANG)))
kill(clist->mpid, SIGTERM);
wait(&clist->mpid);
- if (!(tmp = waitpid(clist->death_pid, NULL, WNOHANG)))
- kill(clist->death_pid, SIGTERM);
- wait(&clist->death_pid);
- if (!(tmp = waitpid(clist->trap_pid, NULL, WNOHANG)))
- kill(clist->trap_pid, SIGTERM);
- wait(&clist->trap_pid);
- if (!(tmp = waitpid(clist->pain_pid, NULL, WNOHANG)))
- kill(clist->pain_pid, SIGTERM);
- wait(&clist->pain_pid);
+ if (!(tmp = waitpid(clist->sfx.death_pid, NULL, WNOHANG)))
+ kill(clist->sfx.death_pid, SIGTERM);
+ wait(&clist->sfx.death_pid);
+ if (!(tmp = waitpid(clist->sfx.footstep_pid, NULL, WNOHANG)))
+ kill(clist->sfx.footstep_pid, SIGTERM);
+ wait(&clist->sfx.footstep_pid);
+ if (!(tmp = waitpid(clist->sfx.new_lvl_pid, NULL, WNOHANG)))
+ kill(clist->sfx.new_lvl_pid, SIGTERM);
+ wait(&clist->sfx.new_lvl_pid);
+ if (!(tmp = waitpid(clist->sfx.pain_pid, NULL, WNOHANG)))
+ kill(clist->sfx.pain_pid, SIGTERM);
+ wait(&clist->sfx.pain_pid);
+ if (!(tmp = waitpid(clist->sfx.trap_pid, NULL, WNOHANG)))
+ kill(clist->sfx.trap_pid, SIGTERM);
+ wait(&clist->sfx.trap_pid);
}
int
diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c
index 2aed165..84032d7 100644
--- a/src/ft_init_sfx.c
+++ b/src/ft_init_sfx.c
@@ -16,6 +16,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
+#include <unistd.h>
static int8_t
ft_split_sfx(char ***target, const char *path)
@@ -41,9 +42,12 @@ 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->footstep_one, FT_SFX_FS_ONE_PATH) < 0 ||
+ ft_split_sfx(&sfx->footstep_two, FT_SFX_FS_TWO_PATH) < 0 ||
+ ft_split_sfx(&sfx->new_lvl, FT_SFX_N_LVL_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)
+ ft_split_sfx(&sfx->pain_two, FT_SFX_SCR_TWO_PATH) < 0 ||
+ ft_split_sfx(&sfx->trap, FT_SFX_TRAP_PATH) < 0)
return (-1);
return (0);
}
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index a7af38e..647b887 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -83,6 +83,8 @@ int
{
cl->key_ptr[cl->key_input[i]](cl);
ft_collision(old_y, old_x, cl->key_input[i], cl);
+ if (cl->key_input[i] >= 0 && cl->key_input[i] <= 3)
+ ft_sfx_footstep(cl);
if (cl->mlist.isnlvl && !cl->plist.isdead)
{
if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&
@@ -94,7 +96,7 @@ int
}
i++;
}
- /* if (cl->key_input[0] != -1) */
+ if (cl->key_input[0] != -1)
ft_draw_scene(cl);
return (0);
}
diff --git a/src/ft_sfx_death.c b/src/ft_sfx_death.c
index e093cf3..2566358 100644
--- a/src/ft_sfx_death.c
+++ b/src/ft_sfx_death.c
@@ -16,8 +16,8 @@
void
ft_sfx_death(t_cub *cl)
{
- cl->death_pid = fork();
- if (cl->death_pid == 0)
+ cl->sfx.death_pid = fork();
+ if (cl->sfx.death_pid == 0)
{
execve(*(cl->sfx.death + 0), cl->sfx.death, cl->envp);
}
diff --git a/src/ft_sfx_footstep.c b/src/ft_sfx_footstep.c
new file mode 100644
index 0000000..d7a62d2
--- /dev/null
+++ b/src/ft_sfx_footstep.c
@@ -0,0 +1,46 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sfx_trap.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 <stddef.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <libft.h>
+void
+ ft_sfx_footstep(t_cub *cl)
+{
+ static uint8_t ref = 0;
+ pid_t tmp;
+ int status;
+
+ tmp = waitpid(cl->sfx.footstep_pid, &status, WNOHANG);
+ /* ft_printf("top_pid %d\nfs_pid %d\ntmp %d\n\n", getpid(), cl->sfx.footstep_pid, tmp); */
+ if (tmp > 0)
+ {
+ cl->sfx.footstep_pid = fork();
+ if (cl->sfx.footstep_pid == 0)
+ {
+ ref += 1;
+ if (ref > 201)
+ ref = 0;
+ if (ref % 2)
+ execve(*(cl->sfx.footstep_one + 0),
+ cl->sfx.footstep_one, cl->envp);
+ else
+ execve(*(cl->sfx.footstep_two + 0),
+ cl->sfx.footstep_two, cl->envp);
+ }
+ }
+}
diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c
index 32fc35a..cf5dafa 100644
--- a/src/ft_sfx_trap.c
+++ b/src/ft_sfx_trap.c
@@ -12,21 +12,22 @@
#include <cub3d.h>
#include <unistd.h>
+#include <stdint.h>
static void
ft_sfx_pain(t_cub *cl)
{
- static uint8_t ref_scr = 0;
+ static uint8_t ref = 0;
- ref_scr += 1;
- if (ref_scr > 201)
- ref_scr = 0;
- if (ref_scr % 2)
+ ref += 1;
+ if (ref > 201)
+ ref = 0;
+ if (ref % 2)
{
- cl->pain_pid = fork();
- if (cl->pain_pid == 0)
+ cl->sfx.pain_pid = fork();
+ if (cl->sfx.pain_pid == 0)
{
- if (ref_scr % 3)
+ if (ref % 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);
@@ -37,8 +38,8 @@ static void
void
ft_sfx_trap(t_cub *cl)
{
- cl->trap_pid = fork();
- if (cl->trap_pid == 0)
+ cl->sfx.trap_pid = fork();
+ if (cl->sfx.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 4a1bc2d..927c915 100644
--- a/src/ft_suffer_animation.c
+++ b/src/ft_suffer_animation.c
@@ -16,6 +16,7 @@
#include <stdint.h>
#include <unistd.h>
+#include <sys/wait.h>
void
ft_linux_suffer_animation(t_cub *cl)
{
@@ -48,7 +49,6 @@ void
/* TODO death screen here */
}
ft_sfx_trap(cl);
-
}
void