blob: 0430e2f26d63e6e4ad0ff4d51cf9641c6148ff87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_draw_sprite.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */
/* Updated: 2020/02/24 20:22:47 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
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])
{
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++;
}
}
|