62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* position.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/12/29 18:06:59 by erey-bet #+# #+# */
|
|
/* Updated: 2022/12/29 18:07:01 by erey-bet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#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]);
|
|
}
|
|
|
|
void set_element(t_data *data, int x, int y, char element)
|
|
{
|
|
data->map[y][x] = element;
|
|
}
|