aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h4
-rw-r--r--src/ft_drawsquare.c5
-rw-r--r--src/ft_exit.c1
-rw-r--r--src/ft_get_map.c20
-rw-r--r--src/ft_init_lists.c15
-rw-r--r--src/ft_parse_map.c1
-rw-r--r--src/main.c2
8 files changed, 39 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index f826999..0b45fb9 100644
--- a/Makefile
+++ b/Makefile
@@ -26,6 +26,7 @@ SRCS_NAME += ft_get_res.c
SRCS_NAME += ft_get_tex.c
SRCS_NAME += ft_get_sprite_tex.c
SRCS_NAME += ft_get_colors.c
+SRCS_NAME += ft_get_map.c
SRCS_NAME += ft_check_empty_line.c
SRCS_NAME += ft_free_words.c
SRCS_NAME += ft_map_error.c
diff --git a/inc/cub3d.h b/inc/cub3d.h
index ead1b52..7df93ad 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -28,6 +28,7 @@ typedef struct s_cub
char *sprite_path;
int f_color;
int c_color;
+ char **map;
} t_cub;
typedef struct s_win
@@ -44,11 +45,12 @@ t_cub *ft_init_cub(void);
void ft_parse_map(const char *map_path, t_win *wlist);
int ft_key_event(int keycode, void *param);
int ft_exit(uint8_t exit_code, t_win *wlist);
-void ft_drawsquare(t_win *wlist, int a, int b);
+void ft_drawsquare(int a, int b, int rgb, t_win *wlist);
int ft_get_res(int fd, t_win *wlist);
int ft_get_tex(int fd, t_win *wlist);
int ft_get_sprite_tex(int fd, t_win *wlist);
int ft_get_colors(int fd, t_win *wlist);
+int ft_get_map(int fd, t_win *wlist);
void ft_check_empty_line(int fd,
unsigned int linum,
t_win *wlist);
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);
}
diff --git a/src/main.c b/src/main.c
index 4d7b341..d80866b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
}