/* ************************************************************************** */ /* */ /* :::::::: */ /* map.c :+: :+: */ /* +:+ */ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */ /* Updated: 2023/10/29 14:59:47 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) { map[y] = ft_calloc(512, 8); while (ret > 0) { ret = get_next_line(fd, &line); if (line[0]) break ; } if (ret == 0) { map[y] = NULL; int i; i = 0; while (i < y) { printf("%s\n", map[i]); i++; } free(line); printf("xpos: %lf ypos %lf xdir %lf ydir %lf\n\n", vl->posy, vl->posx, vl->dirx, vl->diry); return (map); } printf("line: %s\n", line); x = 0; while (x <= 512 && line[x]) { 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++; } free(line); if (x > 500 || y > 500) return (NULL); return (map); }