From 0265ecb22fc843c4c82b0b636a8948be78b23269 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Wed, 15 Jun 2022 01:08:31 +0200 Subject: [PATCH] add parsing color --- includes/Cub3D.h | 14 +++---- map/subject_magma.cub | 2 + srcs/get_texture_array.c | 9 +++-- srcs/main.c | 8 ++-- srcs/parsing/check_color_texture.c | 60 ++++++++++++------------------ srcs/utils.c | 14 +++---- 6 files changed, 49 insertions(+), 58 deletions(-) diff --git a/includes/Cub3D.h b/includes/Cub3D.h index 9867dc1..f05203d 100644 --- a/includes/Cub3D.h +++ b/includes/Cub3D.h @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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{ diff --git a/map/subject_magma.cub b/map/subject_magma.cub index d0384d7..4c2d621 100644 --- a/map/subject_magma.cub +++ b/map/subject_magma.cub @@ -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 diff --git a/srcs/get_texture_array.c b/srcs/get_texture_array.c index 4a11cd9..1ff1185 100644 --- a/srcs/get_texture_array.c +++ b/srcs/get_texture_array.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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) diff --git a/srcs/main.c b/srcs/main.c index 3f3f70d..7f5b0e3 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -72,7 +72,7 @@ int main(int argc, char **argv) t_data img; if (argc != 2) - ft_error("Error: bad number of arguments, only need a map"); + ft_error("Error: bad number of arguments, only need a map"); set_map(&img); img.player.x = 0; img.player.y = 0; @@ -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; diff --git a/srcs/parsing/check_color_texture.c b/srcs/parsing/check_color_texture.c index 152751d..3f532fb 100644 --- a/srcs/parsing/check_color_texture.c +++ b/srcs/parsing/check_color_texture.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/srcs/utils.c b/srcs/utils.c index ce7391a..27d482f 100644 --- a/srcs/utils.c +++ b/srcs/utils.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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)