diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-22 16:58:26 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-22 16:58:26 +0100 |
commit | b34688558a7b9d2b1f95c00a33197cdc017e8dc5 (patch) | |
tree | 51c0339d1252a1384113767f1efa5a285f05b325 /src | |
parent | Raycasting normed (diff) | |
download | 42-cub3d-b34688558a7b9d2b1f95c00a33197cdc017e8dc5.tar.gz 42-cub3d-b34688558a7b9d2b1f95c00a33197cdc017e8dc5.tar.bz2 42-cub3d-b34688558a7b9d2b1f95c00a33197cdc017e8dc5.tar.xz 42-cub3d-b34688558a7b9d2b1f95c00a33197cdc017e8dc5.tar.zst 42-cub3d-b34688558a7b9d2b1f95c00a33197cdc017e8dc5.zip |
Norm so far
Diffstat (limited to '')
-rw-r--r-- | src/ft_del_sfx_cmd.c | 30 | ||||
-rw-r--r-- | src/ft_del_sprites_lists.c (renamed from src/ft_del_lists.c) | 11 | ||||
-rw-r--r-- | src/ft_exit.c | 3 | ||||
-rw-r--r-- | src/ft_suffer_animation.c | 43 | ||||
-rw-r--r-- | src/ft_tex_init.c | 106 | ||||
-rw-r--r-- | src/ft_tex_num_init.c | 69 | ||||
-rw-r--r-- | src/ft_tex_weap_init.c | 3 | ||||
-rw-r--r-- | src/ft_treat_args.c | 21 | ||||
-rw-r--r-- | src/ft_warp_level.c | 34 |
9 files changed, 180 insertions, 140 deletions
diff --git a/src/ft_del_sfx_cmd.c b/src/ft_del_sfx_cmd.c new file mode 100644 index 0000000..b5c5fdf --- /dev/null +++ b/src/ft_del_sfx_cmd.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_del_sfx_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +void + ft_del_sfx_cmd(t_cub *clist) +{ + uint8_t i; + + i = 0; + while (i < 10) + { + ft_memdel((void*)&clist->sfx[i].cmd); + i++; + } + ft_memdel((void*)&clist->sfx[1].cmd_alt); + ft_memdel((void*)&clist->sfx[3].cmd_alt); +} diff --git a/src/ft_del_lists.c b/src/ft_del_sprites_lists.c index e1a5288..72e5fa9 100644 --- a/src/ft_del_lists.c +++ b/src/ft_del_sprites_lists.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_del_lists.c :+: :+: :+: */ +/* ft_del_sprites_lists.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -15,18 +15,11 @@ #include <stdint.h> void - ft_del_lists(t_cub *clist) + ft_del_sprites_lists(t_cub *clist) { uint8_t i; i = 0; - while (i < 10) - { - ft_memdel((void*)&clist->sfx[i].cmd); - i++; - } - ft_memdel((void*)&clist->sfx[1].cmd_alt); - ft_memdel((void*)&clist->sfx[3].cmd_alt); while (i < 8) { ft_memdel((void*)&clist->sprites[i]); diff --git a/src/ft_exit.c b/src/ft_exit.c index 2af15c7..a8ca19f 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -61,7 +61,8 @@ int } ft_cancel_threads(clist); ft_del_map(&clist->mlist); - ft_del_lists(clist); + ft_del_sprites_lists(clist); + ft_del_sfx_cmd(clist); ft_del_last_remains(clist); ft_printf("Exiting program\n"); exit(exit_code); diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 6a325bc..51de24a 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -15,6 +15,23 @@ #include <mlx.h> #include <stdint.h> +static void + ft_get_damaged(t_cub *cl) +{ + cl->plist.life -= FT_TRAP_DAMAGE_AMOUNT; + if (cl->plist.life <= 0) + { + cl->isdead = 1; + cl->sfx[0].sfx_play(cl->sfx); + ft_death_screen(cl); + } + else + { + cl->sfx[4].sfx_play(cl->sfx); + cl->sfx[3].sfx_play(cl->sfx); + } +} + void ft_linux_suffer_animation(t_cub *cl) { @@ -36,18 +53,7 @@ void 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 -= FT_TRAP_DAMAGE_AMOUNT; - if (cl->plist.life <= 0) - { - cl->isdead = 1; - cl->sfx[0].sfx_play(cl->sfx); - ft_death_screen(cl); - } - else - { - cl->sfx[4].sfx_play(cl->sfx); - cl->sfx[3].sfx_play(cl->sfx); - } + ft_get_damaged(cl); } void @@ -72,17 +78,6 @@ void (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); } } - cl->plist.life -= FT_TRAP_DAMAGE_AMOUNT; - if (cl->plist.life <= 0) - { - cl->isdead = 1; - cl->sfx[0].sfx_play(cl->sfx); - ft_death_screen(cl); - } - else - { - cl->sfx[4].sfx_play(cl->sfx); - cl->sfx[3].sfx_play(cl->sfx); - } + ft_get_damaged(cl); cl->doicast = 0; } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 5e445ce..89a4d77 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -41,55 +41,6 @@ */ static void - ft_init_numbers(t_cub *cl) -{ - cl->tnum[0].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_ZER_PATH, &cl->tnum[0].img_w, &cl->tnum[0].img_h); - cl->tnum[0].ptr = mlx_get_data_addr(cl->tnum[0].img, - &cl->tnum[0].bpp, &cl->tnum[0].sizeline, &cl->tnum[0].endian); - cl->tnum[1].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_ONE_PATH, &cl->tnum[1].img_w, &cl->tnum[1].img_h); - cl->tnum[1].ptr = mlx_get_data_addr(cl->tnum[1].img, - &cl->tnum[1].bpp, &cl->tnum[1].sizeline, &cl->tnum[1].endian); - cl->tnum[2].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_TWO_PATH, &cl->tnum[2].img_w, &cl->tnum[2].img_h); - cl->tnum[2].ptr = mlx_get_data_addr(cl->tnum[2].img, - &cl->tnum[2].bpp, &cl->tnum[2].sizeline, &cl->tnum[2].endian); - cl->tnum[3].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_THR_PATH, &cl->tnum[3].img_w, &cl->tnum[3].img_h); - cl->tnum[3].ptr = mlx_get_data_addr(cl->tnum[3].img, - &cl->tnum[3].bpp, &cl->tnum[3].sizeline, &cl->tnum[3].endian); - cl->tnum[4].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_FOU_PATH, &cl->tnum[4].img_w, &cl->tnum[4].img_h); - cl->tnum[4].ptr = mlx_get_data_addr(cl->tnum[4].img, - &cl->tnum[4].bpp, &cl->tnum[4].sizeline, &cl->tnum[4].endian); - cl->tnum[5].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_FIV_PATH, &cl->tnum[5].img_w, &cl->tnum[5].img_h); - cl->tnum[5].ptr = mlx_get_data_addr(cl->tnum[5].img, - &cl->tnum[5].bpp, &cl->tnum[5].sizeline, &cl->tnum[5].endian); - cl->tnum[6].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_SIX_PATH, &cl->tnum[6].img_w, &cl->tnum[6].img_h); - cl->tnum[6].ptr = mlx_get_data_addr(cl->tnum[6].img, - &cl->tnum[6].bpp, &cl->tnum[6].sizeline, &cl->tnum[6].endian); - cl->tnum[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_SEV_PATH, &cl->tnum[7].img_w, &cl->tnum[7].img_h); - cl->tnum[7].ptr = mlx_get_data_addr(cl->tnum[7].img, - &cl->tnum[7].bpp, &cl->tnum[7].sizeline, &cl->tnum[7].endian); - cl->tnum[8].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_EIG_PATH, &cl->tnum[8].img_w, &cl->tnum[8].img_h); - cl->tnum[8].ptr = mlx_get_data_addr(cl->tnum[8].img, - &cl->tnum[8].bpp, &cl->tnum[8].sizeline, &cl->tnum[8].endian); - cl->tnum[9].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_NIN_PATH, &cl->tnum[9].img_w, &cl->tnum[9].img_h); - cl->tnum[9].ptr = mlx_get_data_addr(cl->tnum[9].img, - &cl->tnum[9].bpp, &cl->tnum[9].sizeline, &cl->tnum[9].endian); - cl->tnum[10].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_PER_PATH, &cl->tnum[10].img_w, &cl->tnum[10].img_h); - cl->tnum[10].ptr = mlx_get_data_addr(cl->tnum[10].img, - &cl->tnum[10].bpp, &cl->tnum[10].sizeline, &cl->tnum[10].endian); -} - -static void ft_next_sprite_init(t_cub *cl) { uint8_t i; @@ -108,22 +59,8 @@ static void } static void - ft_wall_tex_init_norme_bis(t_cub *cl) + ft_wall_tex_init_more_bonus(t_cub *cl) { - if (cl->mlist.isskybox) - { - cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.skybox_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h); - cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, - &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); - } - else if (cl->mlist.isctex) - { - cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.ce_tex_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h); - cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, - &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); - } cl->tlist[16].img = mlx_xpm_file_to_image(cl->wlist.wlx, FT_HUD_BACK_PATH, &cl->tlist[16].img_w, &cl->tlist[16].img_h); cl->tlist[16].ptr = mlx_get_data_addr(cl->tlist[16].img, @@ -136,14 +73,40 @@ static void FT_WEAPON_TWO_SPR_PATH, &cl->tlist[19].img_w, &cl->tlist[19].img_h); cl->tlist[19].ptr = mlx_get_data_addr(cl->tlist[19].img, &cl->tlist[19].bpp, &cl->tlist[19].sizeline, &cl->tlist[19].endian); - ft_init_numbers(cl); cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) ft_next_sprite_init(cl); } static void - ft_wall_tex_init_norme(t_cub *cl) + ft_wall_tex_init_next_bonus(t_cub *cl) +{ + if (cl->mlist.isheals) + { + cl->tlist[17].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_HEAL_PACK_PATH, &cl->tlist[17].img_w, &cl->tlist[17].img_h); + cl->tlist[17].ptr = mlx_get_data_addr(cl->tlist[17].img, + &cl->tlist[17].bpp, &cl->tlist[17].sizeline, &cl->tlist[17].endian); + } + if (cl->mlist.isskybox) + { + cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.skybox_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h); + cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, + &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); + } + else if (cl->mlist.isctex) + { + cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.ce_tex_path, &cl->tlist[7].img_w, &cl->tlist[7].img_h); + cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img, + &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian); + } + ft_wall_tex_init_more_bonus(cl); +} + +static void + ft_wall_tex_init_bonus(t_cub *cl) { if (cl->mlist.isnlvl) { @@ -166,14 +129,7 @@ static void cl->tlist[15].ptr = mlx_get_data_addr(cl->tlist[15].img, &cl->tlist[15].bpp, &cl->tlist[15].sizeline, &cl->tlist[15].endian); } - if (cl->mlist.isheals) - { - cl->tlist[17].img = mlx_xpm_file_to_image(cl->wlist.wlx, - FT_HEAL_PACK_PATH, &cl->tlist[17].img_w, &cl->tlist[17].img_h); - cl->tlist[17].ptr = mlx_get_data_addr(cl->tlist[17].img, - &cl->tlist[17].bpp, &cl->tlist[17].sizeline, &cl->tlist[17].endian); - } - ft_wall_tex_init_norme_bis(cl); + ft_wall_tex_init_next_bonus(cl); } void @@ -199,5 +155,5 @@ void cl->mlist.sprite_path[0], &cl->tlist[4].img_w, &cl->tlist[4].img_h); cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img, &cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian); - ft_wall_tex_init_norme(cl); + ft_wall_tex_init_bonus(cl); } diff --git a/src/ft_tex_num_init.c b/src/ft_tex_num_init.c new file mode 100644 index 0000000..b17910a --- /dev/null +++ b/src/ft_tex_num_init.c @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tex_num_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fmoenne- <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:43:55 by fmoenne- #+# #+# */ +/* Updated: 2020/02/14 17:43:56 by fmoenne- ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <mlx.h> + +static void + ft_next_num_init(t_cub *cl) +{ + cl->tnum[6].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_SIX_PATH, &cl->tnum[6].img_w, &cl->tnum[6].img_h); + cl->tnum[6].ptr = mlx_get_data_addr(cl->tnum[6].img, + &cl->tnum[6].bpp, &cl->tnum[6].sizeline, &cl->tnum[6].endian); + cl->tnum[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_SEV_PATH, &cl->tnum[7].img_w, &cl->tnum[7].img_h); + cl->tnum[7].ptr = mlx_get_data_addr(cl->tnum[7].img, + &cl->tnum[7].bpp, &cl->tnum[7].sizeline, &cl->tnum[7].endian); + cl->tnum[8].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_EIG_PATH, &cl->tnum[8].img_w, &cl->tnum[8].img_h); + cl->tnum[8].ptr = mlx_get_data_addr(cl->tnum[8].img, + &cl->tnum[8].bpp, &cl->tnum[8].sizeline, &cl->tnum[8].endian); + cl->tnum[9].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_NIN_PATH, &cl->tnum[9].img_w, &cl->tnum[9].img_h); + cl->tnum[9].ptr = mlx_get_data_addr(cl->tnum[9].img, + &cl->tnum[9].bpp, &cl->tnum[9].sizeline, &cl->tnum[9].endian); + cl->tnum[10].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_PER_PATH, &cl->tnum[10].img_w, &cl->tnum[10].img_h); + cl->tnum[10].ptr = mlx_get_data_addr(cl->tnum[10].img, + &cl->tnum[10].bpp, &cl->tnum[10].sizeline, &cl->tnum[10].endian); +} + +void + ft_num_tex_init(t_cub *cl) +{ + cl->tnum[0].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_ZER_PATH, &cl->tnum[0].img_w, &cl->tnum[0].img_h); + cl->tnum[0].ptr = mlx_get_data_addr(cl->tnum[0].img, + &cl->tnum[0].bpp, &cl->tnum[0].sizeline, &cl->tnum[0].endian); + cl->tnum[1].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_ONE_PATH, &cl->tnum[1].img_w, &cl->tnum[1].img_h); + cl->tnum[1].ptr = mlx_get_data_addr(cl->tnum[1].img, + &cl->tnum[1].bpp, &cl->tnum[1].sizeline, &cl->tnum[1].endian); + cl->tnum[2].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_TWO_PATH, &cl->tnum[2].img_w, &cl->tnum[2].img_h); + cl->tnum[2].ptr = mlx_get_data_addr(cl->tnum[2].img, + &cl->tnum[2].bpp, &cl->tnum[2].sizeline, &cl->tnum[2].endian); + cl->tnum[3].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_THR_PATH, &cl->tnum[3].img_w, &cl->tnum[3].img_h); + cl->tnum[3].ptr = mlx_get_data_addr(cl->tnum[3].img, + &cl->tnum[3].bpp, &cl->tnum[3].sizeline, &cl->tnum[3].endian); + cl->tnum[4].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_FOU_PATH, &cl->tnum[4].img_w, &cl->tnum[4].img_h); + cl->tnum[4].ptr = mlx_get_data_addr(cl->tnum[4].img, + &cl->tnum[4].bpp, &cl->tnum[4].sizeline, &cl->tnum[4].endian); + cl->tnum[5].img = mlx_xpm_file_to_image(cl->wlist.wlx, + FT_FIV_PATH, &cl->tnum[5].img_w, &cl->tnum[5].img_h); + cl->tnum[5].ptr = mlx_get_data_addr(cl->tnum[5].img, + &cl->tnum[5].bpp, &cl->tnum[5].sizeline, &cl->tnum[5].endian); + ft_next_num_init(cl); +} diff --git a/src/ft_tex_weap_init.c b/src/ft_tex_weap_init.c index 983da0b..d0bf835 100644 --- a/src/ft_tex_weap_init.c +++ b/src/ft_tex_weap_init.c @@ -10,10 +10,7 @@ /* */ /* ************************************************************************** */ -#include <libft.h> #include <cub3d.h> -#include <stdint.h> -#include <stdio.h> #include <mlx.h> /* diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index cf487f7..19da836 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -29,6 +29,18 @@ uint8_t return (0); } +static void + ft_init_macos_img(t_cub *clist) +{ + if (FT_OS == 1) + { + clist->img.img = mlx_new_image(clist->wlist.wlx, + clist->wlist.x_size, clist->wlist.y_size); + clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, + &clist->img.sizeline, &clist->img.endian); + } +} + uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist) { @@ -38,13 +50,8 @@ uint8_t return (ft_exit(FT_RET_FAILED_MLX, clist)); ft_wall_tex_init(clist); ft_weap_tex_init(clist); - if (FT_OS == 1) - { - clist->img.img = mlx_new_image(clist->wlist.wlx, - clist->wlist.x_size, clist->wlist.y_size); - clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, - &clist->img.sizeline, &clist->img.endian); - } + ft_num_tex_init(clist); + ft_init_macos_img(clist); ft_draw_scene(clist); if (clist->mlist.ismusic) ft_enable_music(clist); diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 8fb5415..88ab45d 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -12,11 +12,9 @@ #include <libft.h> #include <cub3d.h> -#include <mlx.h> #include <stddef.h> #include <stdlib.h> #include <stdint.h> -#include <unistd.h> #include <signal.h> #include <pthread.h> @@ -39,24 +37,23 @@ static void cl->plist.handles_weapon = tmp_handles; } -static void - ft_del_some(t_cub *cl) +static int8_t + ft_reinit_some(t_cub *cl) { - int8_t i; - ft_player_keepings(cl); cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); ft_del_tex(cl); - i = -1; - while (++i < 8) - ft_memdel((void*)&cl->sprites[i]); - ft_memdel((void*)&cl->sprites); - i = -1; - while (++i < 2) - ft_memdel((void*)&cl->weaps[i]); - ft_memdel((void*)&cl->weaps); + ft_del_map(&cl->mlist); + ft_del_sprites_lists(cl); + if (ft_init_sprites(&cl->sprites) < 0) + return (-1); + if (ft_init_weaps(&cl->weaps) < 0) + return (-1); + if (ft_init_map(&cl->mlist) < 0) + return (-1); + return (0); } static void @@ -92,13 +89,7 @@ int8_t ft_sprintf(next_path, "%s", path); if ((isoldmus = cl->mlist.ismusic)) tmp_mup = ft_strdup(cl->mlist.music_path); - ft_del_some(cl); - ft_del_map(&cl->mlist); - if (ft_init_sprites(&cl->sprites) < 0) - return (-1); - if (ft_init_weaps(&cl->weaps) < 0) - return (-1); - if (ft_init_map(&cl->mlist) < 0) + if (ft_reinit_some(cl) < 0) return (-1); ft_parse_map(next_path, cl); ft_treat_music(isoldmus, tmp_mup, cl); @@ -107,6 +98,7 @@ int8_t ft_memdel((void*)&tmp_mup); ft_wall_tex_init(cl); ft_weap_tex_init(cl); + ft_num_tex_init(cl); ft_memdel((void*)&next_path); return (0); } |