diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-13 02:35:49 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-13 02:35:49 +0100 |
commit | 8d68891b9e6089cd29095c94d0a30f2a3ec0a2c7 (patch) | |
tree | 026b97aaa56ac87328d1fa7332872e86b1b15d32 | |
parent | Added sound effects files (diff) | |
download | 42-cub3d-8d68891b9e6089cd29095c94d0a30f2a3ec0a2c7.tar.gz 42-cub3d-8d68891b9e6089cd29095c94d0a30f2a3ec0a2c7.tar.bz2 42-cub3d-8d68891b9e6089cd29095c94d0a30f2a3ec0a2c7.tar.xz 42-cub3d-8d68891b9e6089cd29095c94d0a30f2a3ec0a2c7.tar.zst 42-cub3d-8d68891b9e6089cd29095c94d0a30f2a3ec0a2c7.zip |
Freed leaks
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 4 | ||||
-rw-r--r-- | inc/cub3d_defines.h | 2 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | src/ft_check_missing.c | 2 | ||||
-rw-r--r-- | src/ft_del_extra_sprites.c | 31 | ||||
-rw-r--r-- | src/ft_exit.c | 1 | ||||
-rw-r--r-- | src/ft_key_loop.c | 5 | ||||
-rw-r--r-- | src/ft_suffer_animation.c | 31 | ||||
-rw-r--r-- | src/ft_treat_args.c | 2 | ||||
-rw-r--r-- | src/ft_warp_level.c | 4 |
11 files changed, 74 insertions, 10 deletions
@@ -93,6 +93,7 @@ SRCS_NAME += ft_suffer_animation.c 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 = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index 2103295..a2d050c 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -81,7 +81,8 @@ void ft_draw_sprite(t_cub *cl, t_sprite *sprite); void ft_calc_trap(t_cub *cl); void ft_draw_traps(t_cub *cl, t_sprite *sprite); void ft_draw_skybox(t_cub *cl); -void ft_suffer_animation(t_cub *cl); +void ft_macos_suffer_animation(t_cub *cl); +void ft_linux_suffer_animation(t_cub *cl); void ft_draw_life_bar(t_win *wl, t_cub *cl); /* @@ -153,6 +154,7 @@ int8_t ft_save_to_bmp(t_cub *cl); int ft_error(uint8_t retval, const char *errmsg, t_cub *clist); uint8_t ft_free_words(char **words); uint8_t ft_free_sprites(char **sprites); +void ft_del_extra_sprites(t_cub *cl); int8_t ft_warp_level(char *path, t_cub *cl); int ft_exit(uint8_t exit_code, t_cub *clist); uint32_t ft_rgb_to_hex(t_rgb rgb); diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 588670d..ab3a910 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -89,7 +89,7 @@ enum # define FT_SFX_N_LVL_PATH "./media/sound/sfx/next_lvl.wav" # 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_SCR_TRAP_PATH "./media/sound/sfx/trap.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" diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index e1ca235..d5b3bf7 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -237,7 +237,6 @@ typedef struct s_cub struct s_map mlist; struct s_ray rlist; struct s_img img; - struct s_img red_scr; struct s_rgb f_rgb; struct s_rgb c_rgb; struct s_img tlist[16]; diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index e349d05..1e89781 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -27,7 +27,7 @@ static int ft_check_missing_sfx(t_cub *clist) { if (ft_check_not_found(FT_SFX_DEATH_PATH) < 0) - return (ft_missing_error(FT_MISS_SFX_DEATH, clist)); + return (ft_missing_error(FT_ERR_MISS_SFX_DEATH, clist)); if (ft_check_not_found(FT_SFX_FS_ONE_PATH) < 0) return (ft_missing_error(FT_ERR_MISS_SFX_FS_ONE, clist)); if (ft_check_not_found(FT_SFX_FS_TWO_PATH) < 0) diff --git a/src/ft_del_extra_sprites.c b/src/ft_del_extra_sprites.c new file mode 100644 index 0000000..21df608 --- /dev/null +++ b/src/ft_del_extra_sprites.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_key_loop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ +/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <mlx.h> +#include <stdint.h> +#include <stddef.h> + +void + ft_del_extra_sprites(t_cub *cl) +{ + uint8_t i; + + i = 1; + while ((i + 2) <= cl->mlist.topsp) + { + if (cl->tlist[i + 7].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 7].img); + i++; + } +} diff --git a/src/ft_exit.c b/src/ft_exit.c index 3ec26ad..28a1489 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -71,6 +71,7 @@ int { if (clist->walltexgood) ft_del_tex(clist); + ft_del_extra_sprites(clist); if (clist->wlist.inited) { if (FT_OS == 1) diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index 66f72ef..8f9d688 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -58,7 +58,10 @@ static void { pl->pos_x = old_x + ((old_x - x) / 3); pl->pos_y = old_y + ((old_y - y) / 3); - ft_suffer_animation(cl); + if (FT_OS == 1) + ft_macos_suffer_animation(cl); + else + ft_linux_suffer_animation(cl); x = ft_find_x(key, pl); y = ft_find_y(key, pl); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index bc8eb12..7df91cd 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -17,7 +17,36 @@ #include <unistd.h> void - ft_suffer_animation(t_cub *cl) + ft_linux_suffer_animation(t_cub *cl) +{ + int32_t x; + int32_t y; + + y = -1; + cl->img.img = mlx_new_image(cl->wlist.wlx, + cl->wlist.x_size, cl->wlist.y_size); + cl->img.ptr = mlx_get_data_addr(cl->img.img, &cl->img.bpp, + &cl->img.sizeline, &cl->img.endian); + while (++y < (int32_t)cl->wlist.y_size) + { + x = -1; + while (++x < (int32_t)cl->wlist.x_size) + { + *(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline))) = 0x00880404; + } + } + mlx_put_image_to_window(cl->wlist.wlx, + cl->wlist.winptr, cl->img.img, 0, 0); + mlx_destroy_image(cl->wlist.wlx, cl->img.img); + cl->plist.life -= 20; + if (cl->plist.life <= 0) + ft_warp_level(cl->mlist.filename, cl); + /* TODO death screen here */ +} + +void + ft_macos_suffer_animation(t_cub *cl) { int32_t x; int32_t y; diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index 92464ab..4cc759e 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -55,6 +55,6 @@ uint8_t return (ft_exit(FT_RET_FINE, clist)); } else - return (ft_error(FT_RET_BAD_ARGV, FT_ERR_ARGV, clist)) + return (ft_error(FT_RET_BAD_ARGV, FT_ERR_ARGV, clist)); return (FT_RET_FINE); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 7a04dc9..69b7b78 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -58,16 +58,14 @@ static void cl->tlist[i].img = NULL; } if (cl->mlist.isnlvl && cl->tlist[5].img) - { mlx_destroy_image(cl->wlist.wlx, cl->tlist[5].img); - cl->tlist[5].img = NULL; - } if (cl->mlist.isftex && cl->tlist[6].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img); if (cl->mlist.isctex && cl->tlist[7].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img); if (cl->mlist.istraps && cl->tlist[15].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img); + ft_del_extra_sprites(cl); } static void |