diff --git a/Makefile b/Makefile index 405f4ce..8d218da 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SRCS = asset.c color.c draw.c ft_freer.c main.c map.c parsing.c xpm.c +SRCS = asset.c color.c draw.c key.c main.c map.c parsing.c xpm.c OBJS = ${SRCS:.c=.o} @@ -30,6 +30,7 @@ fclean: clean make -C libftx fclean make -C minilibx-linux clean -re: fclean all +re: fclean + make all .PHONY: all clean fclean re diff --git a/color.c b/color.c index 2070fa9..625a68c 100644 --- a/color.c +++ b/color.c @@ -6,7 +6,7 @@ /* By: cchauvet nb_color_swap + 5 > NB_COLORS) - data->nb_color_swap = 0; - square.color = colors[data->nb_color_swap++]; + square.size = CASE_SIZE; + square.color = colors[ft_random_generator(0, 100)]; data->ecolor = name_generator(square); - square.color = colors[data->nb_color_swap++]; + square.color = colors[ft_random_generator(0, 100)]; data->pcolor = name_generator(square); - square.color = colors[data->nb_color_swap++]; + square.color = colors[ft_random_generator(0, 100)]; data->wcolor = name_generator(square); - square.color = colors[data->nb_color_swap++]; + square.color = colors[ft_random_generator(0, 100)]; data->ccolor = name_generator(square); - square.color = colors[data->nb_color_swap++]; + square.color = colors[ft_random_generator(0, 100)]; square.size = WINDOW_SIZE; - square.color = colors[data->nb_color_swap++]; + square.color = colors[ft_random_generator(0, 100)]; data->bcolor = name_generator(square); if (data->bcolor == NULL || data->wcolor == NULL || data->pcolor == NULL || data->ecolor == NULL || data->ccolor == NULL) diff --git a/color_and_shape.o b/color_and_shape.o deleted file mode 100644 index ebef5cf..0000000 Binary files a/color_and_shape.o and /dev/null differ diff --git a/draw.c b/draw.c index 2dd18df..ee49a02 100644 --- a/draw.c +++ b/draw.c @@ -6,7 +6,7 @@ /* By: cchauvet mlx, img_path, &bozo, &bozo); if (img == NULL) return ; @@ -37,14 +38,16 @@ static char *ft_char2xpm(t_data data, char c) return (NULL); } -int ft_draw_map(t_data *data, t_map *map) +int ft_draw_map(t_data *data) { size_t x; size_t y; char **patern; char *path; - patern = ft_get_player_map(*map); + ft_fill_pos(data); + ft_color_changer(data); + patern = ft_get_player_map(*data->map); if (patern == NULL) return (1); ft_draw_xpm(data, data->bcolor, 0, 0); @@ -61,6 +64,6 @@ int ft_draw_map(t_data *data, t_map *map) } y++; } - //ft_freer_tab_ultimate(1, patern); + ft_freer_tab_ultimate(1, patern); return (0); } diff --git a/key.c b/key.c new file mode 100644 index 0000000..7047b60 --- /dev/null +++ b/key.c @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* key.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cchauvet map->player_pos[0]; + y = data->map->player_pos[1]; + if (direction == 'L') + new_pos = &data->map->patern[x - 1][y]; + if (direction == 'U') + new_pos = &data->map->patern[x][y + 1]; + if (direction == 'D') + new_pos = &data->map->patern[x][y - 1]; + if (direction == 'R') + new_pos = &data->map->patern[x + 1][y]; + if (*new_pos == 'C') + data->map->nb_collectable++; + if (*new_pos == '0' || *new_pos == 'C') + ft_case_update(new_pos, &data->map->patern[y][x]); + ft_draw_map(data); +} + +int ft_key(int keycode, t_data *data) +{ + ft_printf("%d\n", keycode); + if (keycode == 65361) + ft_move(data, 'L'); + else if (keycode == 65363) + ft_move(data, 'R'); + else if (keycode == 65362) + ft_move(data, 'U'); + else if (keycode == 65364) + ft_move(data, 'D'); + return (0); +} + diff --git a/libftx/extra/Makefile b/libftx/extra/Makefile index 7aa0d1f..b115e7f 100644 --- a/libftx/extra/Makefile +++ b/libftx/extra/Makefile @@ -6,13 +6,13 @@ # By: cchauvet # include +# include +# include # include "../libft/libft.h" -void ft_freer_tab_ultimate(size_t len, ...); -void ft_freer_ultimate(size_t len, ...); +char *get_next_line(int fd); +size_t ft_random_generator(size_t start, size_t stop); +void ft_freer_tab_ultimate(size_t len, ...); +void ft_freer_ultimate(size_t len, ...); char *ft_strgen(char c, size_t len); char *ft_strfjoin(char *s1, char *s2); char *ft_strmerger(size_t arg_len, ...); diff --git a/libftx/extra/ft_freer.c b/libftx/extra/ft_freer.c index e7853b9..a010acf 100644 --- a/libftx/extra/ft_freer.c +++ b/libftx/extra/ft_freer.c @@ -6,15 +6,14 @@ /* By: cchauvet map = map; + data->mlx = mlx_init(); + data->window = mlx_new_window(data->mlx, WINDOW_SIZE, WINDOW_SIZE, "solong"); + ft_draw_map(data); + mlx_key_hook(data->window, ft_key, data); + mlx_loop(data->mlx); + ft_freer_tab_ultimate(1, map->patern); + mlx_destroy_window(data->mlx, data->window); + mlx_destroy_display(data->mlx); + free(data->mlx); + ft_freer_ultimate(5, data->bcolor, data->pcolor, data->ccolor, data->wcolor, data->ecolor); + free(data); + free(map); return (0); } diff --git a/map.c b/map.c index 17451f0..169cb1e 100644 --- a/map.c +++ b/map.c @@ -6,7 +6,7 @@ /* By: cchauvet map->patern[y] != NULL) + { + x = 0; + while (x < ft_strlen(data->map->patern[y])) + { + if (data->map->patern[y][x] == 'P') + { + data->map->player_pos[0] = x; + data->map->player_pos[1] = y; + } + if (data->map->patern[y][x] == 'E') + { + data->map->exit_pos[0] = x; + data->map->exit_pos[1] = y; + } + x++; + } + y++; + } +} + t_map *ft_getmap(char *path) { t_map *map; - map = malloc(sizeof(t_map)); + map = ft_calloc(sizeof(t_map), 1); if (map == NULL) return (NULL); - map->exit[2] = 0; - map->player_pos[2] = 0; map->patern = ft_readfile(path); if (ft_map_is_correct(map) == 0) return (NULL); @@ -90,7 +115,7 @@ char **ft_get_player_map(t_map map) size_t y; size_t i; - player_map = malloc(RENDER_DISTANCE * 2 + 2); + player_map = ft_calloc(RENDER_DISTANCE * 2 + 2, sizeof(char *)); if (player_map == NULL) return (NULL); i = 0; @@ -100,6 +125,7 @@ char **ft_get_player_map(t_map map) player_map[y] = ft_strgen('0', RENDER_DISTANCE * 2 + 1); if (map.player_pos[1] + y >= RENDER_DISTANCE && map.patern[i] != NULL) { + free(player_map[y]); player_map[y] = ft_get_line(map.patern[i], map.player_pos[0]); i++; } diff --git a/parsing.c b/parsing.c index 2dc12f4..f0a5147 100644 --- a/parsing.c +++ b/parsing.c @@ -6,7 +6,7 @@ /* By: cchauvet y_len) + test1 = 0; + test2 = 0; + y = 0; + while (y < map->y_len) { - cord[0] = -1; - while ((size_t) ++cord[0] < map->x_len) + x = 0; + while (x < map->x_len) { - if (map->patern[cord[1]][cord[0]] == 'E') - { - map->exit[0] = cord[0]; - map->exit[1] = cord[1]; - map->exit[2]++; - } - else if (map->patern[cord[1]][cord[0]] == 'P') - { - map->player_pos[0] = cord[0]; - map->player_pos[1] = cord[1]; - map->player_pos[2]++; - } + if (map->patern[y][x] == 'E') + test1++; + else if (map->patern[y][x] == 'P') + test2++; + x++; } + y++; } - if (map->player_pos[2] == 1 && map->exit[2] == 1) + if (test1 == 1 && test2 == 1) return (1); return (0); } diff --git a/solong.h b/solong.h index 15e387b..4656478 100644 --- a/solong.h +++ b/solong.h @@ -6,7 +6,7 @@ /* By: cchauvet