diff --git a/config.cub b/config.cub index 0e96b22..bd5ec99 100644 --- a/config.cub +++ b/config.cub @@ -1,5 +1,5 @@ -F 220,100,0 -C 225,30,0 +C 0,100,255 +F 100,100,100 NO ./path_to_the_north_texture EA ./path_to_the_east_texture diff --git a/cub3d.h b/cub3d.h index e9298bb..1a6940e 100644 --- a/cub3d.h +++ b/cub3d.h @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 10:46:35 by houtworm #+# #+# */ -/* Updated: 2023/10/27 14:58:39 by djonker ######## odam.nl */ +/* Updated: 2023/10/27 16:46:25 by djonker ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -51,6 +51,12 @@ typedef struct s_varlist int stepy; int hit; int side; + int32_t fcolor; + int32_t ccolor; + char *northwt; + char *eastwt; + char *southwt; + char *westwt; } t_varlist; // init.c diff --git a/src/draw.c b/src/draw.c index 261a618..5de6af3 100644 --- a/src/draw.c +++ b/src/draw.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:54:20 by houtworm #+# #+# */ -/* Updated: 2023/10/27 14:36:03 by djonker ######## odam.nl */ +/* Updated: 2023/10/27 17:04:16 by djonker ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -20,11 +20,11 @@ void ft_drawline(int x, t_varlist *vl, int drawstart, int drawend) while (vl->h >= y) { if (y < drawstart) - mlx_put_pixel(vl->img, x, y, 0x005566FF); + mlx_put_pixel(vl->img, x, y, vl->ccolor); else if (y < drawend) mlx_put_pixel(vl->img, x, y, 0x440000FF); else - mlx_put_pixel(vl->img, x, y, 0x444444FF); + mlx_put_pixel(vl->img, x, y, vl->fcolor); y++; } } diff --git a/src/map.c b/src/map.c index 57db6c5..a136c0c 100644 --- a/src/map.c +++ b/src/map.c @@ -6,7 +6,7 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 17:33:50 by houtworm #+# #+# */ -/* Updated: 2023/10/27 13:44:41 by djonker ######## odam.nl */ +/* Updated: 2023/10/27 16:25:33 by djonker ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ char **ft_getmap(void) {1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, - {1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,1}, + {1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, diff --git a/src/parse.c b/src/parse.c index 1226668..4259268 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,11 +6,68 @@ /* By: houtworm +#+ */ /* +#+ */ /* Created: 2023/10/26 16:48:55 by houtworm #+# #+# */ -/* Updated: 2023/10/27 13:49:00 by djonker ######## odam.nl */ +/* Updated: 2023/10/27 19:56:28 by djonker ######## odam.nl */ /* */ /* ************************************************************************** */ #include "../cub3d.h" +#include + +int ft_settexture(t_varlist *vl, char *line) +{ + int i; + + printf("line: %s\n", line); + i = 0; + while (line[i] != '.') + i++; + if (ft_strncmp(line, "NO ", 3)) + vl->northwt = ft_strdup(&line[i]); + if (ft_strncmp(line, "EA ", 3)) + vl->eastwt = ft_strdup(&line[i]); + if (ft_strncmp(line, "SO ", 3)) + vl->southwt = ft_strdup(&line[i]); + if (ft_strncmp(line, "WE ", 3)) + vl->westwt = ft_strdup(&line[i]); + return (0); +} + +int ft_setcolor(t_varlist *vl, char *line) +{ + int i; + int r; + int g; + int b; + + i = 0; + while (line[i] < '0' || line[i] > '9') + i++; + r = ft_atoi(&line[i]); + while (line[i] >= '0' && line[i] <= '9') + i++; + while (line[i] < '0' || line[i] > '9') + i++; + g = ft_atoi(&line[i]); + while (line[i] >= '0' && line[i] <= '9') + i++; + while (line[i] < '0' || line[i] > '9') + i++; + b = ft_atoi(&line[i]); + if (line[0] == 'F') + vl->fcolor = (r << 24 | g << 16 | b << 8 | 255); + if (line[0] == 'C') + vl->ccolor = (r << 24 | g << 16 | b << 8 | 255); + return (0); +} + +int ft_checkline(t_varlist *vl, char *line) +{ + if ((line[0] == 'F' || line[0] == 'C') && line[1] == ' ') + ft_setcolor(vl, line); + else if ((!ft_strncmp(line, "NO ", 3) || !ft_strncmp(line, "EA ", 3) || !ft_strncmp(line, "SO ", 3) || !ft_strncmp(line, "WE ", 3))) + ft_settexture(vl, line); + return (0); +} t_varlist ft_parseconfigfile(t_varlist vl, char *filename) { @@ -22,8 +79,10 @@ t_varlist ft_parseconfigfile(t_varlist vl, char *filename) ft_errorexit("file does not exist", "parseconfigfile", 1); while (get_next_line(fd, &line)) { + ft_checkline(&vl, line); free(line); } + free(line); vl.map = ft_getmap(); return (vl); }