diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-18 21:35:54 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-18 21:35:54 +0100 |
commit | d114d2571a3808eba1f0a5038ad862b790a96074 (patch) | |
tree | 8d2d4c19a2a8de61a253dc0a4fc2434a770470a6 /src | |
parent | Merge branch 'better_sprites' (diff) | |
download | 42-cub3d-d114d2571a3808eba1f0a5038ad862b790a96074.tar.gz 42-cub3d-d114d2571a3808eba1f0a5038ad862b790a96074.tar.bz2 42-cub3d-d114d2571a3808eba1f0a5038ad862b790a96074.tar.xz 42-cub3d-d114d2571a3808eba1f0a5038ad862b790a96074.tar.zst 42-cub3d-d114d2571a3808eba1f0a5038ad862b790a96074.zip |
In progress
Diffstat (limited to '')
-rw-r--r-- | src/ft_check_map_line.c | 4 | ||||
-rw-r--r-- | src/ft_check_missing.c | 3 | ||||
-rw-r--r-- | src/ft_draw_heals.c | 110 | ||||
-rw-r--r-- | src/ft_draw_heals_extra.c | 43 | ||||
-rw-r--r-- | src/ft_exit.c | 2 | ||||
-rw-r--r-- | src/ft_get_heal_spawn.c | 45 | ||||
-rw-r--r-- | src/ft_get_player_spawn.c | 1 | ||||
-rw-r--r-- | src/ft_get_traps.c | 4 | ||||
-rw-r--r-- | src/ft_init_map.c | 2 | ||||
-rw-r--r-- | src/ft_raycasting.c | 1 | ||||
-rw-r--r-- | src/ft_tex_init.c | 10 | ||||
-rw-r--r-- | src/ft_warp_level.c | 4 |
12 files changed, 224 insertions, 5 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index b9fd636..79e0297 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -37,8 +37,8 @@ static int8_t ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL); return (-1); } - if (line[i] == 'T') - clist->mlist.istraps = 1; + clist->mlist.istraps = (line[i] == 'T') ? (1) : (0); + clist->mlist.isheals = (line[i] == '+') ? (1) : (0); ft_get_topsp(line[i], clist); return (0); } diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index 4d06276..6bf41ab 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -59,6 +59,9 @@ static int if (ft_check_not_found(FT_HUD_BACK_PATH) < 0 || ft_check_ext(FT_HUD_BACK_PATH, ".xpm") < 0) return (ft_missing_error(FT_ERR_MISS_HUD_BACK, clist)); + if (ft_check_not_found(FT_HEAL_PACK_PATH) < 0 || + ft_check_ext(FT_HEAL_PACK_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_HEAL_PACK, clist)); return (ft_check_missing_sprites(clist)); } diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c new file mode 100644 index 0000000..8e2c842 --- /dev/null +++ b/src/ft_draw_heals.c @@ -0,0 +1,110 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +static void + ft_sort_heals_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.heals_order[it]; + cl->mlist.heals_order[it] = cl->mlist.heals_order[it + 1]; + cl->mlist.heals_order[it + 1] = tmp; + it = 0; + } +} + +void + ft_sort_heals(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->heals[it].s_pos_x) * + (cl->plist.pos_x - cl->heals[it].s_pos_x) + + (cl->plist.pos_y - cl->heals[it].s_pos_y) * + (cl->plist.pos_y - cl->heals[it].s_pos_y)); + cl->mlist.heals_order[it] = it; + it++; + } + it = 0; + while (it < cl->mlist.heals_nbr) + { + ft_sort_heals_norme(dist_tab, it, cl); + } +} + +static void + ft_put_heal(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[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 1] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = + (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y + 2] / calc; +} + +void + ft_draw_heals(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[17].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[17].img_h / 2) / + sprite->spriteheight) / 128; + ft_printf("isheals %d\n", cl->mlist.isheals); + if (sprite->transformy > 0 + && cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y] + && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) + ft_put_heal(sprite, cl); + sprite->y++; + } + sprite->x++; + } +} diff --git a/src/ft_draw_heals_extra.c b/src/ft_draw_heals_extra.c new file mode 100644 index 0000000..05ff830 --- /dev/null +++ b/src/ft_draw_heals_extra.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals_extra.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +void + ft_calc_heal(t_cub *cl) +{ + t_sprite sprite; + int32_t i; + + i = 0; + while (i < cl->mlist.traps_nbr) + { + sprite = cl->heals[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_h_w(cl, &sprite); + ft_draw_heals(cl, &sprite); + i++; + } +} diff --git a/src/ft_exit.c b/src/ft_exit.c index 78b6d0a..390f234 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -86,6 +86,8 @@ static void mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img); if (clist->tlist[16].img) mlx_destroy_image(clist->wlist.wlx, clist->tlist[16].img); + if (clist->mlist.isheals && clist->tlist[17].img) + mlx_destroy_image(clist->wlist.wlx, clist->tlist[17].img); ft_del_extra_sprites(clist); } diff --git a/src/ft_get_heal_spawn.c b/src/ft_get_heal_spawn.c new file mode 100644 index 0000000..142709b --- /dev/null +++ b/src/ft_get_heal_spawn.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_traps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 18:24:52 by rbousset #+# #+# */ +/* Updated: 2020/02/28 18:24:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +void + ft_get_heal_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] == '+') + { + clist->mlist.heals_nbr++; + if (clist->mlist.heals_nbr > 64) + ft_map_error(FT_ERR_TOO_MUCH_HEALS, clist); + clist->heals[i].s_pos_x = x; + clist->heals[i].s_pos_y = y; + i++; + } + x++; + } + x = 1; + y++; + } +} diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index ef2edd9..1ba6437 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -84,6 +84,7 @@ void ft_get_start_side(clist->mlist.map[y][x], plist); ft_get_sprite_spawn(clist); ft_get_trap_spawn(clist); + ft_get_heal_spawn(clist); return ; } x++; diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c index b7d12e1..2d652f8 100644 --- a/src/ft_get_traps.c +++ b/src/ft_get_traps.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_get_tex_nl.c :+: :+: :+: */ +/* ft_get_traps.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -31,6 +31,8 @@ void if (clist->mlist.map[y][x] == 'T') { clist->mlist.traps_nbr++; + if (clist->mlist.traps_nbr > 512) + ft_map_error(FT_ERR_TOO_MUCH_TRAPS, clist); clist->traps[i].s_pos_x = x; clist->traps[i].s_pos_y = y; i++; diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 8b97906..d610fac 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -89,8 +89,10 @@ int8_t mlist->ismusic = 0; mlist->isskybox = 0; mlist->istraps = 0; + mlist->isheals = 0; mlist->sprite_nbr = 0; mlist->traps_nbr = 0; + mlist->heals_nbr = 0; mlist->darklvl = 0; return (ft_init_map_norme(mlist)); } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index aa050c5..d805cdf 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -107,6 +107,7 @@ void ft_floor_cast(cl); ft_calc_sprite(cl); ft_calc_trap(cl); + ft_calc_heal(cl); ft_memdel((void*)&cl->rlist.wall_dist_tab); ft_memdel((void*)&cl->rlist.wall_bz); } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index fe8aadd..6486e87 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -36,6 +36,7 @@ ** 14 : sprite 9 ** 15 : trap ** 16 : HUD back +** 17 : heal pack */ static void @@ -79,9 +80,7 @@ static void &cl->tlist[16].bpp, &cl->tlist[16].sizeline, &cl->tlist[16].endian); cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) - { ft_next_sprite_init(cl); - } } static void @@ -108,6 +107,13 @@ 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); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index fadbb2a..a2b6006 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -61,6 +61,10 @@ static void 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); + if (cl->tlist[16].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[16].img); + if (cl->mlist.isheals && cl->tlist[17].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[17].img); ft_del_extra_sprites(cl); i = -1; while (++i < 8) |