so_long/games/position.c

45 lines
540 B
C

#include "../so_long.h"
t_xy *get_position(char **map, char c)
{
int y;
t_xy *xy;
y = 0;
xy = NULL;
while (map[y])
{
if (ft_strchr_gnl(map[y], c) != -1)
{
xy = ft_calloc(1, sizeof(t_xy));
xy->x = ft_strchr_gnl(map[y], c);
xy->y = y;
break;
}
y++;
}
return (xy);
}
int has_element(char **map, char c)
{
t_xy *xy;
xy = get_position(map, c);
if (xy == NULL)
{
free(xy);
return (0);
}
else
{
free(xy);
return (1);
}
}
char get_element(t_data *data, t_xy xy)
{
return (data->map[xy.y][xy.x]);
}