-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.c
98 lines (91 loc) · 2.73 KB
/
functions.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybouddou <ybouddou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/16 12:52:06 by ybouddou #+# #+# */
/* Updated: 2020/12/04 09:17:27 by ybouddou ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int key_close(t_cub3d *cub)
{
mlx_clear_window(cub->mlx.p, cub->mlx.w);
ft_putstr_fd("END OF GAME!\n", 2);
exit(0);
return (0);
}
void if_sprite(t_cub3d *cub)
{
cub->parse.line = NULL;
if (cub->sprite_num)
{
cub->sprite_buf = (double *)malloc((cub->res.w + 1) * sizeof(double));
cub->sprite = malloc((cub->sprite_num + 1) * sizeof(t_sprite));
}
}
void free_path(t_cub3d *cub)
{
free(cub->path.no);
free(cub->path.so);
free(cub->path.ea);
free(cub->path.we);
free(cub->path.s);
cub->path.s = NULL;
cub->path.no = NULL;
cub->path.so = NULL;
cub->path.ea = NULL;
cub->path.we = NULL;
}
void wallrendering(t_cub3d *cub)
{
cub->tex_y = (int)cub->texpos;
cub->texpos += cub->step;
if (cub->side == 0)
cub->color = cub->txt[2].img_data[cub->tex_x + cub->tex_y *
cub->txt[2].w];
else if (cub->side == 1)
cub->color = cub->txt[3].img_data[cub->tex_x + cub->tex_y *
cub->txt[3].w];
else if (cub->side == 2)
cub->color = cub->txt[0].img_data[cub->tex_x + cub->tex_y *
cub->txt[0].w];
else if (cub->side == 3)
cub->color = cub->txt[1].img_data[cub->tex_x + cub->tex_y *
cub->txt[1].w];
cub->img.img_data[cub->img.h * cub->res.w + cub->ray] = cub->color;
if (cub->ac == 3)
{
cub->image[(cub->ray + (cub->drawend - cub->bmp_pos) * cub->res.w)
* 3 + 2] = cub->color >> 16;
cub->image[(cub->ray + (cub->drawend - cub->bmp_pos) * cub->res.w)
* 3 + 1] = cub->color >> 8;
cub->image[(cub->ray + (cub->drawend - cub->bmp_pos) * cub->res.w)
* 3 + 0] = cub->color;
cub->bmp_pos++;
}
}
void spritesort(t_cub3d *cub)
{
t_sprite tmp;
int i;
int j;
i = 0;
while (i < cub->sprite_num - 1)
{
j = 0;
while (j < cub->sprite_num - i - 1)
{
if (cub->sprite[j].dist < cub->sprite[j + 1].dist)
{
tmp = cub->sprite[j];
cub->sprite[j] = cub->sprite[j + 1];
cub->sprite[j + 1] = tmp;
}
j++;
}
i++;
}
}