From abd20a73b4733a1a8b845f6ff0817ed77e545173 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 10 Mar 2020 10:48:58 +0100 Subject: Freed multiple leaks --- src/ft_exit.c | 4 ++++ src/ft_init_lists.c | 2 ++ src/ft_init_s_ray.c | 2 ++ src/ft_raycasting.c | 14 ++++++-------- src/ft_save_to_bmp.c | 7 ++++--- src/ft_warp_level.c | 9 ++++++--- 6 files changed, 24 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ft_exit.c b/src/ft_exit.c index 97c9e02..fb6de09 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -57,6 +57,10 @@ static void mlx_destroy_image(clist->wlist.wlx, clist->tlist[4].img); if (clist->mlist.isnlvl && clist->tlist[5].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[5].img); + if (clist->mlist.isftex && clist->tlist[6].img) + mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img); + if (clist->mlist.isctex && clist->tlist[7].img) + mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img); } int diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index bd2ae74..82f5c0e 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -76,6 +76,8 @@ static int8_t cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); + if (!(cl->rlist.wall_dist_tab = (float*)malloc(1 * sizeof(float)))) + return (-1); cl->currlvl = 0; cl->walltexgood = 0; ft_init_funptr(cl); diff --git a/src/ft_init_s_ray.c b/src/ft_init_s_ray.c index e890d68..0d4ba96 100644 --- a/src/ft_init_s_ray.c +++ b/src/ft_init_s_ray.c @@ -11,6 +11,8 @@ /* ************************************************************************** */ #include +#include +#include t_ray ft_init_s_ray(void) diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 3cbd368..baa71af 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -83,17 +83,16 @@ static void void ft_castray(t_cub *cl) { - uint16_t i; - t_win *wl; - float *dist_tab; + uint16_t i; + t_win *wl; + ft_memdel((void**)&cl->rlist.wall_dist_tab); wl = &cl->wlist; i = (wl->y_size / 2) + 1; while (++i < wl->y_size) ft_floor_cast(i, cl); - if (!(dist_tab = malloc(sizeof(float) * cl->wlist.x_size))) - return ; - if (!(cl->rlist.wall_dist_tab = malloc(sizeof(float) * cl->wlist.x_size))) + if (!(cl->rlist.wall_dist_tab = + (float*)malloc(sizeof(float) * cl->wlist.x_size))) return ; i = 0; while (i < wl->x_size) @@ -102,8 +101,7 @@ void ft_choose_tex(cl); ft_calc_tex(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); - dist_tab[i] = cl->rlist.wall_dist; - cl->rlist.wall_dist_tab = dist_tab; + cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist; i++; } } diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c index 90bbb1f..ae3a2b6 100644 --- a/src/ft_save_to_bmp.c +++ b/src/ft_save_to_bmp.c @@ -93,9 +93,10 @@ static int8_t bmp_info.size_image = size; if (!(fd = open(fname, O_RDWR | O_CREAT, 0644))) return (-1); - write(fd, &bmp_file, sizeof(t_bmp_file)); - write(fd, &bmp_info, sizeof(t_bmp_info)); - write(fd, bmp, size); + if (!write(fd, &bmp_file, sizeof(t_bmp_file)) || + !write(fd, &bmp_info, sizeof(t_bmp_info)) || + !write(fd, bmp, size)) + return (-1); close(fd); return (0); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 4a02c2b..1f744c2 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -59,13 +59,16 @@ static void cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); - i = 0; - while (i <= 5) + i = -1; + while (++i <= 5) { mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img); cl->tlist[i].img = NULL; - i++; } + 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); } static void -- cgit v1.2.3 From 25247ca1f3ffc9485b02686f616c41a52f8eb82a Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 00:00:07 +0100 Subject: Pas trop ecole opti memoire mais ok --- src/ft_floor_cast.c | 46 +++++++++++++++++++++++++++------------------- src/ft_raycasting.c | 16 ++++++++++------ 2 files changed, 37 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 384f699..d2c6046 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -78,8 +78,6 @@ static void { ft_set_tex_xy(7, rl, cl); } - rl->x_floor += cl->mlist.x_floor_step; - rl->y_floor += cl->mlist.y_floor_step; if (cl->mlist.isftex) ft_draw_extra_tex(6, y, x, cl); else @@ -91,28 +89,38 @@ static void } void - ft_floor_cast(uint16_t y, t_cub *cl) + ft_floor_cast(t_cub *cl) { t_ray *rl; uint16_t x; + uint16_t y; rl = &cl->rlist; - rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x; - rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y; - rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x; - rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y; - rl->p = y - cl->wlist.y_size / 2; - cl->plist.pos_z = 0.5 * cl->wlist.y_size; - rl->row_dist = cl->plist.pos_z / rl->p; - cl->mlist.x_floor_step = rl->row_dist * - (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size; - cl->mlist.y_floor_step = rl->row_dist * - (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size; - rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir; - rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir; - x = 0; - while (++x < cl->wlist.x_size) + y = (cl->wlist.y_size / 2) + 1; + while (++y < cl->wlist.y_size) { - ft_floor_cast_loop(y, x, rl, cl); + rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x; + rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y; + rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x; + rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y; + rl->p = y - cl->wlist.y_size / 2; + cl->plist.pos_z = 0.5 * cl->wlist.y_size; + rl->row_dist = cl->plist.pos_z / rl->p; + cl->mlist.x_floor_step = rl->row_dist * + (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size; + cl->mlist.y_floor_step = rl->row_dist * + (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size; + rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir; + rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir; + x = -1; + while (++x < cl->wlist.x_size) + { + if (cl->rlist.wall_bz[x] <= y) + { + ft_floor_cast_loop(y, x, rl, cl); + } + rl->x_floor += cl->mlist.x_floor_step; + rl->y_floor += cl->mlist.y_floor_step; + } } } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index baa71af..5c57044 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -76,24 +76,25 @@ static void if (cl->rlist.wall_t < 0) cl->rlist.wall_t = 0; cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2; - if (cl->rlist.wall_b >= (float)wl->y_size) + if (cl->rlist.wall_b >= (int16_t)wl->y_size) cl->rlist.wall_b = wl->y_size - 1; + cl->rlist.wall_bz[i] = cl->rlist.wall_b; } void ft_castray(t_cub *cl) { - uint16_t i; - t_win *wl; + uint16_t i; + t_win *wl; ft_memdel((void**)&cl->rlist.wall_dist_tab); wl = &cl->wlist; - i = (wl->y_size / 2) + 1; - while (++i < wl->y_size) - ft_floor_cast(i, cl); if (!(cl->rlist.wall_dist_tab = (float*)malloc(sizeof(float) * cl->wlist.x_size))) return ; + if (!(cl->rlist.wall_bz = + (int16_t*)malloc(cl->wlist.x_size * sizeof(int16_t)))) + return ; i = 0; while (i < wl->x_size) { @@ -104,4 +105,7 @@ void cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist; i++; } + ft_floor_cast(cl); + i = 0; + ft_memdel((void**)&cl->rlist.wall_bz); } -- cgit v1.2.3 From 02433637a499cd48e501d89c54e6ddf488dca98f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 00:27:19 +0100 Subject: qweqwe --- src/ft_floor_cast.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src') diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index d2c6046..1082fe5 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -16,16 +16,8 @@ static void ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) { - if (cl->mlist.darklvl > 0) - { - *(int*)(cl->img.ptr + + *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl); - } - else - { - *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); - } } static void -- cgit v1.2.3 From 1bfb92324f267291f556cb464ea42a07d3c8224a Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 00:36:54 +0100 Subject: Freed leaks --- src/ft_init_lists.c | 2 -- src/ft_raycasting.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 82f5c0e..bd2ae74 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -76,8 +76,6 @@ static int8_t cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); - if (!(cl->rlist.wall_dist_tab = (float*)malloc(1 * sizeof(float)))) - return (-1); cl->currlvl = 0; cl->walltexgood = 0; ft_init_funptr(cl); diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 5c57044..221c43d 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -87,7 +87,6 @@ void uint16_t i; t_win *wl; - ft_memdel((void**)&cl->rlist.wall_dist_tab); wl = &cl->wlist; if (!(cl->rlist.wall_dist_tab = (float*)malloc(sizeof(float) * cl->wlist.x_size))) @@ -107,5 +106,6 @@ void } ft_floor_cast(cl); i = 0; + ft_memdel((void**)&cl->rlist.wall_dist_tab); ft_memdel((void**)&cl->rlist.wall_bz); } -- cgit v1.2.3 From 54a87749b47b094d54858f563fe7796a2209d83b Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 00:39:54 +0100 Subject: Stupid me --- src/ft_floor_cast.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 1082fe5..36c759f 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -23,8 +23,8 @@ static void static void ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl) { - float dist; - float calc; + float dist; + float calc; if ((dist = cl->rlist.row_dist) <= 0) dist = 0.0001; -- cgit v1.2.3 From 154ccbc0546018554982f9170d32b7858a8c33aa Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 01:17:41 +0100 Subject: Norme --- src/ft_floor_cast.c | 16 ++-------------- src/ft_floor_cast_inits.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 src/ft_floor_cast_inits.c (limited to 'src') diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 36c759f..b6c7e72 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_raycasting.c :+: :+: :+: */ +/* ft_floor_cast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -91,19 +91,7 @@ void y = (cl->wlist.y_size / 2) + 1; while (++y < cl->wlist.y_size) { - rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x; - rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y; - rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x; - rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y; - rl->p = y - cl->wlist.y_size / 2; - cl->plist.pos_z = 0.5 * cl->wlist.y_size; - rl->row_dist = cl->plist.pos_z / rl->p; - cl->mlist.x_floor_step = rl->row_dist * - (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size; - cl->mlist.y_floor_step = rl->row_dist * - (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size; - rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir; - rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir; + ft_floor_cast_inits(y, rl, cl); x = -1; while (++x < cl->wlist.x_size) { diff --git a/src/ft_floor_cast_inits.c b/src/ft_floor_cast_inits.c new file mode 100644 index 0000000..591eb24 --- /dev/null +++ b/src/ft_floor_cast_inits.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_floor_cast_inits.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:22:57 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +void + ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl) +{ + rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x; + rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y; + rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x; + rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y; + rl->p = y - cl->wlist.y_size / 2; + cl->plist.pos_z = 0.5 * cl->wlist.y_size; + rl->row_dist = cl->plist.pos_z / rl->p; + cl->mlist.x_floor_step = rl->row_dist * + (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size; + cl->mlist.y_floor_step = rl->row_dist * + (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size; + rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir; + rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir; +} -- cgit v1.2.3 From a752af80e3778b8a17b53b49b11ed235494a623d Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 01:44:15 +0100 Subject: Sliding like a champ --- src/ft_key_loop.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index d40de34..d3e871b 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -53,12 +53,12 @@ static void pl = &cl->plist; x = ft_find_x(key, pl); y = ft_find_y(key, pl); - if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][x]) || - cl->mlist.map[y][x] == '\0') - { - pl->pos_y = old_y; + if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[(uint64_t)old_y][x]) || + cl->mlist.map[(uint64_t)old_y][x] == '\0') pl->pos_x = old_x; - } + if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][(uint64_t)old_x]) || + cl->mlist.map[y][(uint64_t)old_x] == '\0') + pl->pos_y = old_y; } int -- cgit v1.2.3 From 15e4ca8491c9b2872b30cb1522f72920514a62f1 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 02:03:18 +0100 Subject: ft_calc_sprite in a better location, still sliding like a champ --- src/ft_draw_scene.c | 2 -- src/ft_raycasting.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 2cfa3f4..4d15df2 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -52,7 +52,6 @@ void } if (clist->mlist.isskybox) ft_draw_skybox(clist); - ft_calc_sprite(clist); mlx_put_image_to_window(clist->wlist.wlx, clist->wlist.winptr, clist->img.img, 0, 0); if (clist->ishud && clist->mlist.isnlvl) @@ -73,7 +72,6 @@ void clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, &clist->img.sizeline, &clist->img.endian); ft_castray(clist); - ft_calc_sprite(clist); if (ft_save_to_bmp(clist) < 0) ft_error(FT_RET_BMP_ERR, FT_ERR_WR_BMP, clist); mlx_destroy_image(clist->wlist.wlx, clist->img.img); diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 221c43d..2d6d197 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -105,7 +105,7 @@ void i++; } ft_floor_cast(cl); - i = 0; + ft_calc_sprite(cl); ft_memdel((void**)&cl->rlist.wall_dist_tab); ft_memdel((void**)&cl->rlist.wall_bz); } -- cgit v1.2.3 From 79af897f235b2172ce37e6d30b829fa0928aef3a Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 09:17:49 +0100 Subject: Good trap init --- src/ft_exit.c | 1 + src/ft_init_map.c | 2 ++ src/ft_tex_init.c | 89 +++++++++++++++++++++++++++++------------------------ src/ft_warp_level.c | 1 + 4 files changed, 53 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/ft_exit.c b/src/ft_exit.c index fb6de09..3b00701 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -33,6 +33,7 @@ static void ft_memdel((void**)&clist->mlist.ce_tex_path); ft_memdel((void**)&clist->mlist.nlevel_path); ft_memdel((void**)&clist->mlist.skybox_path); + ft_memdel((void**)&clist->mlist.traps_path); ft_memdel((void**)&clist->mlist.music_path); ft_memdel((void**)&clist->mlist.music_cmd); ft_memdel((void**)&clist->mlist.mapl); diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 27b4a39..f2b0726 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -29,6 +29,7 @@ static int8_t !(mlist->ce_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->nlevel_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->skybox_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->traps_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->music_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->music_cmd = (char*)ft_calloc(1, sizeof(char))) || !(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) || @@ -60,6 +61,7 @@ int8_t mlist->isnlvl = 0; mlist->ismusic = 0; mlist->isskybox = 0; + mlist->istrap = 0; mlist->darklvl = 0; mlist->scale = 0; mlist->nlx = 0; diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 4cbdf73..32bfb66 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -16,60 +16,69 @@ #include /* -** 0 : no -** 1 : so -** 2 : ea -** 3 : we -** 4 : sprite -** 5 : new level door -** 6 : floor -** 7 : ceil +** 0 : no +** 1 : so +** 2 : ea +** 3 : we +** 4 : sprite 1 +** 5 : new level door +** 6 : floor +** 7 : ceil / skybox +** 8 : sprite 2 +** 9 : sprite 3 +** 10 : sprite 4 +** 11 : sprite 5 +** 12 : sprite 6 +** 13 : sprite 7 +** 14 : sprite 8 +** 15 : trap */ static void - ft_get_nlvl_img(t_cub *cl) + ft_wall_tex_init_norme_bis(t_cub *cl) { - cl->tlist[5].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.nl_tex_path, &cl->tlist[5].img_w, &cl->tlist[5].img_h); - cl->tlist[5].ptr = mlx_get_data_addr(cl->tlist[5].img, - &cl->tlist[5].bpp, &cl->tlist[5].sizeline, &cl->tlist[5].endian); -} - -static void - ft_get_floor_tex(t_cub *cl) -{ - cl->tlist[6].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.fl_tex_path, &cl->tlist[6].img_w, &cl->tlist[6].img_h); - cl->tlist[6].ptr = mlx_get_data_addr(cl->tlist[6].img, - &cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian); -} - -static void - ft_get_ceil_tex(t_cub *cl) -{ - cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, + 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[7].ptr = mlx_get_data_addr(cl->tlist[7].img, + &cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].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); + } + cl->walltexgood = 1; } static void ft_wall_tex_init_norme(t_cub *cl) { if (cl->mlist.isnlvl) - ft_get_nlvl_img(cl); + { + cl->tlist[5].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.nl_tex_path, &cl->tlist[5].img_w, &cl->tlist[5].img_h); + cl->tlist[5].ptr = mlx_get_data_addr(cl->tlist[5].img, + &cl->tlist[5].bpp, &cl->tlist[5].sizeline, &cl->tlist[5].endian); + } if (cl->mlist.isftex) - ft_get_floor_tex(cl); - if (cl->mlist.isctex) - ft_get_ceil_tex(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); + cl->tlist[6].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.fl_tex_path, &cl->tlist[6].img_w, &cl->tlist[6].img_h); + cl->tlist[6].ptr = mlx_get_data_addr(cl->tlist[6].img, + &cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian); } - cl->walltexgood = 1; + if (cl->mlist.istrap) + { + cl->tlist[15].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.traps_path, &cl->tlist[15].img_w, &cl->tlist[15].img_h); + cl->tlist[15].ptr = mlx_get_data_addr(cl->tlist[15].img, + &cl->tlist[15].bpp, &cl->tlist[15].sizeline, &cl->tlist[15].endian); + } + ft_wall_tex_init_norme_bis(cl); } void diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 1f744c2..3c9110f 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -34,6 +34,7 @@ static void ft_memdel((void**)&ml->ce_tex_path); ft_memdel((void**)&ml->nlevel_path); ft_memdel((void**)&ml->skybox_path); + ft_memdel((void**)&ml->traps_path); ft_memdel((void**)&ml->music_path); ft_memdel((void**)&ml->music_cmd); ft_memdel((void**)&ml->mapl); -- cgit v1.2.3 From bfa1f4e6e61152ba3ff555d1508f43f0a5ab2754 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 09:50:36 +0100 Subject: Secured collision segv --- src/ft_exit.c | 2 ++ src/ft_init_lists.c | 2 +- src/ft_key_loop.c | 13 +++++++++---- src/ft_warp_level.c | 17 +++-------------- 4 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/ft_exit.c b/src/ft_exit.c index 3b00701..4125567 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -62,6 +62,8 @@ static void mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img); if (clist->mlist.isctex && clist->tlist[7].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img); + if (clist->mlist.istrap && clist->tlist[15].img) + mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img); } int diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index bd2ae74..8ba9a13 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -28,7 +28,7 @@ t_rgb return (rgb); } -static t_player +t_player ft_init_player(void) { t_player plist; diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index d3e871b..c68b228 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -26,7 +26,7 @@ static uint64_t return (pl->pos_x - (pl->dir_y * FT_COLL_MULT)); else if (key == 3) return (pl->pos_x - (pl->dir_x * (FT_COLL_MULT / 2))); - return (1); + return ((uint64_t)pl->pos_x); } static uint64_t @@ -40,9 +40,10 @@ static uint64_t return (pl->pos_y - (pl->dir_x * FT_COLL_MULT)); else if (key == 3) return (pl->pos_y + (pl->dir_y * (FT_COLL_MULT / 2))); - return (1); + return ((uint64_t)pl->pos_y); } +#include static void ft_collision(float old_y, float old_x, int32_t key, t_cub *cl) { @@ -75,8 +76,12 @@ int ft_collision(old_y, old_x, cl->key_input[i], cl); if (cl->mlist.isnlvl) { - if (ft_warp_level(cl) < 0) - return (ft_exit(FT_RET_FAILED_STRUCTS, cl)); + if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && + (uint32_t)cl->plist.pos_y == cl->mlist.nly) + { + return ((ft_warp_level(cl) < 0) ? + (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0)); + } } i++; } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 3c9110f..a4f705b 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -47,16 +47,7 @@ static void { uint8_t i; - cl->plist.pos_x = 0; - cl->plist.pos_y = 0; - cl->plist.pos_z = 0; - cl->plist.start_x = 0; - cl->plist.start_y = 0; - cl->plist.cam_x = 0; - cl->plist.dir_x = -1; - cl->plist.dir_y = 0; - cl->plist.plane_x = 0; - cl->plist.plane_y = 0.66; + cl->plist = ft_init_player(); cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); @@ -70,6 +61,8 @@ static void 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.istrap && cl->tlist[15].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img); } static void @@ -100,9 +93,6 @@ int8_t char *tmp_mup; uint8_t isoldmus; - if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && - (uint32_t)cl->plist.pos_y == cl->mlist.nly) - { if (!(next_path = (char *)malloc((ft_strlen( cl->mlist.nlevel_path) + 1) * sizeof(char)))) return (-1); @@ -119,6 +109,5 @@ int8_t ft_memdel((void**)&tmp_mup); ft_wall_tex_init(cl); ft_memdel((void**)&next_path); - } return (0); } -- cgit v1.2.3 From c1d1d76e0c88fbbbe4b1e0611a13a6a4df6cb424 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 09:59:17 +0100 Subject: Parsed traps --- src/ft_get_traps.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/ft_init_funptr.c | 4 +++- src/ft_select_get.c | 2 +- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/ft_get_traps.c (limited to 'src') diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c new file mode 100644 index 0000000..cdc05de --- /dev/null +++ b/src/ft_get_traps.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_tex_nl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 18:24:52 by rbousset #+# #+# */ +/* Updated: 2020/02/28 18:24:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +int8_t + ft_get_traps(char **words, t_cub *clist) +{ + if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM); + return (-1); + } + ft_memdel((void**)&clist->mlist.traps_path); + if (!(clist->mlist.traps_path = ft_strdup(*(words + 1)))) + { + ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE); + return (-1); + } + if (ft_check_not_found(clist->mlist.traps_path) < 0) + { + ft_sprintf(clist->errmsg, FT_ERR_RD_TRAP); + return (-1); + } + return (0); +} diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c index 6bfa3f7..c74b2c8 100644 --- a/src/ft_init_funptr.c +++ b/src/ft_init_funptr.c @@ -29,7 +29,8 @@ void ft_sprintf(clist->ref[10], "MU"); ft_sprintf(clist->ref[11], "SH"); ft_sprintf(clist->ref[12], "SB"); - ft_bzero(clist->ref[13], 3); + ft_sprintf(clist->ref[13], "T"); + ft_bzero(clist->ref[14], 3); } void @@ -54,4 +55,5 @@ void clist->get_ptr[10] = ft_get_music; clist->get_ptr[11] = ft_get_darkness; clist->get_ptr[12] = ft_get_skybox; + clist->get_ptr[14] = ft_get_traps; } diff --git a/src/ft_select_get.c b/src/ft_select_get.c index fe6bb3e..2a95309 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -66,7 +66,7 @@ static int8_t ret = 0; while (ft_strncmp(words[0], clist->ref[ret], 3) && clist->ref[ret][0]) ret++; - if (ret == 13) + if (ret == 14) ret = FT_PARSE_END_RET; ret = ft_check_exists(ret, clist); ret = ft_check_exists_two(ret, clist); -- cgit v1.2.3 From c581c7e3543058f015bddf96d76ac2d771ea40a0 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 10:16:48 +0100 Subject: Nice parse --- src/ft_check_map_line.c | 2 ++ src/ft_exit.c | 2 +- src/ft_get_traps.c | 28 ++++++++++++++++++++++++++++ src/ft_init_funptr.c | 2 +- src/ft_init_map.c | 4 +++- src/ft_select_get.c | 4 ++++ src/ft_tex_init.c | 2 +- src/ft_warp_level.c | 2 +- 8 files changed, 41 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 7fa68b7..c88e1f5 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -37,6 +37,8 @@ static int8_t ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL); return (-1); } + if (line[i] == 'T') + clist->mlist.istraps = 1; return (0); } diff --git a/src/ft_exit.c b/src/ft_exit.c index 4125567..4a131c8 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -62,7 +62,7 @@ static void mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img); if (clist->mlist.isctex && clist->tlist[7].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img); - if (clist->mlist.istrap && clist->tlist[15].img) + if (clist->mlist.istraps && clist->tlist[15].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img); } diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c index cdc05de..0235bb5 100644 --- a/src/ft_get_traps.c +++ b/src/ft_get_traps.c @@ -14,6 +14,34 @@ #include #include +void + ft_get_trap_spawn(t_cub *clist) +{ + size_t x; + size_t y; + uint8_t i; + + x = 1; + y = 1; + i = 0; + while (clist->mlist.map[y]) + { + while (clist->mlist.map[y][x]) + { + if (clist->mlist.map[y][x] == 'T') + { + clist->mlist.traps_nbr++; + clist->traps[i].s_pos_x = x; + clist->traps[i].s_pos_y = y; + i++; + } + x++; + } + x = 1; + y++; + } +} + int8_t ft_get_traps(char **words, t_cub *clist) { diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c index c74b2c8..c299336 100644 --- a/src/ft_init_funptr.c +++ b/src/ft_init_funptr.c @@ -55,5 +55,5 @@ void clist->get_ptr[10] = ft_get_music; clist->get_ptr[11] = ft_get_darkness; clist->get_ptr[12] = ft_get_skybox; - clist->get_ptr[14] = ft_get_traps; + clist->get_ptr[13] = ft_get_traps; } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index f2b0726..867a5b0 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -61,7 +61,9 @@ int8_t mlist->isnlvl = 0; mlist->ismusic = 0; mlist->isskybox = 0; - mlist->istrap = 0; + mlist->istraps = 0; + mlist->sprite_nbr = 0; + mlist->traps_nbr = 0; mlist->darklvl = 0; mlist->scale = 0; mlist->nlx = 0; diff --git a/src/ft_select_get.c b/src/ft_select_get.c index 2a95309..f748721 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -53,6 +53,10 @@ static int8_t return (-1); if (ret == 10 && (clist->mlist.music_path[0])) return (-1); + if (ret == 12 && (clist->mlist.skybox_path[0])) + return (-1); + if (ret == 13 && (clist->mlist.traps_path[0])) + return (-1); return (ret); } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 32bfb66..30b738e 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -71,7 +71,7 @@ static void cl->tlist[6].ptr = mlx_get_data_addr(cl->tlist[6].img, &cl->tlist[6].bpp, &cl->tlist[6].sizeline, &cl->tlist[6].endian); } - if (cl->mlist.istrap) + if (cl->mlist.istraps) { cl->tlist[15].img = mlx_xpm_file_to_image(cl->wlist.wlx, cl->mlist.traps_path, &cl->tlist[15].img_w, &cl->tlist[15].img_h); diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index a4f705b..faaf322 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -61,7 +61,7 @@ static void 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.istrap && cl->tlist[15].img) + if (cl->mlist.istraps && cl->tlist[15].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img); } -- cgit v1.2.3 From 537ace5d3615855ad2e236ab6f94862241ac71c4 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 10:19:22 +0100 Subject: Ok --- src/ft_draw_map.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c index 232891c..fc2613b 100644 --- a/src/ft_draw_map.c +++ b/src/ft_draw_map.c @@ -49,13 +49,13 @@ void { while (map[y][x]) { - if (ft_ischarset("1D", map[y][x])) + if (ft_ischarset("1", map[y][x])) ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) - 9 + (y * (scale)), 0x00ca5422, clist); else if (map[y][x] == '2') ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) - 9 + (y * (scale)), 0x0033ccff, clist); - else if (ft_ischarset("0LNSEW", map[y][x])) + else if (ft_ischarset("0LNSEWT", map[y][x])) ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) - 9 + (y * (scale)), 0x006afa6a, clist); x++; -- cgit v1.2.3 From 8df5ba15b4b54511ade9c875bf84ac2696630aa7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 10:28:33 +0100 Subject: Perfect collision on them traps --- src/ft_key_loop.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index c68b228..d19daaa 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -54,6 +54,13 @@ static void pl = &cl->plist; x = ft_find_x(key, pl); y = ft_find_y(key, pl); + if (cl->mlist.map[y][x] == 'T') + { + pl->pos_x = old_x + ((old_x - x) / 4); + pl->pos_y = old_y + ((old_y - y) / 4); + x = ft_find_x(key, pl); + y = ft_find_y(key, pl); + } if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[(uint64_t)old_y][x]) || cl->mlist.map[(uint64_t)old_y][x] == '\0') pl->pos_x = old_x; -- cgit v1.2.3 From b236416db21d03f7749e1c80d5b7abee70ea07d5 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 12:38:21 +0100 Subject: Pretty cool animation --- src/ft_draw_hud.c | 2 +- src/ft_floor_cast.c | 2 +- src/ft_init_lists.c | 1 + src/ft_key_loop.c | 1 + src/ft_suffer_animation.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/ft_suffer_animation.c (limited to 'src') diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c index 4ae497a..486112d 100644 --- a/src/ft_draw_hud.c +++ b/src/ft_draw_hud.c @@ -65,7 +65,7 @@ static void while (y < clist->wlist.y_size - (clist->mlist.map_h * scl) - 20) { *(int*)(clist->img.ptr + - ((uint8_t)x * 4 + (y * clist->img.sizeline))) = col; + ((uint16_t)x * 4 + (y * clist->img.sizeline))) = col; y++; } y = clist->wlist.y_size - (clist->mlist.map_h * scl) - 45; diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index b6c7e72..2eda9d8 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -17,7 +17,7 @@ static void ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) { *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl); + (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl); } static void diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 8ba9a13..79b0d14 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -43,6 +43,7 @@ t_player plist.dir_y = 0; plist.plane_x = 0; plist.plane_y = 0.66; + plist.life = 100; return (plist); } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index d19daaa..29718df 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -58,6 +58,7 @@ static void { pl->pos_x = old_x + ((old_x - x) / 4); pl->pos_y = old_y + ((old_y - y) / 4); + ft_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 new file mode 100644 index 0000000..bb69b4b --- /dev/null +++ b/src/ft_suffer_animation.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_key_loop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ +/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +void + ft_suffer_animation(t_cub *cl) +{ + uint16_t x; + uint16_t y; + + 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); + x = 0; + y = 0; + while (y < cl->wlist.y_size) + { + while (x < cl->wlist.x_size) + { + *(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline))) = 0x00ce1212; + x++; + } + x = 0; + y++; + } + 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); +} -- cgit v1.2.3 From 878b565e98728dcd0fba8dfeeba8b1ff46dbd5cd Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 11 Mar 2020 12:48:34 +0100 Subject: Tweaked suff animation --- src/ft_key_loop.c | 1 - src/ft_suffer_animation.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index 29718df..e0c2c28 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -43,7 +43,6 @@ static uint64_t return ((uint64_t)pl->pos_y); } -#include static void ft_collision(float old_y, float old_x, int32_t key, t_cub *cl) { diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index bb69b4b..4e77ca7 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -20,25 +20,31 @@ void { uint16_t x; uint16_t y; + uint8_t i; - 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); - x = 0; - y = 0; - while (y < cl->wlist.y_size) + i = 0; + while (i < 8) { - while (x < cl->wlist.x_size) + 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); + x = 0; + y = 0; + while (y < cl->wlist.y_size) { - *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = 0x00ce1212; - x++; + while (x < cl->wlist.x_size) + { + *(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline))) = 0x00ce1212; + x++; + } + x = 0; + y++; } - x = 0; - y++; + 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); + i++; } - 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); } -- cgit v1.2.3 From 17906f353bb6e87528f552891d7d4c91bb3ac789 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 11 Mar 2020 14:38:52 +0100 Subject: why macos --- src/ft_suffer_animation.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 4e77ca7..a2ce3b1 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -18,33 +18,30 @@ void ft_suffer_animation(t_cub *cl) { - uint16_t x; - uint16_t y; - uint8_t i; + int32_t x; + int32_t y; + int8_t i; + int32_t col; - i = 0; - while (i < 8) + i = -1; + col = 0x00ce2524; + while (++i < 100) { - 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); - x = 0; - y = 0; - while (y < cl->wlist.y_size) + cl->red_scr.img = mlx_new_image(cl->wlist.wlx, + cl->wlist.x_size, cl->wlist.y_size); + cl->red_scr.ptr = mlx_get_data_addr(cl->red_scr.img, &cl->red_scr.bpp, + &cl->red_scr.sizeline, &cl->red_scr.endian); + x = -1; + y = -1; + while (++y < (int32_t)cl->wlist.y_size) { - while (x < cl->wlist.x_size) - { - *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = 0x00ce1212; - x++; - } - x = 0; - y++; + while (++x < (int32_t)cl->wlist.x_size) + *(int*)(cl->red_scr.ptr + + (x * 4 + (y * cl->red_scr.sizeline))) = col; + x = -1; } 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); - i++; + cl->wlist.winptr, cl->red_scr.img, 0, 0); + mlx_destroy_image(cl->wlist.wlx, cl->red_scr.img); } } -- cgit v1.2.3 From 650e83573987d004171f250e236b21b243477355 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 11 Mar 2020 14:57:54 +0100 Subject: is not working --- src/ft_suffer_animation.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index a2ce3b1..3d3595a 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -21,11 +21,9 @@ void int32_t x; int32_t y; int8_t i; - int32_t col; i = -1; - col = 0x00ce2524; - while (++i < 100) + while (++i < 15) { cl->red_scr.img = mlx_new_image(cl->wlist.wlx, cl->wlist.x_size, cl->wlist.y_size); @@ -37,7 +35,7 @@ void { while (++x < (int32_t)cl->wlist.x_size) *(int*)(cl->red_scr.ptr + - (x * 4 + (y * cl->red_scr.sizeline))) = col; + (x * 4 + (y * cl->red_scr.sizeline))) = 0x00ce2524; x = -1; } mlx_put_image_to_window(cl->wlist.wlx, -- cgit v1.2.3 From 114df1314a69161e5802ce6192aa8f1599867f3e Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 11 Mar 2020 15:30:51 +0100 Subject: qweqwe --- src/ft_draw_scene.c | 12 ++++++------ src/ft_exit.c | 1 + src/ft_suffer_animation.c | 33 ++++++++++++++++----------------- src/ft_treat_args.c | 9 +++++---- 4 files changed, 28 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 4d15df2..9664363 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -41,10 +41,10 @@ static int8_t void ft_draw_scene(t_cub *clist) { - 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); + /* 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_castray(clist); if (clist->ishud) { @@ -53,7 +53,7 @@ void if (clist->mlist.isskybox) ft_draw_skybox(clist); mlx_put_image_to_window(clist->wlist.wlx, - clist->wlist.winptr, clist->img.img, 0, 0); + clist->wlist.winptr, clist->img.img, 0, 0); if (clist->ishud && clist->mlist.isnlvl) { if (ft_put_stage(clist) < 0) @@ -61,7 +61,7 @@ void ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); } } - mlx_destroy_image(clist->wlist.wlx, clist->img.img); + /* mlx_destroy_image(clist->wlist.wlx, clist->img.img); */ } void diff --git a/src/ft_exit.c b/src/ft_exit.c index 4a131c8..e0093da 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -73,6 +73,7 @@ int ft_del_tex(clist); if (clist->wlist.inited) { + mlx_destroy_image(clist->wlist.wlx, clist->img.img); mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr); clist->wlist.winptr = NULL; } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 3d3595a..2a1beb4 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -14,6 +14,7 @@ #include #include #include +#include void ft_suffer_animation(t_cub *cl) @@ -22,24 +23,22 @@ void int32_t y; int8_t i; - i = -1; - while (++i < 15) + /* cl->red_scr.img = mlx_new_image(cl->wlist.wlx, */ + /* cl->wlist.x_size, cl->wlist.y_size); */ + /* cl->red_scr.ptr = mlx_get_data_addr(cl->red_scr.img, &cl->red_scr.bpp, */ + /* &cl->red_scr.sizeline, &cl->red_scr.endian); */ + y = -1; + while (++y < (int32_t)cl->wlist.y_size) { - cl->red_scr.img = mlx_new_image(cl->wlist.wlx, - cl->wlist.x_size, cl->wlist.y_size); - cl->red_scr.ptr = mlx_get_data_addr(cl->red_scr.img, &cl->red_scr.bpp, - &cl->red_scr.sizeline, &cl->red_scr.endian); x = -1; - y = -1; - while (++y < (int32_t)cl->wlist.y_size) - { - while (++x < (int32_t)cl->wlist.x_size) - *(int*)(cl->red_scr.ptr + - (x * 4 + (y * cl->red_scr.sizeline))) = 0x00ce2524; - x = -1; - } - mlx_put_image_to_window(cl->wlist.wlx, - cl->wlist.winptr, cl->red_scr.img, 0, 0); - mlx_destroy_image(cl->wlist.wlx, cl->red_scr.img); + while (++x < (int32_t)cl->wlist.x_size) + *(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline))) = 0x00ffffff; } + i = -1; + mlx_put_image_to_window(cl->wlist.wlx, + cl->wlist.winptr, cl->img.img, 0, 0); + sleep(5); + /* while (++i < 120) */ + /* mlx_destroy_image(cl->wlist.wlx, cl->red_scr.img); */ } diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index a47f9f7..fe794d8 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -35,14 +36,14 @@ uint8_t if (argc < 3) { if (ft_init_winptr(clist) < 0) - { return (ft_exit(FT_RET_FAILED_MLX, clist)); - } + 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_draw_scene(clist); if (clist->mlist.ismusic) - { ft_enable_music(clist); - } ft_hooks_and_loops(&clist->wlist, clist); } else if (argc == 3 && !ft_strncmp("--save", argv[2], 7)) -- cgit v1.2.3 From 7f77c9bc922fb608f689385d642304956afe0492 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 11 Mar 2020 16:07:29 +0100 Subject: Performance --- src/ft_draw_scene.c | 11 ++++------- src/ft_hex_to_rgb.c | 11 +++++++++++ src/ft_init_lists.c | 1 + src/ft_key_loop.c | 7 +++---- src/ft_suffer_animation.c | 26 ++++++++++++++------------ 5 files changed, 33 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 9664363..39cdadc 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -45,22 +45,19 @@ void /* 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_castray(clist); + if (clist->doicast) + ft_castray(clist); + else + clist->doicast = 1; if (clist->ishud) - { ft_draw_hud(clist); - } if (clist->mlist.isskybox) ft_draw_skybox(clist); mlx_put_image_to_window(clist->wlist.wlx, clist->wlist.winptr, clist->img.img, 0, 0); if (clist->ishud && clist->mlist.isnlvl) - { if (ft_put_stage(clist) < 0) - { ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); - } - } /* mlx_destroy_image(clist->wlist.wlx, clist->img.img); */ } diff --git a/src/ft_hex_to_rgb.c b/src/ft_hex_to_rgb.c index 30332cc..1732473 100644 --- a/src/ft_hex_to_rgb.c +++ b/src/ft_hex_to_rgb.c @@ -13,6 +13,17 @@ #include #include +t_rgb + ft_hex_to_og_rgb(uint32_t color) +{ + t_rgb rgb; + + rgb.r = (color >> 16) & 255; + rgb.g = (color >> 8) & 255; + rgb.b = color & 255; + return (rgb); +} + t_bmp_rgb ft_hex_to_rgb(uint32_t color) { diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 79b0d14..d480912 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -74,6 +74,7 @@ static int8_t cl->key_input[i] = -1; cl->ishud = 0; cl->isoldmus = 0; + cl->doicast = 1; cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index e0c2c28..45ed379 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -55,8 +56,8 @@ static void y = ft_find_y(key, pl); if (cl->mlist.map[y][x] == 'T') { - pl->pos_x = old_x + ((old_x - x) / 4); - pl->pos_y = old_y + ((old_y - y) / 4); + pl->pos_x = old_x + ((old_x - x) / 3); + pl->pos_y = old_y + ((old_y - y) / 3); ft_suffer_animation(cl); x = ft_find_x(key, pl); y = ft_find_y(key, pl); @@ -93,8 +94,6 @@ int i++; } if (cl->key_input[0] != -1) - { ft_draw_scene(cl); - } return (0); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 2a1beb4..1a9b51a 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -21,24 +21,26 @@ void { int32_t x; int32_t y; - int8_t i; + int32_t col; + t_rgb rgb; - /* cl->red_scr.img = mlx_new_image(cl->wlist.wlx, */ - /* cl->wlist.x_size, cl->wlist.y_size); */ - /* cl->red_scr.ptr = mlx_get_data_addr(cl->red_scr.img, &cl->red_scr.bpp, */ - /* &cl->red_scr.sizeline, &cl->red_scr.endian); */ y = -1; + col = 0x00880000; while (++y < (int32_t)cl->wlist.y_size) { x = -1; while (++x < (int32_t)cl->wlist.x_size) + { + rgb = ft_hex_to_og_rgb(*(int*)(cl->img.ptr + + (x * 4 + (y * cl->img.sizeline)))); + rgb.r += 120; *(int*)(cl->img.ptr + - (x * 4 + (y * cl->img.sizeline))) = 0x00ffffff; + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); + } + /* if (y < (int32_t)cl->wlist.y_size / 2) */ + /* col += 0x00000000; */ + /* else */ + /* col -= 0x00000000; */ } - i = -1; - mlx_put_image_to_window(cl->wlist.wlx, - cl->wlist.winptr, cl->img.img, 0, 0); - sleep(5); - /* while (++i < 120) */ - /* mlx_destroy_image(cl->wlist.wlx, cl->red_scr.img); */ + cl->doicast = 0; } -- cgit v1.2.3 From 7b61072321c71c1612a7b33d2e8d722a49c5bc99 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 11 Mar 2020 18:06:17 +0100 Subject: ca tue --- src/ft_draw_scene.c | 5 --- src/ft_draw_traps.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ src/ft_draw_traps_extra.c | 44 +++++++++++++++++++ src/ft_get_player_spawn.c | 1 + src/ft_raycasting.c | 1 + src/ft_suffer_animation.c | 14 +++--- 6 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 src/ft_draw_traps.c create mode 100644 src/ft_draw_traps_extra.c (limited to 'src') diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 39cdadc..80cd1bc 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -41,10 +41,6 @@ static int8_t void ft_draw_scene(t_cub *clist) { - /* 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); */ if (clist->doicast) ft_castray(clist); else @@ -58,7 +54,6 @@ void if (clist->ishud && clist->mlist.isnlvl) if (ft_put_stage(clist) < 0) ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); - /* mlx_destroy_image(clist->wlist.wlx, clist->img.img); */ } void diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c new file mode 100644 index 0000000..42f837b --- /dev/null +++ b/src/ft_draw_traps.c @@ -0,0 +1,110 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_traps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include + +static void + ft_sort_traps_norme(float *dist_tab, int32_t it, t_cub *cl) +{ + uint32_t tmp; + + tmp = 0; + if (dist_tab[it] > dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.traps_order[it]; + cl->mlist.traps_order[it] = cl->mlist.traps_order[it + 1]; + cl->mlist.traps_order[it + 1] = tmp; + it = 0; + } +} + +void + ft_sort_traps(t_cub *cl) +{ + float dist_tab[4096]; + int32_t it; + + it = 0; + while (it < cl->mlist.sprite_nbr) + { + dist_tab[it] = ((cl->plist.pos_x - cl->traps[it].s_pos_x) * + (cl->plist.pos_x - cl->traps[it].s_pos_x) + + (cl->plist.pos_y - cl->traps[it].s_pos_y) * + (cl->plist.pos_y - cl->traps[it].s_pos_y)); + cl->mlist.traps_order[it] = it; + it++; + } + it = 0; + while (it < cl->mlist.traps_nbr) + { + ft_sort_traps_norme(dist_tab, it, cl); + } +} + +static void + ft_put_trap(t_sprite *sprite, t_cub *cl) +{ + float dist; + float calc; + + if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + dist = 0.0001; + calc = (dist * 0.1 * cl->mlist.darklvl); + calc = (calc >= 255) ? (255) : (calc); + calc = (calc < 1) ? (1) : (calc); + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = + (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = + (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y + 1] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = + (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y + 2] / calc; + cl->img.ptr[sprite->x * 4 + cl->wlist.x_size * sprite->y + 3] = (char)0; +} + +void + ft_draw_traps(t_cub *cl, t_sprite *sprite) +{ + int32_t d; + + sprite->x = sprite->drawstartx; + while (sprite->x < sprite->drawendx) + { + sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + + sprite->spritescreenx)) * cl->tlist[15].img_w / sprite->spritewidth); + sprite->y = sprite->drawstarty; + while (sprite->y < sprite->drawendy) + { + d = sprite->y * 256 - cl->wlist.y_size * 128 + + sprite->spriteheight * 128; + sprite->tex_y = ((d * cl->tlist[15].img_h / 2) / + sprite->spriteheight) / 128; + if (sprite->transformy > 0 && cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y] + && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) + { + ft_put_trap(sprite, cl); + } + sprite->y++; + } + sprite->x++; + } +} diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c new file mode 100644 index 0000000..a2fd0ab --- /dev/null +++ b/src/ft_draw_traps_extra.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_traps_extra.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include +#include + +void + ft_calc_trap(t_cub *cl) +{ + t_sprite sprite; + int32_t i; + + i = 0; + while (i < cl->mlist.traps_nbr) + { + sprite = cl->traps[i]; + sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); + sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); + sprite.invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y + - cl->plist.dir_x * cl->plist.plane_y); + sprite.transformx = sprite.invdet * (cl->plist.dir_y * sprite.spritex + - cl->plist.dir_x * sprite.spritey); + sprite.transformy = sprite.invdet * (-cl->plist.plane_y * sprite.spritex + + cl->plist.plane_x * sprite.spritey); + sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * + (1 + sprite.transformx / sprite.transformy); + ft_sprite_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_traps(cl, &sprite); + i++; + } +} diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 6853313..ef2edd9 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -83,6 +83,7 @@ void plist->start_y = plist->pos_y; ft_get_start_side(clist->mlist.map[y][x], plist); ft_get_sprite_spawn(clist); + ft_get_trap_spawn(clist); return ; } x++; diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 2d6d197..a0720ea 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -106,6 +106,7 @@ void } ft_floor_cast(cl); ft_calc_sprite(cl); + ft_calc_trap(cl); ft_memdel((void**)&cl->rlist.wall_dist_tab); ft_memdel((void**)&cl->rlist.wall_bz); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 1a9b51a..b800a39 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -21,11 +21,9 @@ void { int32_t x; int32_t y; - int32_t col; t_rgb rgb; y = -1; - col = 0x00880000; while (++y < (int32_t)cl->wlist.y_size) { x = -1; @@ -33,14 +31,16 @@ void { rgb = ft_hex_to_og_rgb(*(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline)))); - rgb.r += 120; + rgb.r += 150; + rgb.g += 20; + rgb.b += 20; *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); } - /* if (y < (int32_t)cl->wlist.y_size / 2) */ - /* col += 0x00000000; */ - /* else */ - /* col -= 0x00000000; */ } + cl->plist.life -= 20; + if (cl->plist.life <= 0) + ft_exit(0, cl); + /* TODO death screen here */ cl->doicast = 0; } -- cgit v1.2.3