aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_sprite.c
blob: 28ffb10f93c3bd5dab5167b67836b55ff3fed9c5 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   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)
{
	int d;
	int tex_x;
	int tex_y;

	cl->sprites.x = cl->sprites.s_start_x;
	while (cl->sprites.x < cl->sprites.s_end_x)
	{
		tex_x = (int)((cl->sprites.x - (-cl->sprites.s_w / 2 + cl->sprites.s_screen_x))
				* cl->tlist[4].img_w / cl->sprites.s_w);
		cl->sprites.y = cl->sprites.s_start_y;
		while (cl->sprites.y < cl->sprites.s_end_y)
		{
			d = cl->sprites.y * 256 - cl->wlist->y_size * 128 + cl->sprites.s_h * 128;
			tex_y = ((d * cl->tlist[4].img_h) / cl->sprites.s_h) / 256;
			if (*(cl->tlist[4].ptr + tex_x + tex_y * cl->tlist[4].sizeline / 4))
			{
				cl->img.ptr[tex_x * 4 + (cl->img.sizeline * tex_y)] =
					(char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 *
					cl->tlist[4].img_h * tex_y];
				/*puts("qwe");*/
			}
			cl->sprites.y++;
		}
		cl->sprites.x++;
	}
}