63 lines
2.1 KiB
C
63 lines
2.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* draw.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/12/13 15:49:23 by cchauvet #+# #+# */
|
|
/* Updated: 2023/01/11 18:48:44 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "solong.h"
|
|
|
|
static void ft_draw_img(t_data *data, void *img, size_t x, size_t y)
|
|
{
|
|
if (img != NULL)
|
|
mlx_put_image_to_window(data->mlx, data->window, img, x, y);
|
|
}
|
|
|
|
static void *ft_char2img(t_data *data, char c)
|
|
{
|
|
if (c == 'C')
|
|
return (data->assets[data->nb_swaps + 1 % NB_COLORS]);
|
|
if (c == '1')
|
|
return (data->assets[data->nb_swaps + 2 % NB_COLORS]);
|
|
if (c == 'E')
|
|
return (data->assets[data->nb_swaps + 3 % NB_COLORS]);
|
|
if (c == 'P')
|
|
return (data->assets[data->nb_swaps + 4 % NB_COLORS]);
|
|
if (c == 'B')
|
|
return (data->assets[data->nb_swaps + 5 % NB_COLORS]);
|
|
return (NULL);
|
|
}
|
|
|
|
int ft_draw_map(t_data *data)
|
|
{
|
|
ssize_t tab[2];
|
|
char **patern;
|
|
void *img;
|
|
|
|
ft_fill_pos(data);
|
|
data->nb_swaps = data->nb_swaps++ % (NB_COLORS - 6);
|
|
patern = ft_get_player_map(*data->map);
|
|
if (patern == NULL)
|
|
return (1);
|
|
ft_draw_img(data, data->assets[data->nb_swaps + NB_COLORS], 0, 0);
|
|
tab[1] = -1;
|
|
while (patern[++tab[1]] != NULL)
|
|
{
|
|
tab[0] = -1;
|
|
while (patern[tab[1]][++tab[0]] != '\0')
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
ft_freer_tab_ultimate(1, patern);
|
|
data->nb_swaps++;
|
|
return (0);
|
|
}
|