diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-26 22:28:11 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-26 22:28:11 +0100 |
commit | 29b45c0bbdcc3a8eb980d6fdc65efa09382c0ede (patch) | |
tree | a6060e809807384d96099df120d0c423d1da09b1 /src | |
parent | Better error management (diff) | |
download | 42-cub3d-29b45c0bbdcc3a8eb980d6fdc65efa09382c0ede.tar.gz 42-cub3d-29b45c0bbdcc3a8eb980d6fdc65efa09382c0ede.tar.bz2 42-cub3d-29b45c0bbdcc3a8eb980d6fdc65efa09382c0ede.tar.xz 42-cub3d-29b45c0bbdcc3a8eb980d6fdc65efa09382c0ede.tar.zst 42-cub3d-29b45c0bbdcc3a8eb980d6fdc65efa09382c0ede.zip |
Can't believe it
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_drawsquare.c | 5 | ||||
-rw-r--r-- | src/ft_exit.c | 1 | ||||
-rw-r--r-- | src/ft_get_map.c | 20 | ||||
-rw-r--r-- | src/ft_init_lists.c | 15 | ||||
-rw-r--r-- | src/ft_parse_map.c | 1 | ||||
-rw-r--r-- | src/main.c | 2 |
6 files changed, 35 insertions, 9 deletions
diff --git a/src/ft_drawsquare.c b/src/ft_drawsquare.c index df055fa..1f1334b 100644 --- a/src/ft_drawsquare.c +++ b/src/ft_drawsquare.c @@ -2,7 +2,7 @@ #include <cub3d.h> void -ft_drawsquare(t_win *wlist, int a, int b) +ft_drawsquare(int a, int b, int rgb, t_win *wlist) { int x; int y; @@ -13,8 +13,7 @@ ft_drawsquare(t_win *wlist, int a, int b) { while (y > b - 40) { - mlx_pixel_put(wlist->wlx, wlist->winptr, x, y, - wlist->clist->f_color); + mlx_pixel_put(wlist->wlx, wlist->winptr, x, y, rgb); y--; } y = b; diff --git a/src/ft_exit.c b/src/ft_exit.c index 165c3d9..14f1f2a 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -11,6 +11,7 @@ ft_free_lists(t_win *wlist) ft_memdel(wlist->clist->ea_tex_path); ft_memdel(wlist->clist->we_tex_path); ft_memdel(wlist->clist->sprite_path); + ft_free_words(wlist->clist->map, NULL); ft_memdel(wlist->clist); ft_memdel(wlist->winptr); ft_memdel(wlist->wlx); diff --git a/src/ft_get_map.c b/src/ft_get_map.c new file mode 100644 index 0000000..a45052c --- /dev/null +++ b/src/ft_get_map.c @@ -0,0 +1,20 @@ +#include <libft.h> +#include <cub3d.h> +#include <stddef.h> +#include <stdlib.h> + +int +ft_get_map(int fd, t_win *wlist) +{ + size_t i; + char *line; + + ft_free_words(wlist->clist->map, NULL); + i = 0; + if (!(wlist->clist->map = (char**)malloc(40 * sizeof(char*)))) + return (-1); + while (get_next_line(fd, &line) > 0) + { + } + return (0); +} diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 6bec697..b395840 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -24,13 +24,18 @@ t_cub if (!(clist = (t_cub*)malloc(sizeof(t_cub)))) return (NULL); - if (!(clist->no_tex_path = (char*)ft_calloc(1, 1)) || - !(clist->so_tex_path = (char*)ft_calloc(1, 1)) || - !(clist->ea_tex_path = (char*)ft_calloc(1, 1)) || - !(clist->we_tex_path = (char*)ft_calloc(1, 1)) || - !(clist->sprite_path = (char*)ft_calloc(1, 1))) + if (!(clist->no_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(clist->so_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(clist->ea_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(clist->we_tex_path = (char*)ft_calloc(1, sizeof(char))) || + !(clist->sprite_path = (char*)ft_calloc(1, sizeof(char)))) return (NULL); clist->f_color = 0; clist->c_color = 0; + if (!(clist->map = (char**)ft_calloc(2, sizeof(char*)))) + return (NULL); + if (!(clist->map[0] = (char*)ft_calloc(1, sizeof(char)))) + return (NULL); + clist->map[1] = 0; return (clist); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 32ba5d8..70b81d4 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -56,4 +56,5 @@ ft_parse_map(const char *map_path, t_win *wlist) ft_get_colors(fd, wlist); ft_print_list(wlist); ft_check_empty_line(fd, 10, wlist); + ft_get_map(fd, wlist); } @@ -18,7 +18,7 @@ int if (ft_init_winlx(wlist) < 0) return (ft_exit(3, wlist)); mlx_key_hook(wlist->winptr, ft_key_event, wlist); - ft_drawsquare(wlist, 80, 80); + ft_drawsquare(80, 80, wlist->clist->f_color, wlist); mlx_loop(wlist->wlx); return (0); } |