/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_draw_sprite.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ /* Updated: 2020/02/24 20:22:47 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include #include #include void ft_draw_sprite(t_cub *cl, t_sprite *sprite) { int32_t d; printf("start x : %d\nstart y : %d\nend x : %d\nend y : %d\n", sprite->drawstartx, sprite->drawstarty, sprite->drawendy, sprite->drawendy); sprite->x = sprite->drawstartx; while (sprite->x < sprite->drawendx) { sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + sprite->spritescreenx)) * cl->tlist[4].img_w / sprite->spritewidth); sprite->y = sprite->drawstarty; if (sprite->transformy > 0 && sprite->x >= 0 && sprite->x < (int32_t)cl->wlist->x_size) while (sprite->y < sprite->drawendy) { d = sprite->y * 256 - cl->wlist->y_size * 128 + sprite->spriteheight * 128; sprite->tex_y = ((d * cl->tlist[4].img_h / 2) / sprite->spriteheight) / 128; if (cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y] != (char)0) { cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y]; cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y + 1]; cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y + 2]; } sprite->y++; } sprite->x++; } }