diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-13 03:11:12 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-13 03:11:12 +0100 |
commit | a90c6f5cafbc47c7380d932d8db7bffd9b8b72bf (patch) | |
tree | 4e7044b92a3e97a338aaf769fe2b55d63e69338b | |
parent | Removed beta minilibx make options (diff) | |
download | 42-cub3d-a90c6f5cafbc47c7380d932d8db7bffd9b8b72bf.tar.gz 42-cub3d-a90c6f5cafbc47c7380d932d8db7bffd9b8b72bf.tar.bz2 42-cub3d-a90c6f5cafbc47c7380d932d8db7bffd9b8b72bf.tar.xz 42-cub3d-a90c6f5cafbc47c7380d932d8db7bffd9b8b72bf.tar.zst 42-cub3d-a90c6f5cafbc47c7380d932d8db7bffd9b8b72bf.zip |
sounds
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 1 | ||||
-rw-r--r-- | inc/cub3d_defines.h | 24 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | src/ft_check_missing.c | 21 | ||||
-rw-r--r-- | src/ft_get_music.c | 4 | ||||
-rw-r--r-- | src/ft_init_lists.c | 4 | ||||
-rw-r--r-- | src/ft_init_sfx.c | 47 |
8 files changed, 75 insertions, 28 deletions
@@ -90,6 +90,7 @@ SRCS_NAME += ft_draw_traps.c 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 = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index a2d050c..b0f91fd 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -34,6 +34,7 @@ int8_t ft_init_map(t_map *mlist); t_bmp_file ft_init_bmp(void); t_bmp_info ft_init_bmp_info(void); t_rgb ft_hex_to_og_rgb(uint32_t color); +int8_t ft_init_sfx(t_sfx *sfx); /* ** ====== HOOKS ====== diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index ab3a910..7257108 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -83,6 +83,11 @@ enum ** ====== SOUNDS ====== */ +# if FT_OS == 1 +# define FT_SND_CMD "/usr/bin/afplay --volume 0.2 %s" +# else +# define FT_SND_CMD "/usr/bin/aplay -f cd -t wav -q %s" +# endif # define FT_SFX_DEATH_PATH "./media/sound/sfx/death_screen.wav" # define FT_SFX_FS_ONE_PATH "./media/sound/sfx/footstep_one.wav" # define FT_SFX_FS_TWO_PATH "./media/sound/sfx/footstep_two.wav" @@ -90,25 +95,6 @@ enum # define FT_SFX_SCR_ONE_PATH "./media/sound/sfx/scream_one.wav" # define FT_SFX_SCR_TWO_PATH "./media/sound/sfx/scream_two.wav" # define FT_SFX_TRAP_PATH "./media/sound/sfx/trap.wav" -# if FT_OS == 1 -# define FT_MUS_CMD "/usr/bin/afplay --volume 0.2 %s" -# define FT_SFX_DEATH "/usr/bin/afplay --volume 0.2 ./media/sound/sfx/death_screen.wav" -# define FT_SFX_FS_ONE "/usr/bin/afplay --volume 0.2 ./media/sound/sfx/footstep_one.wav" -# define FT_SFX_FS_TWO "/usr/bin/afplay --volume 0.2 ./media/sound/sfx/footstep_two.wav" -# define FT_SFX_N_LVL "/usr/bin/afplay --volume 0.2 ./media/sound/sfx/next_lvl.wav" -# define FT_SFX_PAIN_ONE "/usr/bin/afplay --volume 0.2 ./media/sound/sfx/scream_one.wav" -# define FT_SFX_PAIN_TWO "/usr/bin/afplay --volume 0.2 ./media/sound/sfx/scream_two.wav" -# define FT_SFX_TRAP "/usr/bin/afplay --volume 0.2 ./media/sound/sfx/trap.wav" -# else -# define FT_MUS_CMD "/usr/bin/aplay -f cd -t wav -q %s" -# define FT_SFX_DEATH "/usr/bin/aplay -f cd -t wav -q ./media/sound/sfx/death_screen.wav" -# define FT_SFX_FS_ONE "/usr/bin/aplay -f cd -t wav -q ./media/sound/sfx/footstep_one.wav" -# define FT_SFX_FS_TWO "/usr/bin/aplay -f cd -t wav -q ./media/sound/sfx/footstep_two.wav" -# define FT_SFX_N_LVL "/usr/bin/aplay -f cd -t wav -q ./media/sound/sfx/next_lvl.wav" -# define FT_SFX_PAIN_ONE "/usr/bin/aplay -f cd -t wav -q ./media/sound/sfx/scream_one.wav" -# define FT_SFX_PAIN_TWO "/usr/bin/aplay -f cd -t wav -q ./media/sound/sfx/scream_two.wav" -# define FT_SFX_TRAP "/usr/bin/aplay -f cd -t wav -q ./media/sound/sfx/trap.wav" -# endif /* ** ====== MOVE SPEED ====== diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index d5b3bf7..b28c5ec 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -242,6 +242,7 @@ typedef struct s_cub struct s_img tlist[16]; struct s_sprite sprites[8][4096]; struct s_sprite traps[512]; + struct s_sfx sfx; } t_cub; # endif diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index 1e89781..f9df88f 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -26,19 +26,26 @@ int static int ft_check_missing_sfx(t_cub *clist) { - if (ft_check_not_found(FT_SFX_DEATH_PATH) < 0) + if (ft_check_not_found(FT_SFX_DEATH_PATH) < 0 || + ft_check_ext(FT_SFX_DEATH_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_DEATH, clist)); - if (ft_check_not_found(FT_SFX_FS_ONE_PATH) < 0) + if (ft_check_not_found(FT_SFX_FS_ONE_PATH) < 0 || + ft_check_ext(FT_SFX_FS_ONE_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_FS_ONE, clist)); - if (ft_check_not_found(FT_SFX_FS_TWO_PATH) < 0) + if (ft_check_not_found(FT_SFX_FS_TWO_PATH) < 0 || + ft_check_ext(FT_SFX_FS_TWO_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_FS_TWO, clist)); - if (ft_check_not_found(FT_SFX_N_LVL_PATH) < 0) + if (ft_check_not_found(FT_SFX_N_LVL_PATH) < 0 || + ft_check_ext(FT_SFX_N_LVL_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_N_LVL, clist)); - if (ft_check_not_found(FT_SFX_SCR_ONE_PATH) < 0) + if (ft_check_not_found(FT_SFX_SCR_ONE_PATH) < 0 || + ft_check_ext(FT_SFX_SCR_ONE_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_SCR_ONE, clist)); - if (ft_check_not_found(FT_SFX_SCR_TWO_PATH) < 0) + if (ft_check_not_found(FT_SFX_SCR_TWO_PATH) < 0 || + ft_check_ext(FT_SFX_SCR_TWO_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_SCR_TWO, clist)); - if (ft_check_not_found(FT_SFX_TRAP_PATH) < 0) + if (ft_check_not_found(FT_SFX_TRAP_PATH) < 0 || + ft_check_ext(FT_SFX_TRAP_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_TRAP, clist)); return (0); } diff --git a/src/ft_get_music.c b/src/ft_get_music.c index 2383e0a..7a8d36f 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -21,11 +21,11 @@ static int8_t uint8_t len; len = ft_strlen(mlist->music_path); - len += ft_strlen(FT_MUS_CMD) - 2; + len += ft_strlen(FT_SND_CMD) - 2; ft_memdel((void**)&mlist->music_cmd); if (!(mlist->music_cmd = (char *)malloc((len + 1) * sizeof(char)))) return (-1); - ft_sprintf(mlist->music_cmd, FT_MUS_CMD, + ft_sprintf(mlist->music_cmd, FT_SND_CMD, mlist->music_path); ft_free_words(mlist->mcmd_words); if (!(mlist->mcmd_words = ft_split(mlist->music_cmd, ' '))) diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index d480912..a6484c2 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -78,6 +78,10 @@ static int8_t cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); + if (ft_init_sfx(&cl->sfx) < 0) + return (-1); + ft_printf("%s\n", cl->sfx.death[0]); + ft_printf("%s\n", cl->sfx.trap[0]); cl->currlvl = 0; cl->walltexgood = 0; ft_init_funptr(cl); diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c new file mode 100644 index 0000000..1452b5c --- /dev/null +++ b/src/ft_init_sfx.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_init_lists.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 <libft.h> +#include <mlx.h> +#include <cub3d.h> +#include <stddef.h> +#include <stdlib.h> +#include <stdint.h> + +static int8_t + ft_split_sfx(char ***target, const char *path) +{ + uint8_t len; + char *tmp; + + len = ft_strlen(path); + len += ft_strlen(FT_SND_CMD) - 2; + if (!(tmp = (char *)malloc((len + 1) * sizeof(char)))) + return (-1); + ft_sprintf(tmp, FT_SND_CMD, path); + if (!(*target = ft_split(tmp, ' '))) + { + ft_memdel((void**)&tmp); + return (-1); + } + ft_memdel((void**)&tmp); + return (0); +} + +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) + return (-1); + return (0); +} |