diff --git a/Makefile b/Makefile index b8ac58e..405f4ce 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -SRCS = asset.c draw.c main.c map.c parsing.c shape.c xpm.c +SRCS = asset.c color.c draw.c ft_freer.c main.c map.c parsing.c xpm.c -OBJ = ${SRCS:.c=.o} +OBJS = ${SRCS:.c=.o} NAME = so_long @@ -15,13 +15,13 @@ FLAG = -Wall -Wextra -Werror -g all: ${NAME} -${NAME}: ${OBJ} +${NAME}: ${OBJS} make -C libftx make -C minilibx-linux - ${CC} ${OBJ} -o ${NAME} ${LIBS} -lXext -lX11 + ${CC} ${OBJS} -o ${NAME} ${LIBS} -lXext -lX11 clean: - rm -f OBJ + rm -f ${OBJS} make -C libftx clean make -C minilibx-linux clean diff --git a/asset.c b/asset.c index 0439501..2bf4fce 100644 --- a/asset.c +++ b/asset.c @@ -6,69 +6,32 @@ /* By: cchauvet nb_color_swap + 5 > NB_COLORS) + data->nb_color_swap = 0; + square.color = colors[data->nb_color_swap++]; + data->ecolor = name_generator(square); + square.color = colors[data->nb_color_swap++]; + data->pcolor = name_generator(square); + square.color = colors[data->nb_color_swap++]; + data->wcolor = name_generator(square); + square.color = colors[data->nb_color_swap++]; + data->ccolor = name_generator(square); + square.color = colors[data->nb_color_swap++]; + square.size = WINDOW_SIZE; + square.color = colors[data->nb_color_swap++]; + data->bcolor = name_generator(square); + if (data->bcolor == NULL || data->wcolor == NULL + || data->pcolor == NULL || data->ecolor == NULL || data->ccolor == NULL) + { + ft_printf("Memory error"); + ft_freer_ultimate(5, data->wcolor, data->ecolor, data->bcolor); + ft_freer_ultimate(2, data->pcolor, data->ccolor); + return (1); + } + return (0); +} + +int ft_color_changer(t_data *data) +{ + char **colors; + + colors = ft_split(COLORS, '|'); + if (colors == NULL) + { + ft_printf("Memory error"); + return (1); + } + ft_textures_set(data, colors); + ft_freer_tab_ultimate(1, colors); + return (0); +} + diff --git a/color.o b/color.o new file mode 100644 index 0000000..89b58ff Binary files /dev/null and b/color.o differ diff --git a/color_and_shape.o b/color_and_shape.o new file mode 100644 index 0000000..ebef5cf Binary files /dev/null and b/color_and_shape.o differ diff --git a/draw.c b/draw.c index 1157277..2dd18df 100644 --- a/draw.c +++ b/draw.c @@ -6,42 +6,61 @@ /* By: cchauvet mlx, img_path, &bozo, &bozo); + if (img == NULL) + return ; + mlx_put_image_to_window(data->mlx, data->window, img, x, y); + mlx_destroy_image(data->mlx, img); } -int ft_draw_map(void *mlx, void *window, t_map map) +static char *ft_char2xpm(t_data data, char c) +{ + if (c == 'C') + return (data.ccolor); + if (c == '1') + return (data.wcolor); + if (c == 'E') + return (data.ecolor); + if (c == 'P') + return (data.pcolor); + return (NULL); +} + +int ft_draw_map(t_data *data, t_map *map) { size_t x; size_t y; + char **patern; + char *path; - map = ft_getmap(path); - if (map == NULL) - return (0); - if (ft_map_is_correct(map)) - { - free(map); - return (0); - } + patern = ft_get_player_map(*map); + if (patern == NULL) + return (1); + ft_draw_xpm(data, data->bcolor, 0, 0); y = 0; - while (y < 0) + while (patern[y] != NULL) { x = 0; - while (x < 0) - x++; - return (0); + while (patern[y][x] != '\0') + { + path = ft_char2xpm(*data, patern[y][x]); + if (path != NULL) + ft_draw_xpm(data, path, x * CASE_SIZE, y * CASE_SIZE); + x++; + } + y++; } - return (1); + //ft_freer_tab_ultimate(1, patern); + return (0); } diff --git a/draw.o b/draw.o index ba8b261..dcc2760 100644 Binary files a/draw.o and b/draw.o differ diff --git a/ft_freer.c b/ft_freer.c new file mode 100644 index 0000000..e7853b9 --- /dev/null +++ b/ft_freer.c @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_freer.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet # include "../libft/libft.h" +char *ft_strgen(char c, size_t len); char *ft_strfjoin(char *s1, char *s2); char *ft_strmerger(size_t arg_len, ...); int ft_is_in(char *str, char c); diff --git a/libftx/extra/ft_is_in.c b/libftx/extra/ft_is_in.c index 645e5f0..bb8a149 100644 --- a/libftx/extra/ft_is_in.c +++ b/libftx/extra/ft_is_in.c @@ -6,7 +6,7 @@ /* By: cchauvet exit[2] = 0; + map->player_pos[2] = 0; map->patern = ft_readfile(path); if (ft_map_is_correct(map) == 0) return (NULL); return (map); } +static char *ft_get_line(const char *line, size_t player_x) +{ + char *out; + size_t start; + size_t stop; + size_t temp; + size_t i; + + temp = ft_strlen(line); + if (player_x + RENDER_DISTANCE > temp) + stop = temp; + else + stop = player_x + RENDER_DISTANCE; + if (player_x < RENDER_DISTANCE + 1) + start = RENDER_DISTANCE - player_x; + else + start = player_x - RENDER_DISTANCE; + if (RENDER_DISTANCE > player_x) + temp = 0; + else + temp = player_x - RENDER_DISTANCE; + out = ft_strgen('0', RENDER_DISTANCE * 2 + 1); + if (out == NULL) + return (NULL); + i = 0; + while (i < stop + 1) + { + out[start + i] = line[temp + i]; + i++; + } + return (out); +} + char **ft_get_player_map(t_map map) { char **player_map; - ssize_t y; - ssize_t i; + size_t y; + size_t i; player_map = malloc(RENDER_DISTANCE * 2 + 2); if (player_map == NULL) return (NULL); - y = -RENDER_DISTANCE; - while (y < map.y_len - map.player_pos[1] - RENDER_DISTANCE) + i = 0; + y = 0; + while (y < RENDER_DISTANCE * 2 + 1) { - i = map.player_pos[1] + y; - player_map[y] = ft_strndup(map.patern[i], RENDER_DISTANCE * 2 + 1); + player_map[y] = ft_strgen('0', RENDER_DISTANCE * 2 + 1); + if (map.player_pos[1] + y >= RENDER_DISTANCE && map.patern[i] != NULL) + { + player_map[y] = ft_get_line(map.patern[i], map.player_pos[0]); + i++; + } if (player_map[y] == NULL) { - ft_cancel(player_map, RENDER_DISTANCE - y); + ft_cancel(player_map, y); return (NULL); } y++; @@ -73,5 +113,3 @@ char **ft_get_player_map(t_map map) player_map[y] = NULL; return (player_map); } - - diff --git a/map.o b/map.o index 3b13760..5544c91 100644 Binary files a/map.o and b/map.o differ diff --git a/parsing.c b/parsing.c index 8acda88..2dc12f4 100644 --- a/parsing.c +++ b/parsing.c @@ -6,7 +6,7 @@ /* By: cchauvet