diff --git a/.so_long.h.swo b/.so_long.h.swo new file mode 100644 index 0000000..94fdf3c Binary files /dev/null and b/.so_long.h.swo differ diff --git a/Makefile b/Makefile index 616ba2a..6ae35b1 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,12 @@ # By: erey-bet +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/09/27 04:19:30 by erey-bet #+# #+# # -# Updated: 2022/12/10 15:43:34 by erey-bet ### ########.fr # +# Updated: 2022/12/12 17:21:15 by erey-bet ### ########.fr # # # # **************************************************************************** # -SRCS = so_long.c +GNL = get_next_line/get_next_line.c get_next_line/get_next_line_utils.c +SRCS = so_long.c ${GNL} OBJS = ${SRCS:.c=.o} LIBS = libft/libft.a minilibx-linux/libmlx.a CC = clang diff --git a/assets/exit.xpm b/assets/exit.xpm new file mode 100644 index 0000000..8321f20 --- /dev/null +++ b/assets/exit.xpm @@ -0,0 +1,133 @@ +/* XPM */ +static char * exit_xpm[] = { +"128 128 2 1", +" c #000000", +". c #3C00E2", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ............................................................................................................ ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/get_next_line/get_next_line.c b/get_next_line/get_next_line.c index 9ef66b8..32646c8 100644 --- a/get_next_line/get_next_line.c +++ b/get_next_line/get_next_line.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/15 23:42:35 by erey-bet #+# #+# */ -/* Updated: 2022/11/07 17:11:17 by erey-bet ### ########.fr */ +/* Updated: 2022/12/12 17:19:23 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ static char *read_line(int fd) char *buff; int y; - buff = ft_calloc(BUFFER_SIZE + 1, 1); + buff = ft_calloc_gnl(BUFFER_SIZE + 1, 1); if (buff == NULL) return (NULL); y = read(fd, buff, BUFFER_SIZE); @@ -36,8 +36,8 @@ static char *join_str(char *s1, char *s2) int i; int len; - len = ft_strlen(s1); - n_str = ft_calloc(len + ft_strlen(s2) + 1, 1); + len = ft_strlen_gnl(s1); + n_str = ft_calloc_gnl(len + ft_strlen_gnl(s2) + 1, 1); if (n_str == NULL) return (NULL); i = -1; @@ -63,11 +63,11 @@ static char *get_text(char *save) i++; if (save[i] == '\n') i++; - new_s = ft_calloc(i + 1, 1); + new_s = ft_calloc_gnl(i + 1, 1); if (new_s == NULL) return (NULL); - ft_strlcpy(new_s, save, i + 1); - ft_strlcpy(save, save + i, ft_strlen(save)); + ft_strlcpy_gnl(new_s, save, i + 1); + ft_strlcpy_gnl(save, save + i, ft_strlen_gnl(save)); return (new_s); } @@ -93,12 +93,13 @@ char *get_next_line(int fd) static char *save; buff = NULL; - while (buff == NULL || (ft_strchr(save, '\n') == -1)) + while (buff == NULL || (ft_strchr_gnl(save, '\n') == -1)) { buff = read_line(fd); - if (buff == NULL || (ft_strlen(buff) == 0 && ft_strlen(save) == 0)) + if (buff == NULL + || (ft_strlen_gnl(buff) == 0 && ft_strlen_gnl(save) == 0)) return (make_free(buff, &save, 1)); - if (ft_strlen(buff) == 0) + if (ft_strlen_gnl(buff) == 0) { free(buff); break ; @@ -108,7 +109,7 @@ char *get_next_line(int fd) return (NULL); } str = get_text(save); - if (ft_strlen(save) == 0) + if (ft_strlen_gnl(save) == 0) make_free(NULL, &save, 2); return (str); } diff --git a/get_next_line/get_next_line.h b/get_next_line/get_next_line.h index dba8046..e7c6568 100644 --- a/get_next_line/get_next_line.h +++ b/get_next_line/get_next_line.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/15 23:40:12 by erey-bet #+# #+# */ -/* Updated: 2022/11/15 19:42:13 by erey-bet ### ########.fr */ +/* Updated: 2022/12/12 17:16:43 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,9 +20,9 @@ # endif char *get_next_line(int fd); -void *ft_calloc(size_t nitems, size_t size); -size_t ft_strlen(const char *str); -int ft_strchr(const char *str, int search); -void ft_strlcpy(char *dest, const char *src, size_t size); +void *ft_calloc_gnl(size_t nitems, size_t size); +size_t ft_strlen_gnl(const char *str); +int ft_strchr_gnl(const char *str, int search); +void ft_strlcpy_gnl(char *dest, const char *src, size_t size); #endif diff --git a/get_next_line/get_next_line.o b/get_next_line/get_next_line.o new file mode 100644 index 0000000..efe4c00 Binary files /dev/null and b/get_next_line/get_next_line.o differ diff --git a/get_next_line/get_next_line_bonus.c b/get_next_line/get_next_line_bonus.c deleted file mode 100644 index 6a0eb9b..0000000 --- a/get_next_line/get_next_line_bonus.c +++ /dev/null @@ -1,116 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/15 23:42:35 by erey-bet #+# #+# */ -/* Updated: 2022/11/16 13:20:26 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "get_next_line_bonus.h" - -static char *read_line(int fd) -{ - char *buff; - int y; - - buff = ft_calloc(BUFFER_SIZE + 1, 1); - if (buff == NULL) - return (NULL); - y = read(fd, buff, BUFFER_SIZE); - if (y == -1) - { - free(buff); - return (NULL); - } - buff[y] = '\0'; - return (buff); -} - -static char *join_str(char *s1, char *s2) -{ - char *n_str; - int i; - int len; - - len = ft_strlen(s1); - n_str = ft_calloc(len + ft_strlen(s2) + 1, 1); - if (n_str == NULL) - return (NULL); - i = -1; - if (s1 != NULL) - while (s1[++i]) - n_str[i] = s1[i]; - i = -1; - while (s2[++i]) - n_str[i + len] = s2[i]; - n_str[i + len] = '\0'; - free(s1); - free(s2); - return (n_str); -} - -static char *get_text(char *save) -{ - int i; - char *new_s; - - i = 0; - while (save[i] && save[i] != '\n') - i++; - if (save[i] == '\n') - i++; - new_s = ft_calloc(i + 1, 1); - if (new_s == NULL) - return (NULL); - ft_strlcpy(new_s, save, i + 1); - ft_strlcpy(save, save + i, ft_strlen(save)); - return (new_s); -} - -static void *make_free(char *buff, char **save, int choice) -{ - if (choice == 1) - { - free(buff); - free(*save); - } - else - { - free(*save); - *save = NULL; - } - return (NULL); -} - -char *get_next_line(int fd) -{ - char *buff; - char *str; - static char *save[1024]; - - if (fd < 0 || fd >= 1024) - return (NULL); - buff = NULL; - while (buff == NULL || ft_strchr(save[fd], '\n') == -1) - { - buff = read_line(fd); - if (buff == NULL || (ft_strlen(buff) == 0 && ft_strlen(save[fd]) == 0)) - return (make_free(buff, &save[fd], 1)); - if (ft_strlen(buff) == 0) - { - free(buff); - break ; - } - save[fd] = join_str(save[fd], buff); - if (save[fd] == NULL) - return (NULL); - } - str = get_text(save[fd]); - if (ft_strlen(save[fd]) == 0) - make_free(NULL, &save[fd], 2); - return (str); -} diff --git a/get_next_line/get_next_line_utils.c b/get_next_line/get_next_line_utils.c index 624fad3..b507ddb 100644 --- a/get_next_line/get_next_line_utils.c +++ b/get_next_line/get_next_line_utils.c @@ -6,13 +6,13 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/11/07 17:19:41 by erey-bet #+# #+# */ -/* Updated: 2022/11/07 17:19:42 by erey-bet ### ########.fr */ +/* Updated: 2022/12/12 17:16:22 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "get_next_line.h" -void *ft_calloc(size_t nitems, size_t size) +void *ft_calloc_gnl(size_t nitems, size_t size) { size_t i; char *tmp; @@ -33,7 +33,7 @@ void *ft_calloc(size_t nitems, size_t size) return (tmp); } -size_t ft_strlen(const char *str) +size_t ft_strlen_gnl(const char *str) { int i; @@ -45,7 +45,7 @@ size_t ft_strlen(const char *str) return (i); } -int ft_strchr(const char *str, int search) +int ft_strchr_gnl(const char *str, int search) { int i; @@ -59,7 +59,7 @@ int ft_strchr(const char *str, int search) return (-1); } -void ft_strlcpy(char *dest, const char *src, size_t size) +void ft_strlcpy_gnl(char *dest, const char *src, size_t size) { size_t i; diff --git a/get_next_line/get_next_line_utils.o b/get_next_line/get_next_line_utils.o new file mode 100644 index 0000000..25251b9 Binary files /dev/null and b/get_next_line/get_next_line_utils.o differ diff --git a/get_next_line/get_next_line_utils_bonus.c b/get_next_line/get_next_line_utils_bonus.c deleted file mode 100644 index 528ac2f..0000000 --- a/get_next_line/get_next_line_utils_bonus.c +++ /dev/null @@ -1,75 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_utils_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2022/11/07 17:19:41 by erey-bet #+# #+# */ -/* Updated: 2022/11/15 19:57:30 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "get_next_line.h" - -void *ft_calloc(size_t nitems, size_t size) -{ - size_t i; - char *tmp; - - if (nitems == 0 || size == 0) - return (malloc(0)); - if (nitems * size < nitems) - return (NULL); - tmp = malloc(nitems * size); - if (tmp == NULL) - return (NULL); - i = 0; - while (i < nitems * size) - { - tmp[i] = '\0'; - i++; - } - return (tmp); -} - -size_t ft_strlen(const char *str) -{ - int i; - - if (str == NULL) - return (0); - i = 0; - while (str[i] != '\0') - i++; - return (i); -} - -int ft_strchr(const char *str, int search) -{ - int i; - - i = 0; - while (str[i] || str[i] == (unsigned char)search) - { - if (str[i] == (unsigned char)search) - return (i); - i++; - } - return (-1); -} - -void ft_strlcpy(char *dest, const char *src, size_t size) -{ - size_t i; - - i = 0; - if (!size || !dest || !src) - return ; - while (i < size - 1 && src[i] != '\0') - { - dest[i] = src[i]; - i++; - } - dest[i] = '\0'; -} diff --git a/libft/Makefile b/libft/Makefile index e507ce0..78f88f2 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -6,7 +6,7 @@ # By: erey-bet +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/09/27 04:19:30 by erey-bet #+# #+# # -# Updated: 2022/10/19 17:45:46 by erey-bet ### ########.fr # +# Updated: 2022/12/12 13:46:44 by erey-bet ### ########.fr # # # # **************************************************************************** # @@ -16,7 +16,7 @@ ft_strlcat.c ft_toupper.c ft_tolower.c ft_strchr.c ft_strrchr.c ft_strncmp.c \ ft_memchr.c ft_memcmp.c ft_strnstr.c ft_atoi.c ft_calloc.c ft_strdup.c \ ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \ ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \ -ft_get_size.c ft_power.c ft_atoi_check.c +ft_get_size.c ft_power.c ft_atoi_check.c ft_strlen_double.c OBJS = ${SRCS:.c=.o} BONUS_SRCS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c \ ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c diff --git a/libft/ft_atoi.o b/libft/ft_atoi.o new file mode 100644 index 0000000..09dcae9 Binary files /dev/null and b/libft/ft_atoi.o differ diff --git a/libft/ft_atoi_check.o b/libft/ft_atoi_check.o new file mode 100644 index 0000000..2e7a330 Binary files /dev/null and b/libft/ft_atoi_check.o differ diff --git a/libft/ft_bzero.o b/libft/ft_bzero.o new file mode 100644 index 0000000..3ca98c5 Binary files /dev/null and b/libft/ft_bzero.o differ diff --git a/libft/ft_calloc.o b/libft/ft_calloc.o new file mode 100644 index 0000000..2296eb8 Binary files /dev/null and b/libft/ft_calloc.o differ diff --git a/libft/ft_get_size.o b/libft/ft_get_size.o new file mode 100644 index 0000000..8a15881 Binary files /dev/null and b/libft/ft_get_size.o differ diff --git a/libft/ft_isalnum.o b/libft/ft_isalnum.o new file mode 100644 index 0000000..12210a8 Binary files /dev/null and b/libft/ft_isalnum.o differ diff --git a/libft/ft_isalpha.o b/libft/ft_isalpha.o new file mode 100644 index 0000000..2425dd6 Binary files /dev/null and b/libft/ft_isalpha.o differ diff --git a/libft/ft_isascii.o b/libft/ft_isascii.o new file mode 100644 index 0000000..0e5035b Binary files /dev/null and b/libft/ft_isascii.o differ diff --git a/libft/ft_isdigit.o b/libft/ft_isdigit.o new file mode 100644 index 0000000..545ee21 Binary files /dev/null and b/libft/ft_isdigit.o differ diff --git a/libft/ft_isprint.o b/libft/ft_isprint.o new file mode 100644 index 0000000..a8c2143 Binary files /dev/null and b/libft/ft_isprint.o differ diff --git a/libft/ft_itoa.o b/libft/ft_itoa.o new file mode 100644 index 0000000..9507baf Binary files /dev/null and b/libft/ft_itoa.o differ diff --git a/libft/ft_memchr.o b/libft/ft_memchr.o new file mode 100644 index 0000000..5b60a6e Binary files /dev/null and b/libft/ft_memchr.o differ diff --git a/libft/ft_memcmp.o b/libft/ft_memcmp.o new file mode 100644 index 0000000..472d702 Binary files /dev/null and b/libft/ft_memcmp.o differ diff --git a/libft/ft_memcpy.o b/libft/ft_memcpy.o new file mode 100644 index 0000000..64ef5a0 Binary files /dev/null and b/libft/ft_memcpy.o differ diff --git a/libft/ft_memmove.o b/libft/ft_memmove.o new file mode 100644 index 0000000..8a93ec8 Binary files /dev/null and b/libft/ft_memmove.o differ diff --git a/libft/ft_memset.o b/libft/ft_memset.o new file mode 100644 index 0000000..eb85a59 Binary files /dev/null and b/libft/ft_memset.o differ diff --git a/libft/ft_power.o b/libft/ft_power.o new file mode 100644 index 0000000..3450711 Binary files /dev/null and b/libft/ft_power.o differ diff --git a/libft/ft_putchar_fd.o b/libft/ft_putchar_fd.o new file mode 100644 index 0000000..525fbc3 Binary files /dev/null and b/libft/ft_putchar_fd.o differ diff --git a/libft/ft_putendl_fd.o b/libft/ft_putendl_fd.o new file mode 100644 index 0000000..9e9e284 Binary files /dev/null and b/libft/ft_putendl_fd.o differ diff --git a/libft/ft_putnbr_fd.o b/libft/ft_putnbr_fd.o new file mode 100644 index 0000000..3726826 Binary files /dev/null and b/libft/ft_putnbr_fd.o differ diff --git a/libft/ft_putstr_fd.o b/libft/ft_putstr_fd.o new file mode 100644 index 0000000..affd407 Binary files /dev/null and b/libft/ft_putstr_fd.o differ diff --git a/libft/ft_split.o b/libft/ft_split.o new file mode 100644 index 0000000..8b2b242 Binary files /dev/null and b/libft/ft_split.o differ diff --git a/libft/ft_strchr.o b/libft/ft_strchr.o new file mode 100644 index 0000000..19a1abc Binary files /dev/null and b/libft/ft_strchr.o differ diff --git a/libft/ft_strdup.o b/libft/ft_strdup.o new file mode 100644 index 0000000..c4aed59 Binary files /dev/null and b/libft/ft_strdup.o differ diff --git a/libft/ft_striteri.o b/libft/ft_striteri.o new file mode 100644 index 0000000..46ace08 Binary files /dev/null and b/libft/ft_striteri.o differ diff --git a/libft/ft_strjoin.o b/libft/ft_strjoin.o new file mode 100644 index 0000000..10ed510 Binary files /dev/null and b/libft/ft_strjoin.o differ diff --git a/libft/ft_strlcat.o b/libft/ft_strlcat.o new file mode 100644 index 0000000..f780c32 Binary files /dev/null and b/libft/ft_strlcat.o differ diff --git a/libft/ft_strlcpy.o b/libft/ft_strlcpy.o new file mode 100644 index 0000000..8d45fa0 Binary files /dev/null and b/libft/ft_strlcpy.o differ diff --git a/libft/ft_strlen.o b/libft/ft_strlen.o new file mode 100644 index 0000000..2cbf4e3 Binary files /dev/null and b/libft/ft_strlen.o differ diff --git a/get_next_line/get_next_line_bonus.h b/libft/ft_strlen_double.c similarity index 55% rename from get_next_line/get_next_line_bonus.h rename to libft/ft_strlen_double.c index c36a5a1..8ea0ac7 100644 --- a/get_next_line/get_next_line_bonus.h +++ b/libft/ft_strlen_double.c @@ -1,28 +1,30 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* get_next_line_bonus.h :+: :+: :+: */ +/* ft_strlen_double.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2022/10/15 23:40:12 by erey-bet #+# #+# */ -/* Updated: 2022/11/15 20:00:55 by erey-bet ### ########.fr */ +/* Created: 2022/12/12 13:45:14 by erey-bet #+# #+# */ +/* Updated: 2022/12/12 13:46:16 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef GET_NEXT_LINE_BONUS_H -# define GET_NEXT_LINE_BONUS_H +int ft_strlen_double(char **strs) +{ + int i; + int y; + int count; -# include -# include -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 41 -# endif - -char *get_next_line(int fd); -void *ft_calloc(size_t nitems, size_t size); -size_t ft_strlen(const char *str); -int ft_strchr(const char *str, int search); -void ft_strlcpy(char *dest, const char *src, size_t size); - -#endif + i = 0; + while (strs[i]) + { + y = 0; + while (strs[i][y]) + { + count++; + } + i++; + } + return (count); +} diff --git a/libft/ft_strlen_double.o b/libft/ft_strlen_double.o new file mode 100644 index 0000000..de681fa Binary files /dev/null and b/libft/ft_strlen_double.o differ diff --git a/libft/ft_strmapi.o b/libft/ft_strmapi.o new file mode 100644 index 0000000..d24f724 Binary files /dev/null and b/libft/ft_strmapi.o differ diff --git a/libft/ft_strncmp.o b/libft/ft_strncmp.o new file mode 100644 index 0000000..f98e33c Binary files /dev/null and b/libft/ft_strncmp.o differ diff --git a/libft/ft_strnstr.o b/libft/ft_strnstr.o new file mode 100644 index 0000000..763fd26 Binary files /dev/null and b/libft/ft_strnstr.o differ diff --git a/libft/ft_strrchr.o b/libft/ft_strrchr.o new file mode 100644 index 0000000..632d4a2 Binary files /dev/null and b/libft/ft_strrchr.o differ diff --git a/libft/ft_strtrim.o b/libft/ft_strtrim.o new file mode 100644 index 0000000..c50e2a3 Binary files /dev/null and b/libft/ft_strtrim.o differ diff --git a/libft/ft_substr.o b/libft/ft_substr.o new file mode 100644 index 0000000..4aea355 Binary files /dev/null and b/libft/ft_substr.o differ diff --git a/libft/ft_tolower.o b/libft/ft_tolower.o new file mode 100644 index 0000000..08b2bb2 Binary files /dev/null and b/libft/ft_tolower.o differ diff --git a/libft/ft_toupper.o b/libft/ft_toupper.o new file mode 100644 index 0000000..deb631e Binary files /dev/null and b/libft/ft_toupper.o differ diff --git a/libft/libft.a b/libft/libft.a index 17e7ae0..d0d0846 100644 Binary files a/libft/libft.a and b/libft/libft.a differ diff --git a/libft/libft.h b/libft/libft.h index 7546f2e..606df93 100644 --- a/libft/libft.h +++ b/libft/libft.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/26 16:31:10 by erey-bet #+# #+# */ -/* Updated: 2022/10/18 17:32:25 by erey-bet ### ########.fr */ +/* Updated: 2022/12/12 13:46:30 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,5 +67,5 @@ void ft_lstclear(t_list **lst, void (*del)(void*)); void ft_lstiter(t_list *lst, void (*f)(void *)); t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)); int ft_atoi_check(const char *nptr); - +int ft_strlen_double(char **strs); #endif diff --git a/map_test.txt b/map_test.txt new file mode 100644 index 0000000..242be01 --- /dev/null +++ b/map_test.txt @@ -0,0 +1,5 @@ +1111111111111 +10010000000C1 +1000011111001 +1P0011E000001 +1111111111111 diff --git a/so_long b/so_long index 6e4a120..d96326c 100755 Binary files a/so_long and b/so_long differ diff --git a/so_long.c b/so_long.c index f3b6116..e361f59 100644 --- a/so_long.c +++ b/so_long.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/09 14:18:18 by erey-bet #+# #+# */ -/* Updated: 2022/12/11 18:48:15 by erey-bet ### ########.fr */ +/* Updated: 2022/12/12 21:52:42 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,52 +21,129 @@ void free_img(t_data *data) int quit(t_data *data) { - if (data->mlx_img != NULL) - free_img(data); - free(data->mlx_win); - free(data->mlx); + (void)data; exit(0); return (0); } +t_xy *get_position(t_data *data, char c) +{ + int y; + t_xy *xy; + + y = 0; + xy = NULL; + while (data->map[y]) + { + if (ft_strchr_gnl(data->map[y], c) != -1) + { + xy = ft_calloc(1, sizeof(t_xy)); + xy->x = ft_strchr_gnl(data->map[y], c); + xy->y = y; + break; + } + y++; + } + return (xy); +} + +int get_new_element(t_data *data, int x, int y) +{ + return(data->map[data->y_player + y][data->x_player + x]); +} + +void set_new_element(t_data *data, int x, int y) +{ + data->map[data->y_player + y][data->x_player + x] = '0'; +} + +int end(t_data *data) +{ + if (get_position(data, 'C') == NULL) + quit(data); + return (1); +} + +void set_position_player(t_data *data, t_xy *xy) +{ + data->x_player = xy->x; + data->y_player = xy->y; + free(xy); +} + +void move(t_data *data, int x, int y) +{ + if (get_new_element(data, x, y) == '1') + return ; + if (get_new_element(data, x, y) == 'C') + set_new_element(data, x, y); + if (get_new_element(data, x, y) == 'E') + if (end(data)) + return ; + data->x_player += x; + data->y_player += y; +} + int key_hook(int key, t_data *data) { if (key == K_ESC) quit(data); else if (key == K_LEFT) - data->x_player -= 128; + move(data, -1, 0); else if (key == K_RIGHT) - data->x_player += 128; + move(data, 1, 0); else if (key == K_UP) - data->y_player -= 128; + move(data, 0, -1); else if (key == K_DOWN) - data->y_player += 128; + move(data, 0, 1); data->update = 1; return (0); } -int render(t_data *data) +char *assets(char c) +{ + if (c == '0') + return ("assets/background.xpm"); + else if (c == '1') + return ("assets/wall.xpm"); + else if (c == 'C') + return ("assets/collectible.xpm"); + else if (c == 'E') + return ("assets/exit.xpm"); + return (NULL); +} + +void draw_map(t_data *data) { int x; int y; + x = 0; + while (x < (data->w_screen / data->size)) + { + y = 0; + while (y < (data->h_screen / data->size)) + { + if (x != data->x_player || y != data->y_player) + { + data->mlx_img = mlx_xpm_file_to_image(data->mlx, assets(data->map[y][x]), &data->size, &data->size); + if (!data->mlx_img) + data->mlx_img = mlx_xpm_file_to_image(data->mlx, assets('0'), &data->size, &data->size); + mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, x * data->size, y * data->size); + } + y++; + } + x++; + } +} + +int render(t_data *data) +{ if (data->update == 1) { - x = -1; - while (++x < (data->w_screen / 128)) - { - y = -1; - while (++y < (data->h_screen / 128)) - { - if (x * 128 != data->x_player || y * 128 != data->y_player) - { - data->mlx_img = mlx_xpm_file_to_image(data->mlx, "assets/background.xpm", &data->size, &data->size); - mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, x * 128, y *128); - } - } - } + draw_map(data); data->mlx_img = mlx_xpm_file_to_image(data->mlx, "assets/player.xpm", &data->size, &data->size); - mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, data->x_player, data->y_player); + mlx_put_image_to_window(data->mlx, data->mlx_win, data->mlx_img, data->x_player * data->size, data->y_player * data->size); data->update = 0; } return (0); @@ -81,7 +158,33 @@ void init_data(t_data *data) data->h_screen = 768; data->w_screen = 768; data->mlx = mlx_init(); - data->mlx_win = mlx_new_window(data->mlx, data->w_screen, data->h_screen, "lili meli"); +} + +void get_map(char *argv[], t_data *data) +{ + char *tmp_map; + char *map; + int i; + int fd; + + fd = open(argv[1], O_RDONLY); + if (fd == -1) + return ; + i = 0; + map = NULL; + tmp_map = NULL; + while (i == 0 || tmp_map != NULL) + { + tmp_map = get_next_line(fd); + if (tmp_map && map) + map = ft_strjoin(map, tmp_map); + else if (tmp_map) + map = tmp_map; + i++; + } + data->map = ft_split(map, '\n'); + data->h_screen = (i - 1) * data->size; + data->w_screen = ft_strlen(*data->map) * data->size; } int main(int argc, char *argv[]) @@ -90,8 +193,12 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; - map = get_map(argc, argv); init_data(&data); + get_map(argv, &data); + if (data.map == NULL) + return (1); + set_position_player(&data, get_position(&data, 'P')); + data.mlx_win = mlx_new_window(data.mlx, data.w_screen, data.h_screen, "lili meli"); mlx_hook(data.mlx_win, 17, 0, quit, &data); mlx_key_hook(data.mlx_win, key_hook, &data); mlx_loop_hook(data.mlx, render, &data); diff --git a/so_long.h b/so_long.h index c1a0082..375850f 100644 --- a/so_long.h +++ b/so_long.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/10 17:59:18 by erey-bet #+# #+# */ -/* Updated: 2022/12/11 14:47:20 by erey-bet ### ########.fr */ +/* Updated: 2022/12/12 20:53:26 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,16 @@ # include "key.h" # include # include "libft/libft.h" +# include "get_next_line/get_next_line.h" +# include + typedef struct s_data { void *mlx; void *mlx_win; void *mlx_img; + char **map; int update; int size; int x_player; @@ -32,4 +36,10 @@ typedef struct s_data int w_screen; } t_data; +typedef struct s_xy +{ + int x; + int y; +} t_xy; + #endif diff --git a/so_long.o b/so_long.o new file mode 100644 index 0000000..7ec7a89 Binary files /dev/null and b/so_long.o differ