diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | inc/cub3d_defines.h | 2 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 2 | ||||
-rw-r--r-- | media/sound/sfx/ooa.wav | bin | 0 -> 39568 bytes | |||
-rw-r--r-- | src/ft_check_missing_sfx.c | 3 | ||||
-rw-r--r-- | src/ft_del_sfx_cmd.c | 2 | ||||
-rw-r--r-- | src/ft_draw_ammo_bar.c | 4 | ||||
-rw-r--r-- | src/ft_exit.c | 2 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 3 | ||||
-rw-r--r-- | src/ft_init_sfx.c | 29 | ||||
-rw-r--r-- | src/ft_sfx_ooa.c | 41 |
12 files changed, 74 insertions, 17 deletions
@@ -99,6 +99,7 @@ SRCS_NAME += ft_sfx_heal.c SRCS_NAME += ft_sfx_weapon_one.c SRCS_NAME += ft_sfx_weapon_two.c SRCS_NAME += ft_sfx_weapon_three.c +SRCS_NAME += ft_sfx_ooa.c SRCS_NAME += ft_death_screen.c SRCS_NAME += ft_death_hooks.c SRCS_NAME += ft_init_sprites.c diff --git a/inc/cub3d.h b/inc/cub3d.h index 1531023..0d8fede 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -181,6 +181,7 @@ void ft_sfx_weapon_two_load(t_sfx *sfx); void ft_sfx_weapon_two_fire(t_sfx *sfx); void ft_sfx_weapon_three_load(t_sfx *sfx); void ft_sfx_weapon_three_fire(t_sfx *sfx); +void ft_sfx_ooa(t_sfx *sfx); void *ft_sfx_death_thread(void *vargp); void *ft_sfx_footstep_thread(void *vargp); void *ft_sfx_new_lvl_thread(void *vargp); @@ -193,6 +194,7 @@ void *ft_sfx_weapon_two_load_thread(void *vargp); void *ft_sfx_weapon_two_fire_thread(void *vargp); void *ft_sfx_weapon_three_load_thread(void *vargp); void *ft_sfx_weapon_three_fire_thread(void *vargp); +void *ft_sfx_ooa_thread(void *vargp); /* ** ====== DELETION ====== diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 244ed94..4ef2391 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -108,6 +108,7 @@ enum # define FT_SFX_W_TWO_FIRE_PATH "./media/sound/sfx/colt_fire.wav" # define FT_SFX_W_THREE_LOAD_PATH "./media/sound/sfx/double_b_load.wav" # define FT_SFX_W_THREE_FIRE_PATH "./media/sound/sfx/double_b_fire.wav" +# define FT_SFX_OOA_PATH "./media/sound/sfx/ooa.wav" # define FT_DEATH_SCREEN_PATH "./media/img/screens/death_screen.xpm" # define FT_HUD_BACK_PATH "./media/img/hud/hud_back.xpm" # define FT_WEAPON_ONE_SPR_PATH "./media/img/weapons/sword_s.xpm" @@ -265,6 +266,7 @@ enum # define FT_ERR_MISS_SFX_W_TWO_FIRE "weapon two fire sound effect" # define FT_ERR_MISS_SFX_W_THREE_LOAD "weapon three load sound effect" # define FT_ERR_MISS_SFX_W_THREE_FIRE "weapon three fire sound effect" +# define FT_ERR_MISS_SFX_OOA "out of ammunitions sound effect" # define FT_ERR_MISS_DEATH_SCREEN "death screen image" # define FT_ERR_MISS_HUD_BACK "HUD background image" # define FT_ERR_MISS_HEAL_PACK "heal pack image" diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 680f91a..809963c 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -269,7 +269,7 @@ typedef struct s_cub struct s_sprite traps[512]; struct s_sprite heals[64]; struct s_sprite **weaps; - struct s_sfx sfx[12]; + struct s_sfx sfx[13]; } t_cub; # endif diff --git a/media/sound/sfx/ooa.wav b/media/sound/sfx/ooa.wav Binary files differnew file mode 100644 index 0000000..a83c5f7 --- /dev/null +++ b/media/sound/sfx/ooa.wav diff --git a/src/ft_check_missing_sfx.c b/src/ft_check_missing_sfx.c index 1273457..34d08e2 100644 --- a/src/ft_check_missing_sfx.c +++ b/src/ft_check_missing_sfx.c @@ -34,6 +34,9 @@ static int if (ft_check_not_found(FT_SFX_W_THREE_FIRE_PATH) < 0 || ft_check_ext(FT_SFX_W_THREE_FIRE_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_W_THREE_FIRE, clist)); + if (ft_check_not_found(FT_SFX_OOA_PATH) < 0 || + ft_check_ext(FT_SFX_OOA_PATH, ".wav") < 0) + return (ft_missing_error(FT_ERR_MISS_SFX_OOA, clist)); return (0); } diff --git a/src/ft_del_sfx_cmd.c b/src/ft_del_sfx_cmd.c index 701bfa9..4fd38ee 100644 --- a/src/ft_del_sfx_cmd.c +++ b/src/ft_del_sfx_cmd.c @@ -20,7 +20,7 @@ void uint8_t i; i = 0; - while (i < 12) + while (i < 13) { ft_memdel((void*)&clist->sfx[i].cmd); i++; diff --git a/src/ft_draw_ammo_bar.c b/src/ft_draw_ammo_bar.c index 8a73f68..667eee9 100644 --- a/src/ft_draw_ammo_bar.c +++ b/src/ft_draw_ammo_bar.c @@ -121,8 +121,8 @@ void uint8_t w_id; w_id = cl->plist.handles_weapon; - w_id = (cl->plist.handles_weapon == 2) ? (1) : (w_id); - w_id = (cl->plist.handles_weapon == 4) ? (2) : (w_id); + w_id = (w_id == 2) ? (1) : (w_id); + w_id = (w_id == 4) ? (2) : (w_id); ft_get_hw(cl); if (cl->plist.ammo[w_id] >= 0) { diff --git a/src/ft_exit.c b/src/ft_exit.c index 4f955f4..ed1191c 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -40,7 +40,7 @@ static void pthread_join(clist->mtid, NULL); } i = -1; - while (++i < 12) + while (++i < 13) { pthread_mutex_unlock(&clist->sfx[i].mutex); pthread_cancel(clist->sfx[i].tid); diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index 097e2e2..0ccf3fc 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -82,6 +82,9 @@ int clist->plist.ammo[w_id] -= w_id; clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx); clist->plist.fire = 1; + return (0); } + else if (clist->plist.fire == 0 && clist->plist.ammo[w_id] <= 0) + clist->sfx[12].sfx_play(clist->sfx); return (0); } diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c index 202e647..9b58656 100644 --- a/src/ft_init_sfx.c +++ b/src/ft_init_sfx.c @@ -22,18 +22,19 @@ /* ** sfx[] index summary ** ------------------- -** 0: death -** 1: footstep | double -** 2: new level -** 3: pain | double -** 4: trap -** 5: heal -** 6: weapon one load -** 7: weapon one fire -** 8: weapon two load -** 9: weapon two fire +** 0: death +** 1: footstep | double +** 2: new level +** 3: pain | double +** 4: trap +** 5: heal +** 6: weapon one load +** 7: weapon one fire +** 8: weapon two load +** 9: weapon two fire ** 10: weapon three load ** 11: weapon three fire +** 12: out of ammunitions */ static int8_t @@ -70,6 +71,8 @@ static void ft_sfx_weapon_three_load_thread, &cl->sfx); pthread_create(&cl->sfx[11].tid, NULL, ft_sfx_weapon_three_fire_thread, &cl->sfx); + pthread_create(&cl->sfx[12].tid, NULL, + ft_sfx_ooa_thread, &cl->sfx); } static void @@ -87,6 +90,7 @@ static void cl->sfx[9].sfx_play = ft_sfx_weapon_two_fire; cl->sfx[10].sfx_play = ft_sfx_weapon_three_load; cl->sfx[11].sfx_play = ft_sfx_weapon_three_fire; + cl->sfx[12].sfx_play = ft_sfx_ooa; } int8_t @@ -106,10 +110,11 @@ int8_t ft_init_sfx_cmd(&cl->sfx[8].cmd, FT_SFX_W_TWO_LOAD_PATH) < 0 || ft_init_sfx_cmd(&cl->sfx[9].cmd, FT_SFX_W_TWO_FIRE_PATH) < 0 || ft_init_sfx_cmd(&cl->sfx[10].cmd, FT_SFX_W_THREE_LOAD_PATH) < 0 || - ft_init_sfx_cmd(&cl->sfx[11].cmd, FT_SFX_W_THREE_FIRE_PATH) < 0) + ft_init_sfx_cmd(&cl->sfx[11].cmd, FT_SFX_W_THREE_FIRE_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[12].cmd, FT_SFX_OOA_PATH) < 0) return (-1); i = -1; - while (++i < 12) + while (++i < 13) pthread_mutex_init(&cl->sfx[i].mutex, NULL); ft_init_sfx_pthreads(cl); ft_init_sfx_funptr(cl); diff --git a/src/ft_sfx_ooa.c b/src/ft_sfx_ooa.c new file mode 100644 index 0000000..880aea5 --- /dev/null +++ b/src/ft_sfx_ooa.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sfx_ooa.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 <stdlib.h> +#include <pthread.h> + +void + *ft_sfx_ooa_thread(void *vargp) +{ + t_sfx *sfx; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + sfx = (t_sfx *)vargp; + pthread_mutex_lock(&sfx[12].mutex); + while (1) + { + pthread_mutex_lock(&sfx[12].mutex); + if (system(sfx[12].cmd)) + pthread_exit(NULL); + } + return (NULL); +} + +void + ft_sfx_ooa(t_sfx *sfx) +{ + pthread_mutex_unlock(&sfx[12].mutex); +} |