rgb
This commit is contained in:
parent
a48f3d82da
commit
c600aa4b15
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
|
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/14 14:59:08 by apommier ### ########.fr */
|
/* Updated: 2022/06/14 21:26:20 by sadjigui ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -53,9 +53,12 @@ typedef struct all_wall_texture{
|
|||||||
|
|
||||||
typedef struct s_color{
|
typedef struct s_color{
|
||||||
//unsigned char t;
|
//unsigned char t;
|
||||||
unsigned char r;
|
// unsigned char r;
|
||||||
unsigned char g;
|
// unsigned char g;
|
||||||
unsigned char b;
|
// unsigned char b;
|
||||||
|
int r;
|
||||||
|
int g;
|
||||||
|
int b;
|
||||||
} color;
|
} color;
|
||||||
|
|
||||||
typedef struct map_information{
|
typedef struct map_information{
|
||||||
|
|||||||
10
map/map8.cub
10
map/map8.cub
@ -1,14 +1,14 @@
|
|||||||
NO ./sprite/brick_wall.ppm
|
NO ./sprite/brick_wall.ppm
|
||||||
SO ./sprite/brick_wall.ppm
|
SO ./sprite/brick_wall.ppm
|
||||||
|
|
||||||
EA ./sprite/brick_wall.ppm
|
EA ./sprite/brick_wall.ppm
|
||||||
WE ./sprite/brick_wall.ppm
|
WE ./sprite/brick_wall.ppm
|
||||||
|
|
||||||
|
|
||||||
11111111
|
11111111
|
||||||
11000001
|
11111001
|
||||||
10000001
|
10131001
|
||||||
10E00001
|
10111001
|
||||||
11000001
|
1000E001
|
||||||
11000001
|
11000001
|
||||||
11000001
|
11000001
|
||||||
11111111
|
11111111
|
||||||
@ -1,3 +1,8 @@
|
|||||||
|
NO ./sprite/magma.ppm
|
||||||
|
SO ./sprite/stone_bricks.ppm
|
||||||
|
EA ./sprite/glowstone.ppm
|
||||||
|
WE ./sprite/obsidian.ppm
|
||||||
|
|
||||||
F 220,100,0
|
F 220,100,0
|
||||||
C 225,30,0
|
C 225,30,0
|
||||||
|
|
||||||
|
|||||||
94
srcs/parsing.c
Normal file
94
srcs/parsing.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parsing.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/24 14:17:25 by sadjigui #+# #+# */
|
||||||
|
/* Updated: 2022/05/24 14:49:21 by sadjigui ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../includes/Cub3D.h"
|
||||||
|
|
||||||
|
int parsing(char **av);
|
||||||
|
{
|
||||||
|
char *line;
|
||||||
|
int fd;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
fd = open(argv[1], O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
ft_error("Error: Open call fail");
|
||||||
|
line = get_next_line(fd);
|
||||||
|
while (line != NULL)
|
||||||
|
i++;
|
||||||
|
close(fd);
|
||||||
|
if (set_map_test)
|
||||||
|
return (1);
|
||||||
|
return (ret_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
int set_map_test(char **av, int size)
|
||||||
|
{
|
||||||
|
char *line;
|
||||||
|
char **map;
|
||||||
|
int fd;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
fd = open(argv[1], O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
ft_error("Error: Open call fail");
|
||||||
|
map = malloc(sizeof(char *) * (size + 1));
|
||||||
|
if (!map)
|
||||||
|
return (0);
|
||||||
|
line = get_next_line(fd);
|
||||||
|
while (line != NULL)
|
||||||
|
{
|
||||||
|
map[i] = line;
|
||||||
|
free(line);
|
||||||
|
line = get_next_line(fd);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
map[i] = 0;
|
||||||
|
test_map(map, size);
|
||||||
|
// free map
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *out_of_map(int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
str = malloc(sizeof(char) * (size + 1));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
while (i < size)
|
||||||
|
{
|
||||||
|
str[i] = '3';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_map(char **map, int height)
|
||||||
|
{
|
||||||
|
char **tmp;
|
||||||
|
int width;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
width = find_max(map);
|
||||||
|
tmp = malloc(sizeof(char *) * (height + 3));
|
||||||
|
if (!tmp)
|
||||||
|
return (0);
|
||||||
|
while (tmp[i])
|
||||||
|
{
|
||||||
|
tmp[i] = out_of_map(width);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/14 16:35:53 by apommier ### ########.fr */
|
/* Updated: 2022/06/14 21:36:53 by sadjigui ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -96,6 +96,41 @@ void set_texture_file(char *str, t_data *img, char c)
|
|||||||
get_texture(c, str + index + 3, img);
|
get_texture(c, str + index + 3, img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void check_value(char **tab, int index)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (tab[i])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (tab[i][j])
|
||||||
|
{
|
||||||
|
if (ft_isdigit(tab[i][j]))
|
||||||
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_color_utils(char **tab, int index, color *img)
|
||||||
|
{
|
||||||
|
check_value(tab, index);
|
||||||
|
img->r = ft_atoi(tab[0] + index);
|
||||||
|
img->g = ft_atoi(tab[1]);
|
||||||
|
img->b = ft_atoi(tab[2]);
|
||||||
|
|
||||||
|
printf("---%d\n", img->g);
|
||||||
|
if (!(img->r >= 0 && img->r <= 255))
|
||||||
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
|
if (!(img->g >= 0 && img->r <= 255))
|
||||||
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
|
if (!(img->b >= 0 && img->r <= 255))
|
||||||
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
|
}
|
||||||
|
|
||||||
void set_color(char *str, t_data *img)
|
void set_color(char *str, t_data *img)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
@ -104,7 +139,7 @@ void set_color(char *str, t_data *img)
|
|||||||
|
|
||||||
c = next_space(str, 0);
|
c = next_space(str, 0);
|
||||||
index = next_space_index(str, 0);
|
index = next_space_index(str, 0);
|
||||||
tab = ft_split(str + 1, ',');
|
tab = ft_split(str, ',');
|
||||||
if (!tab)
|
if (!tab)
|
||||||
quit_game(img);
|
quit_game(img);
|
||||||
if (double_size(tab) != 3)
|
if (double_size(tab) != 3)
|
||||||
@ -113,13 +148,23 @@ void set_color(char *str, t_data *img)
|
|||||||
{
|
{
|
||||||
if (str[index + 1] != ' ')
|
if (str[index + 1] != ' ')
|
||||||
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index += next_space_index(str, index + 1);
|
||||||
|
set_color_utils(tab, index, &img->map.floor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (c == 'C')
|
if (c == 'C')
|
||||||
{
|
{
|
||||||
if (str[index + 1] != ' ')
|
if (str[index + 1] != ' ')
|
||||||
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index += next_space_index(str, index + 1);
|
||||||
|
set_color_utils(tab, index, &img->map.sky);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
free_double(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_texture_color(char **tab, t_data *img)
|
int check_texture_color(char **tab, t_data *img)
|
||||||
@ -142,7 +187,10 @@ int check_texture_color(char **tab, t_data *img)
|
|||||||
if (next_space(tab[index], 0) == 'N' || next_space(tab[index], 0) == 'S' || next_space(tab[index], 0) == 'W' || next_space(tab[index], 0) == 'E')
|
if (next_space(tab[index], 0) == 'N' || next_space(tab[index], 0) == 'S' || next_space(tab[index], 0) == 'W' || next_space(tab[index], 0) == 'E')
|
||||||
set_texture_file(tab[index], img, next_space(tab[index], 0));
|
set_texture_file(tab[index], img, next_space(tab[index], 0));
|
||||||
else if (next_space(tab[index], 0) == 'F' || next_space(tab[index], 0) == 'C')
|
else if (next_space(tab[index], 0) == 'F' || next_space(tab[index], 0) == 'C')
|
||||||
|
{
|
||||||
set_color(tab[index], img);
|
set_color(tab[index], img);
|
||||||
|
|
||||||
|
}
|
||||||
else if (next_space(tab[index], 0))
|
else if (next_space(tab[index], 0))
|
||||||
ft_exit("Error\nBad syntax in map file\n");
|
ft_exit("Error\nBad syntax in map file\n");
|
||||||
index++;
|
index++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user