basic parsing
This commit is contained in:
parent
accf28619f
commit
3131eb717f
@ -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
|
||||
|
8
cub3d.h
8
cub3d.h
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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++;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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},
|
||||
|
61
src/parse.c
61
src/parse.c
@ -6,11 +6,68 @@
|
||||
/* By: houtworm <codam@houtworm.net> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user