From d114d2571a3808eba1f0a5038ad862b790a96074 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 21:35:54 +0100 Subject: In progress --- src/ft_draw_heals.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/ft_draw_heals.c (limited to 'src/ft_draw_heals.c') 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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_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++; + } +} -- cgit v1.2.3 From 8998478510fba3fd77bdc19a0b503643362d332c Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 18 Mar 2020 21:38:00 +0100 Subject: Works fine --- src/ft_draw_heals.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ft_draw_heals.c') diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c index 8e2c842..d51ae97 100644 --- a/src/ft_draw_heals.c +++ b/src/ft_draw_heals.c @@ -97,7 +97,6 @@ void 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] -- cgit v1.2.3