add parsing color

This commit is contained in:
kinou-p 2022-06-15 01:08:31 +02:00
parent c600aa4b15
commit 0265ecb22f
6 changed files with 49 additions and 58 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
/* Updated: 2022/06/14 21:26:20 by sadjigui ### ########.fr */
/* Updated: 2022/06/14 23:36:25 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -53,12 +53,12 @@ typedef struct all_wall_texture{
typedef struct s_color{
//unsigned char t;
// unsigned char r;
// unsigned char g;
// unsigned char b;
int r;
int g;
int b;
unsigned char r;
unsigned char g;
unsigned char b;
//int r;
//int g;
//int b;
} color;
typedef struct map_information{

View File

@ -3,6 +3,8 @@ SO ./sprite/stone_bricks.ppm
EA ./sprite/glowstone.ppm
WE ./sprite/obsidian.ppm
F 220,100,0
C 31,38,227
1111111111111111111111111
1000000000110000000000001

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
/* Updated: 2022/06/14 16:36:08 by apommier ### ########.fr */
/* Updated: 2022/06/15 00:34:01 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,7 +40,7 @@ void put_texture_in_struct(char type, unsigned char *texture, t_data *img)
}
}
unsigned char *get_texture(char type, char *path, t_data *img)
unsigned char *get_texture(char type, char *path, t_data *img)//change in list
{
int fd;
unsigned char *ret;
@ -56,7 +56,10 @@ unsigned char *get_texture(char type, char *path, t_data *img)
count = 0;
fd = open(path, O_RDONLY);
if (fd == -1)
ft_exit("Error\nBad texture file\n");
{
printf("path= %s\n", path);
ft_exit("Error\nBad texture file prout");
}
while (swap || !count)
{
if (swap)

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
/* Updated: 2022/06/14 16:39:08 by apommier ### ########.fr */
/* Updated: 2022/06/14 18:14:09 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -83,8 +83,8 @@ int main(int argc, char **argv)
if (!img.mlx)
ft_error("Error: mlx_init fail");
img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
img.player.vx = -cos(deg_to_rad(img.player.angle));
img.player.vy = -sin(deg_to_rad(img.player.angle));
img.player.vx = cos(deg_to_rad(img.player.angle));
img.player.vy = sin(deg_to_rad(img.player.angle));
img.player.front = 0;
img.player.side = 0;
img.player.angle_side = 0;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
/* Updated: 2022/06/14 21:36:53 by sadjigui ### ########.fr */
/* Updated: 2022/06/15 01:04:34 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -96,7 +96,7 @@ void set_texture_file(char *str, t_data *img, char c)
get_texture(c, str + index + 3, img);
}
void check_value(char **tab, int index)
void check_value(char **tab)
{
int i;
int j;
@ -107,28 +107,28 @@ void check_value(char **tab, int index)
j = 0;
while (tab[i][j])
{
if (ft_isdigit(tab[i][j]))
ft_exit("Error\nBad syntax in map file (RGB)\n");
if (!ft_isdigit(tab[i][j]))
ft_exit("Error\nBad syntax in map file (RGB)2\n");
j++;
}
i++;
}
}
void set_color_utils(char **tab, int index, color *img)
void set_color_utils(char **tab, 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]);
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[0]) >= 0 && ft_atoi(tab[0]) <= 255))
ft_exit("Error\nBad syntax in map file (RGB)\n");
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[1]) >= 0 && ft_atoi(tab[1]) <= 255))
ft_exit("Error\nBad syntax in map file (RGB)\n");
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[2]) >= 0 && ft_atoi(tab[2]) <= 255))
ft_exit("Error\nBad syntax in map file (RGB)\n");
check_value(tab);
img->r = (unsigned char)ft_atoi(tab[0]);
img->g = (unsigned char)ft_atoi(tab[1]);
img->b = (unsigned char)ft_atoi(tab[2]);
//printf("---%d\n", img->g);
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)
@ -137,33 +137,19 @@ void set_color(char *str, t_data *img)
int index;
char **tab;
printf("str=%s \n", str);
c = next_space(str, 0);
index = next_space_index(str, 0);
tab = ft_split(str, ',');
index = next_space_index(str + 1, 0);
tab = ft_split(str + index + 1, ',');
if (!tab)
quit_game(img);
if (double_size(tab) != 3)
ft_exit("Error\nBad syntax in map file (RGB)\n");
ft_exit("Error\nBad syntax in map file (RGB) 1\n");
print_double_fd(tab, 1);
if (c == 'F')
{
if (str[index + 1] != ' ')
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);
}
}
set_color_utils(tab, &img->map.floor);
if (c == 'C')
{
if (str[index + 1] != ' ')
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);
}
}
set_color_utils(tab, &img->map.sky);
free_double(tab);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
/* Updated: 2022/06/14 16:27:38 by apommier ### ########.fr */
/* Updated: 2022/06/15 00:54:36 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -138,12 +138,12 @@ void set_back(t_data *img)
//int tmp;
//tmp = (int *)img->buffer;
img->map.floor.r = 128;
img->map.floor.g = 128;
img->map.floor.b = 128;
img->map.sky.r = 0;
img->map.sky.g = 191;
img->map.sky.b = 255;
// img->map.floor.r = 128;
// img->map.floor.g = 128;
// img->map.floor.b = 128;
// img->map.sky.r = 0;
// img->map.sky.g = 191;
// img->map.sky.b = 255;
while (x < 512 * 960 * 4)
{
if (x > 512 * 960 * 2)