add parsing color
This commit is contained in:
parent
c600aa4b15
commit
0265ecb22f
@ -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 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{
|
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 r;
|
||||||
int g;
|
//int g;
|
||||||
int b;
|
//int b;
|
||||||
} color;
|
} color;
|
||||||
|
|
||||||
typedef struct map_information{
|
typedef struct map_information{
|
||||||
|
|||||||
@ -3,6 +3,8 @@ SO ./sprite/stone_bricks.ppm
|
|||||||
EA ./sprite/glowstone.ppm
|
EA ./sprite/glowstone.ppm
|
||||||
WE ./sprite/obsidian.ppm
|
WE ./sprite/obsidian.ppm
|
||||||
|
|
||||||
|
F 220,100,0
|
||||||
|
C 31,38,227
|
||||||
|
|
||||||
1111111111111111111111111
|
1111111111111111111111111
|
||||||
1000000000110000000000001
|
1000000000110000000000001
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/05/06 16:10:11 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;
|
int fd;
|
||||||
unsigned char *ret;
|
unsigned char *ret;
|
||||||
@ -56,7 +56,10 @@ unsigned char *get_texture(char type, char *path, t_data *img)
|
|||||||
count = 0;
|
count = 0;
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd == -1)
|
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)
|
while (swap || !count)
|
||||||
{
|
{
|
||||||
if (swap)
|
if (swap)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 16:42:55 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;
|
t_data img;
|
||||||
|
|
||||||
if (argc != 2)
|
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);
|
set_map(&img);
|
||||||
img.player.x = 0;
|
img.player.x = 0;
|
||||||
img.player.y = 0;
|
img.player.y = 0;
|
||||||
@ -83,8 +83,8 @@ int main(int argc, char **argv)
|
|||||||
if (!img.mlx)
|
if (!img.mlx)
|
||||||
ft_error("Error: mlx_init fail");
|
ft_error("Error: mlx_init fail");
|
||||||
img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
|
img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
|
||||||
img.player.vx = -cos(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.vy = sin(deg_to_rad(img.player.angle));
|
||||||
img.player.front = 0;
|
img.player.front = 0;
|
||||||
img.player.side = 0;
|
img.player.side = 0;
|
||||||
img.player.angle_side = 0;
|
img.player.angle_side = 0;
|
||||||
|
|||||||
@ -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 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);
|
get_texture(c, str + index + 3, img);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_value(char **tab, int index)
|
void check_value(char **tab)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
@ -107,28 +107,28 @@ void check_value(char **tab, int index)
|
|||||||
j = 0;
|
j = 0;
|
||||||
while (tab[i][j])
|
while (tab[i][j])
|
||||||
{
|
{
|
||||||
if (ft_isdigit(tab[i][j]))
|
if (!ft_isdigit(tab[i][j]))
|
||||||
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
ft_exit("Error\nBad syntax in map file (RGB)2\n");
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_color_utils(char **tab, int index, color *img)
|
void set_color_utils(char **tab, color *img)
|
||||||
{
|
{
|
||||||
check_value(tab, index);
|
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[0]) >= 0 && ft_atoi(tab[0]) <= 255))
|
||||||
img->r = ft_atoi(tab[0] + index);
|
ft_exit("Error\nBad syntax in map file (RGB)\n");
|
||||||
img->g = ft_atoi(tab[1]);
|
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[1]) >= 0 && ft_atoi(tab[1]) <= 255))
|
||||||
img->b = ft_atoi(tab[2]);
|
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)
|
void set_color(char *str, t_data *img)
|
||||||
@ -137,33 +137,19 @@ void set_color(char *str, t_data *img)
|
|||||||
int index;
|
int index;
|
||||||
char **tab;
|
char **tab;
|
||||||
|
|
||||||
|
printf("str=%s \n", str);
|
||||||
c = next_space(str, 0);
|
c = next_space(str, 0);
|
||||||
index = next_space_index(str, 0);
|
index = next_space_index(str + 1, 0);
|
||||||
tab = ft_split(str, ',');
|
tab = ft_split(str + index + 1, ',');
|
||||||
if (!tab)
|
if (!tab)
|
||||||
quit_game(img);
|
quit_game(img);
|
||||||
if (double_size(tab) != 3)
|
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 (c == 'F')
|
||||||
{
|
set_color_utils(tab, &img->map.floor);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (c == 'C')
|
if (c == 'C')
|
||||||
{
|
set_color_utils(tab, &img->map.sky);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free_double(tab);
|
free_double(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
srcs/utils.c
14
srcs/utils.c
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 23:37:02 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;
|
//int tmp;
|
||||||
|
|
||||||
//tmp = (int *)img->buffer;
|
//tmp = (int *)img->buffer;
|
||||||
img->map.floor.r = 128;
|
// img->map.floor.r = 128;
|
||||||
img->map.floor.g = 128;
|
// img->map.floor.g = 128;
|
||||||
img->map.floor.b = 128;
|
// img->map.floor.b = 128;
|
||||||
img->map.sky.r = 0;
|
// img->map.sky.r = 0;
|
||||||
img->map.sky.g = 191;
|
// img->map.sky.g = 191;
|
||||||
img->map.sky.b = 255;
|
// img->map.sky.b = 255;
|
||||||
while (x < 512 * 960 * 4)
|
while (x < 512 * 960 * 4)
|
||||||
{
|
{
|
||||||
if (x > 512 * 960 * 2)
|
if (x > 512 * 960 * 2)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user