미니맵 그리는 방법
- 픽셀에 하나하나 찍으면 되는 듯
- 찍는 위치는 다음과 같다.
- 그려주는 함수 안에 넣는게 가장 좋을 듯.
python
drawing():
while ():
raycast_vector_init()
raycast_sidedist_init()
raycast_shoot_light()
raycast_darw_line()
mlx_clear_window()
set_minimap()
mlx_put_image_to_window()
mlx_destory_image()
미니맵 디테일
2차원 배열로 된 맵을 돌면서 각 원소의 값에 따라서 색을 다르게 지정해주면 된다.
캐릭터의 위치를 minimap_fill에 알려주면 캐릭터의 위치를 미니맵 안에 보여줄 수 있다.
c
void ft_set_minimap(t_box *tools, t_data *image)
{
t_vec_i map;
t_vec_i pos;
t_vec_i total;
total.y = (int)tools->map_height;
total.x = (int)tools->map_width;
map.y = 0;
while (map.y < total.y)
{
map.x = 0;
while (map.x < total.x)
{
if (tools->arr_map[map.y][map.x] == 1)
minimap_fill(map, total, image, 0x000000);
else if (tools->arr_map[map.y][map.x] == -1)
minimap_fill(map, total, image, 0xA0A0A0);
else
minimap_fill(map, total, image, 0xFFFFFF);
(map.x)++;
}
(map.y)++;
}
pos.x = (int)tools->pos.x;
pos.y = (int)tools->pos.y;
minimap_fill(pos, total, image, 0xff0000);
}
색을 채우는 minimap_fill 함수의 경우 다음과 같이 만들면 된다.
c
void minimap_fill(t_vec_i map, t_vec_i total, t_data *image, int color)
{
int minimap_size;
int rec_size;
int map_col;
int i;
int j;
map_col = total.y;
minimap_size = HEIGHT / 8;
rec_size = minimap_size / map_col;
map.x *= rec_size;
map.y *= rec_size;
i = 0;
while (i < rec_size && (map.x + i < HEIGHT))
{
j = 0;
while (j < rec_size && (map.y + j < WIDTH))
{
my_mlx_pixel_put(image, map.x + i, map.y + j, color);
j++;
}
i++;
}
}