/* ************************************************************************** */ /* */ /* :::::::: */ /* map.c :+: :+: */ /* +:+ */ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */ /* Updated: 2023/10/29 15:23:13 by houtworm ######## odam.nl */ /* */ /* ************************************************************************** */ #include "../cub3d.h" #include char ft_setplayerpos(t_varlist *vl, char dir, int y, int x) { vl->posx = x; vl->posy = y; if (dir == 'N') { vl->dirx = -1; vl->diry = 0; vl->planex = 0; vl->planey = 0.66; } else if (dir == 'E') { vl->dirx = 0; vl->diry = 1; vl->planex = 0.66; vl->planey = 0; } else if (dir == 'S') { vl->dirx = 1; vl->diry = 0; vl->planex = 0; vl->planey = -0.66; } else if (dir == 'W') { vl->dirx = 0; vl->diry = -1; vl->planex = -0.66; vl->planey = 0; } return ('0'); } char **ft_getmap(t_varlist *vl, int fd) { int y; int x; int ret; char **map; char *line; map = ft_calloc(512, 8); y = 0; ret = 1; while (y <= 512 && ret > 0) { if (y > 500) return (NULL); map[y] = ft_calloc(512, 8); while (ret > 0) { ret = get_next_line(fd, &line); if (line[0]) break ; } if (ret == 0) { free(map[y]); free(line); return (map); } x = 0; while (x <= 512 && line[x]) { if (x > 500) return (NULL); if (ft_strchr(" 0", line[x])) map[y][x] = '0'; else if (ft_strchr("1", line[x])) map[y][x] = '1'; else if (ft_strchr("NESW", line[x])) map[y][x] = ft_setplayerpos(vl, line[x], y, x); x++; } free(line); y++; } ft_errorexit("Something went wrong", "ft_getmap", 1); return (0); }