-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_map.c
116 lines (106 loc) · 2.74 KB
/
draw_map.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahajji <ahajji@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 12:21:24 by ahajji #+# #+# */
/* Updated: 2023/11/30 15:13:25 by ahajji ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void draw_rectangle(int x, int y, t_cub3d *data, uint32_t color)
{
int i;
int j;
i = x;
j = y;
while (y < data->size_shape + j)
{
x = i;
while (x < data->size_shape + i)
{
mlx_put_pixel(data->img_map, x, y, color);
x++;
}
y++;
}
}
void draw_map_2(t_cub3d *data, int mode, int i, int j)
{
if (data->map[j][i] == '1')
draw_rectangle(i * data->size_shape, j * data->size_shape, data,
0xFFFFFFFF);
if (data->map[j][i] == '0' || (mode == 0 && data->map[j][i] == 'P'))
draw_rectangle(i * data->size_shape, j * data->size_shape, data,
0x000000FF);
if (data->map[j][i] == ' ')
draw_rectangle(i * data->size_shape, j * data->size_shape, data,
0xFF000033);
if (data->map[j][i] == 'P' && mode)
{
draw_rectangle(i * data->size_shape, j * data->size_shape, data,
0x000000FF);
mlx_put_pixel(data->img, data->px = (i * data->size_shape)
+ (data->size_shape / 2),
data->py = (j * data->size_shape)
+ (data->size_shape / 2), 0xFF0000FF);
}
}
void draw_map(t_cub3d *data, int mode)
{
int i;
int j;
i = 0;
j = 0;
while (j < data->height_map)
{
i = 0;
while (i < data->width_map)
{
draw_map_2(data, mode, i, j);
i++;
}
j++;
}
}
void draw_view_angle(t_cub3d *data)
{
int i;
float ray_angle;
int id_ray;
i = 0;
ray_angle = data->angle - (VIEW_ANGLE / 2);
if (ray_angle < 0)
ray_angle = 360 + ray_angle;
id_ray = 0;
while (i < data->number_rays)
{
if (ray_angle >= 360)
ray_angle -= 360;
check_ray_draw(data, ray_angle, id_ray);
id_ray++;
ray_angle += (VIEW_ANGLE / data->number_rays);
i++;
}
}
void draw_ceil_floor(t_cub3d *data)
{
int i;
int j;
j = 0;
while (j < HEIGHT_WIN)
{
i = 0;
while (i < WIDTH_WIN)
{
if (j < HEIGHT_WIN / 2)
mlx_put_pixel(data->img, i, j, data->textures.sky_hex);
else
mlx_put_pixel(data->img, i, j, data->textures.floor_hex);
i++;
}
j++;
}
}