42_solong/draw.c
Camille Chauvet 195f7bc66a ca marche
2023-01-09 20:41:06 +01:00

70 lines
1.9 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
/* Updated: 2023/01/09 20:13:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "solong.h"
static void ft_draw_xpm(t_data *data, char *img_path, size_t x, size_t y)
{
int bozo;
void *img;
bozo = CASE_SIZE;
img = mlx_xpm_file_to_image(data->mlx, img_path, &bozo, &bozo);
if (img == NULL)
return ;
mlx_put_image_to_window(data->mlx, data->window, img, x, y);
mlx_destroy_image(data->mlx, img);
}
static char *ft_char2xpm(t_data data, char c)
{
if (c == 'C')
return (data.ccolor);
if (c == '1')
return (data.wcolor);
if (c == 'E')
return (data.ecolor);
if (c == 'P')
return (data.pcolor);
return (NULL);
}
int ft_draw_map(t_data *data)
{
size_t x;
size_t y;
char **patern;
char *path;
ft_fill_pos(data);
ft_color_changer(data);
patern = ft_get_player_map(*data->map);
if (patern == NULL)
return (1);
ft_draw_xpm(data, data->bcolor, 0, 0);
y = 0;
while (patern[y] != NULL)
{
x = 0;
while (patern[y][x] != '\0')
{
path = ft_char2xpm(*data, patern[y][x]);
if (path != NULL)
ft_draw_xpm(data, path, x * CASE_SIZE, y * CASE_SIZE);
x++;
}
y++;
}
ft_freer_tab_ultimate(1, patern);
return (0);
}