-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimap.c
94 lines (84 loc) · 2.34 KB
/
minimap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minimap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: phelebra <xhelp00@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/14 16:46:15 by phelebra #+# #+# */
/* Updated: 2023/10/09 15:26:56 by phelebra ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void draw_minimap(t_box *box)
{
draw_map(box);
draw_player(box);
draw_rays(box);
}
void draw_map(t_box *box)
{
t_rect rect;
int i;
int j;
char grid_item;
i = -1;
while (++i < box->map_height)
{
j = -1;
while (++j < box->map_width)
{
grid_item = box->map[i][j];
rect.x = (j * 10) + SCREENWIDTH - (box->map_width * 10) - 10;
rect.y = (i * 10) + 10;
rect.width = 10;
rect.height = 10;
rect.border_color = 0x0014213d;
rect.border_width = 0;
rect.fill_color = get_fill_color(grid_item, box, i, j);
draw_rect(&rect, box);
}
}
}
void draw_player(t_box *box)
{
t_rect rect;
rect.height = 10;
rect.width = 10;
rect.x = (box->info.pos_y * 10) + SCREENWIDTH - (box->map_width * 10) - 15;
rect.y = (box->info.pos_x * 10) + 5;
rect.fill_color = 0x00e63946;
draw_rect(&rect, box);
}
int get_fill_color(char grid_item, t_box *box, int i, int j)
{
int color;
if (grid_item == '0')
color = 0x00757575;
else if (grid_item == '3')
{
if (find_door(box, i, j)->data->state)
color = 0x00939D;
else
color = 0x00666d;
}
else
color = 0x0014213d;
return (color);
}
void draw_rays(t_box *box)
{
int i;
t_line line;
i = -1;
while (++i < SCREENWIDTH)
{
line.begin_x = (box->info.pos_y * 10)
+ SCREENWIDTH - (box->map_width * 10) - 10 ;
line.begin_y = (box->info.pos_x * 10) + 10 ;
line.end_x = box->info.ray[i].end_x;
line.end_y = box->info.ray[i].end_y;
line.color = 0x00e63946;
draw_line(&line, box);
}
}