diff options
Diffstat (limited to 'src/ft_draw_weapons.c')
-rw-r--r-- | src/ft_draw_weapons.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/ft_draw_weapons.c b/src/ft_draw_weapons.c index 2e1ec13..c527987 100644 --- a/src/ft_draw_weapons.c +++ b/src/ft_draw_weapons.c @@ -12,6 +12,7 @@ #include <cub3d.h> #include <stdint.h> +#include <math.h> static void ft_sort_weapons_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) @@ -65,22 +66,19 @@ static void ft_put_weapon(t_sprite *sprite, t_cub *cl) { float dist; - float calc; + t_rgb rgb; - if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) + + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 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[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc; - cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = - (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc; + rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2]; + rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1]; + rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x + * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]; + *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + + (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } void |