2022-12-22 11:41:31 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* draw.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
|
2023-01-16 12:38:47 -05:00
|
|
|
/* Updated: 2023/01/16 15:38:37 by cchauvet ### ########.fr */
|
2022-12-22 11:41:31 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "solong.h"
|
|
|
|
|
2023-01-13 09:10:27 -05:00
|
|
|
void ft_draw_img(t_data *data, void *img, size_t x, size_t y)
|
2022-12-22 11:41:31 -05:00
|
|
|
{
|
2023-01-11 13:10:28 -05:00
|
|
|
if (img != NULL)
|
|
|
|
mlx_put_image_to_window(data->mlx, data->window, img, x, y);
|
2022-12-22 11:41:31 -05:00
|
|
|
}
|
2023-01-06 13:37:36 -05:00
|
|
|
|
2023-01-13 10:10:11 -05:00
|
|
|
static void *ft_char2img(t_data *data, char c)
|
2023-01-08 12:03:40 -05:00
|
|
|
{
|
|
|
|
if (c == 'C')
|
2023-01-16 12:38:47 -05:00
|
|
|
return (data->assets[0]);
|
2023-01-08 12:03:40 -05:00
|
|
|
if (c == '1')
|
2023-01-16 12:38:47 -05:00
|
|
|
return (data->assets[1]);
|
2023-01-08 12:03:40 -05:00
|
|
|
if (c == 'E')
|
2023-01-16 12:38:47 -05:00
|
|
|
return (data->assets[2]);
|
2023-01-08 12:03:40 -05:00
|
|
|
if (c == 'P')
|
2023-01-16 12:38:47 -05:00
|
|
|
return (data->assets[3]);
|
2023-01-08 12:03:40 -05:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2023-01-09 14:41:06 -05:00
|
|
|
int ft_draw_map(t_data *data)
|
2023-01-06 13:37:36 -05:00
|
|
|
{
|
2023-01-10 13:04:46 -05:00
|
|
|
ssize_t tab[2];
|
2023-01-08 12:03:40 -05:00
|
|
|
char **patern;
|
2023-01-11 13:10:28 -05:00
|
|
|
void *img;
|
2023-01-06 13:37:36 -05:00
|
|
|
|
2023-01-13 09:14:11 -05:00
|
|
|
ft_fill_pos(data->map);
|
2023-01-09 14:41:06 -05:00
|
|
|
patern = ft_get_player_map(*data->map);
|
2023-01-08 12:03:40 -05:00
|
|
|
if (patern == NULL)
|
|
|
|
return (1);
|
2023-01-16 12:38:47 -05:00
|
|
|
ft_draw_img(data, data->assets[NB_COLORS], 0, 0);
|
2023-01-10 13:04:46 -05:00
|
|
|
tab[1] = -1;
|
|
|
|
while (patern[++tab[1]] != NULL)
|
2023-01-06 13:37:36 -05:00
|
|
|
{
|
2023-01-10 13:04:46 -05:00
|
|
|
tab[0] = -1;
|
|
|
|
while (patern[tab[1]][++tab[0]] != '\0')
|
2023-01-08 12:03:40 -05:00
|
|
|
{
|
2023-01-11 13:10:28 -05:00
|
|
|
img = ft_char2img(data, patern[tab[1]][tab[0]]);
|
|
|
|
if (img != NULL)
|
|
|
|
ft_draw_img(data, img, tab[0] * CASE_SIZE, tab[1] * CASE_SIZE);
|
2023-01-08 12:03:40 -05:00
|
|
|
}
|
2023-01-06 13:37:36 -05:00
|
|
|
}
|
2023-01-09 14:41:06 -05:00
|
|
|
ft_freer_tab_ultimate(1, patern);
|
2023-01-08 12:03:40 -05:00
|
|
|
return (0);
|
2023-01-06 13:37:36 -05:00
|
|
|
}
|