aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--inc/cub3d.h14
-rw-r--r--src/ft_drawsquare.c3
-rw-r--r--src/ft_exit.c3
-rw-r--r--src/ft_get_res.c22
-rw-r--r--src/ft_map_error.c9
-rw-r--r--src/ft_parse_map.c12
-rw-r--r--src/main.c3
8 files changed, 62 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 05328de..e696f20 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,9 @@ SRCS_NAME += ft_init_lists.c
SRCS_NAME += ft_key_events.c
SRCS_NAME += ft_exit.c
SRCS_NAME += ft_drawsquare.c
-# SRCS_NAME += ft_parse_map.c
+SRCS_NAME += ft_parse_map.c
+SRCS_NAME += ft_get_res.c
+SRCS_NAME += ft_map_error.c
#------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 459bbb7..d5ef69e 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -13,14 +13,22 @@ typedef struct s_win
typedef struct s_cub
{
- char coolcub;
+ char *north_path;
+ char *south_path;
+ char *west_path;
+ char *east_path;
+ char *sprite_path;
+ int f_color;
+ int c_color;
} t_cub;
t_cub *ft_init_cub(void);
t_win *ft_init_win(void);
-void ft_parse_map(t_cub *clist);
+void ft_parse_map(t_win *wlist, t_cub *clist, const char *map_path);
int ft_key_event(int keycode, void *param);
-void ft_exit(uint8_t exit_code);
+int ft_exit(uint8_t exit_code);
void ft_drawsquare(t_win *wlist, t_cub *clist, int a, int b);
+int ft_get_res(int fd, t_win *wlist);
+int ft_map_error(unsigned int line);
#endif
diff --git a/src/ft_drawsquare.c b/src/ft_drawsquare.c
index 78ebd8c..b37dc77 100644
--- a/src/ft_drawsquare.c
+++ b/src/ft_drawsquare.c
@@ -2,11 +2,12 @@
#include <cub3d.h>
void
-ft_drawsquare(t_win *wlist, int a, int b)
+ft_drawsquare(t_win *wlist, t_cub *clist, int a, int b)
{
int x;
int y;
+ (void)clist;
x = a;
y = b;
while (x > a - 40)
diff --git a/src/ft_exit.c b/src/ft_exit.c
index a5b7276..5a4ef73 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -2,11 +2,12 @@
#include <stdlib.h>
#include <inttypes.h>
-void
+int
ft_exit(uint8_t exit_code)
{
ft_printf("Exiting program\n");
if (exit_code < 0 || exit_code > 0)
ft_printf("Exit code: %hhu\n", exit_code);
exit(exit_code);
+ return (0);
}
diff --git a/src/ft_get_res.c b/src/ft_get_res.c
new file mode 100644
index 0000000..c610fc1
--- /dev/null
+++ b/src/ft_get_res.c
@@ -0,0 +1,22 @@
+#include <libft.h>
+#include <cub3d.h>
+
+int
+ft_get_res(int fd, t_win *wlist)
+{
+ char *line;
+ char **words;
+ int i;
+
+ (void)wlist;
+ get_next_line(fd, &line);
+ words = ft_split(line, ' ');
+ i = 0;
+ while (words)
+ {
+ ft_printf("[%s] ", words[i]);
+ i++;
+ }
+ ft_printf("\n");
+ return (0);
+}
diff --git a/src/ft_map_error.c b/src/ft_map_error.c
new file mode 100644
index 0000000..bffb6d1
--- /dev/null
+++ b/src/ft_map_error.c
@@ -0,0 +1,9 @@
+#include <libft.h>
+#include <cub3d.h>
+
+int
+ft_map_error(unsigned int line)
+{
+ ft_printf("\033[1;31mMap error: line %d\033[0m\n", line);
+ return (ft_exit(1));
+}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index baf3b5f..d2fbe0d 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -1,8 +1,18 @@
#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
+#include <fcntl.h>
+
+/*
+** I can't close
+*/
void
-ft_parse_map(t_cub *clist)
+ft_parse_map(t_win *wlist, t_cub *clist, const char *map_path)
{
+ int fd;
+
+ (void)clist;
+ fd = open(map_path, O_RDONLY);
+ ft_get_res(fd, wlist);
}
diff --git a/src/main.c b/src/main.c
index c7fbc58..d23320b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,8 +11,9 @@ int
wlist = ft_init_win();
clist = ft_init_cub();
+ ft_parse_map(wlist, clist, "map/map_one.cub");
mlx_key_hook(wlist->winptr, ft_key_event, wlist);
- ft_drawsquare(wlist, 80, 80);
+ ft_drawsquare(wlist, clist, 80, 80);
mlx_loop(wlist->wlx);
ft_memdel(clist);
return (0);