diff options
author | salaaad2 <arthudurant263@gmail.com> | 2020-03-10 16:16:08 +0100 |
---|---|---|
committer | salaaad2 <arthudurant263@gmail.com> | 2020-03-10 16:16:08 +0100 |
commit | 0d589d0038624e3123e6166f6521d1421dd69b23 (patch) | |
tree | 26db0ad344a9c730192eea0bff01bb410ba225b7 /src | |
parent | still retard (diff) | |
parent | ok now (diff) | |
download | 42-cub3d-0d589d0038624e3123e6166f6521d1421dd69b23.tar.gz 42-cub3d-0d589d0038624e3123e6166f6521d1421dd69b23.tar.bz2 42-cub3d-0d589d0038624e3123e6166f6521d1421dd69b23.tar.xz 42-cub3d-0d589d0038624e3123e6166f6521d1421dd69b23.tar.zst 42-cub3d-0d589d0038624e3123e6166f6521d1421dd69b23.zip |
merge master
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_scene.c | 2 | ||||
-rw-r--r-- | src/ft_draw_skybox.c | 38 | ||||
-rw-r--r-- | src/ft_exit.c | 1 | ||||
-rw-r--r-- | src/ft_floor_cast.c | 17 | ||||
-rw-r--r-- | src/ft_get_skybox.c | 43 | ||||
-rw-r--r-- | src/ft_init_funptr.c | 4 | ||||
-rw-r--r-- | src/ft_init_lists.c | 2 | ||||
-rw-r--r-- | src/ft_init_map.c | 2 | ||||
-rw-r--r-- | src/ft_select_get.c | 2 | ||||
-rw-r--r-- | src/ft_tex_init.c | 7 | ||||
-rw-r--r-- | src/ft_warp_level.c | 3 |
11 files changed, 113 insertions, 8 deletions
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 68a72e9..2cfa3f4 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -50,6 +50,8 @@ void { ft_draw_hud(clist); } + 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); diff --git a/src/ft_draw_skybox.c b/src/ft_draw_skybox.c new file mode 100644 index 0000000..a446485 --- /dev/null +++ b/src/ft_draw_skybox.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_skybox.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:22:57 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <mlx.h> + +void + ft_draw_skybox(t_cub *cl) +{ + int offset; + + offset = 640; + if (cl->plist.dir_x > 0) + offset = -offset; + mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, + cl->tlist[7].img, offset * cl->plist.dir_y, -125); + mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, + cl->tlist[7].img, offset * cl->plist.dir_y, -125); + mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, + cl->tlist[7].img, offset * cl->plist.dir_y, -125); + mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, + cl->tlist[7].img, offset * cl->plist.dir_y, -125); + mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, + cl->tlist[7].img, offset * cl->plist.dir_y, -125); + mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, + cl->tlist[7].img, offset * cl->plist.dir_y, -125); + mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, + cl->tlist[7].img, offset * cl->plist.dir_y, -125); +} diff --git a/src/ft_exit.c b/src/ft_exit.c index 659d0ec..97c9e02 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -32,6 +32,7 @@ static void ft_memdel((void**)&clist->mlist.fl_tex_path); 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.music_path); ft_memdel((void**)&clist->mlist.music_cmd); ft_memdel((void**)&clist->mlist.mapl); diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 6111eca..384f699 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -16,8 +16,16 @@ 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); + if (cl->mlist.darklvl > 0) + { + *(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 @@ -31,6 +39,7 @@ static void calc = (dist * 0.1 * cl->mlist.darklvl); calc = (calc >= 255) ? (255) : (calc); calc = (calc < 1) ? (1) : (calc); + calc = (cl->mlist.darklvl > 0) ? (calc) : (1); cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc; @@ -75,9 +84,9 @@ static void ft_draw_extra_tex(6, y, x, cl); else ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); - if (cl->mlist.isctex) + if (cl->mlist.isctex && !cl->mlist.isskybox) ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl); - else + else if (!cl->mlist.isctex && !cl->mlist.isskybox) ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); } diff --git a/src/ft_get_skybox.c b/src/ft_get_skybox.c new file mode 100644 index 0000000..47c395e --- /dev/null +++ b/src/ft_get_skybox.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_skybox.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 <cub3d.h> +#include <stdint.h> + +int8_t + ft_get_skybox(char **words, t_cub *clist) +{ + if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_sprintf(clist->errmsg, FT_ERR_ARGS); + return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_sprintf(clist->errmsg, FT_ERR_NOT_A_XPM); + return (-1); + } + ft_memdel((void**)&clist->mlist.skybox_path); + if (!(clist->mlist.skybox_path = ft_strdup(*(words + 1)))) + { + ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); + return (-1); + } + if (ft_check_not_found(clist->mlist.skybox_path) < 0) + { + ft_sprintf(clist->errmsg, FT_ERR_RD_SB); + return (-1); + } + clist->mlist.isskybox = 1; + return (0); +} diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c index f95e020..6bfa3f7 100644 --- a/src/ft_init_funptr.c +++ b/src/ft_init_funptr.c @@ -28,7 +28,8 @@ void ft_sprintf(clist->ref[9], "LT"); ft_sprintf(clist->ref[10], "MU"); ft_sprintf(clist->ref[11], "SH"); - ft_bzero(clist->ref[12], 3); + ft_sprintf(clist->ref[12], "SB"); + ft_bzero(clist->ref[13], 3); } void @@ -52,4 +53,5 @@ void clist->get_ptr[9] = ft_get_tex_nl; clist->get_ptr[10] = ft_get_music; clist->get_ptr[11] = ft_get_darkness; + clist->get_ptr[12] = ft_get_skybox; } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index d27df52..bd2ae74 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -42,7 +42,7 @@ static t_player plist.dir_x = -1; plist.dir_y = 0; plist.plane_x = 0; - plist.plane_y = 0.80; + plist.plane_y = 0.66; return (plist); } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 68a3b6d..27b4a39 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -28,6 +28,7 @@ static int8_t !(mlist->fl_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(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->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))) || @@ -58,6 +59,7 @@ int8_t mlist->isctex = 0; mlist->isnlvl = 0; mlist->ismusic = 0; + mlist->isskybox = 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 c246d25..fe6bb3e 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 == 12) + if (ret == 13) ret = FT_PARSE_END_RET; ret = ft_check_exists(ret, clist); ret = ft_check_exists_two(ret, clist); diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 9daa20d..6c9edce 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -66,6 +66,13 @@ static void 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->walltexgood = 1; } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index de2103d..4a02c2b 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -33,6 +33,7 @@ static void ft_memdel((void**)&ml->fl_tex_path); ft_memdel((void**)&ml->ce_tex_path); ft_memdel((void**)&ml->nlevel_path); + ft_memdel((void**)&ml->skybox_path); ft_memdel((void**)&ml->music_path); ft_memdel((void**)&ml->music_cmd); ft_memdel((void**)&ml->mapl); @@ -54,7 +55,7 @@ static void cl->plist.dir_x = -1; cl->plist.dir_y = 0; cl->plist.plane_x = 0; - cl->plist.plane_y = 0.66666666; + cl->plist.plane_y = 0.66; cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); |