├── maps ├── min.ber ├── mapmini.ber ├── Bonus │ ├── map_1.ber │ ├── classic.ber │ ├── map_3.ber │ ├── map_4.ber │ ├── map2_enemy.ber │ ├── map_5.ber │ ├── map.ber │ ├── long.ber │ ├── map_6.ber │ ├── map4.ber │ └── run.ber ├── map_0.ber ├── classic.ber ├── CollectibleFail.ber ├── map_empty_line.ber ├── map_42.ber ├── NoExit.ber ├── big.ber └── map3.ber ├── libft ├── ft_isdigit.c ├── ft_isalnum.c ├── ft_tolower.c ├── ft_putchar_fd.c ├── ft_isascii.c ├── ft_isprint.c ├── ft_toupper.c ├── ft_lstadd_front.c ├── ft_isalpha.c ├── ft_lstdelone.c ├── ft_putendl_fd.c ├── ft_bzero.c ├── ft_putstr_fd.c ├── ft_strlen.c ├── ft_lstiter.c ├── ft_lstsize.c ├── ft_calloc.c ├── ft_lstlast.c ├── ft_memset.c ├── ft_lstclear.c ├── ft_lstnew.c ├── ft_lstadd_back.c ├── ft_strdup.c ├── ft_strrchr.c ├── ft_striteri.c ├── ft_memcpy.c ├── ft_memchr.c ├── ft_memmove.c ├── ft_strchr.c ├── ft_memcmp.c ├── ft_strtrim.c ├── ft_strmapi.c ├── ft_strlcpy.c ├── ft_strjoin.c ├── ft_strncmp.c ├── ft_strnstr.c ├── ft_lstmap.c ├── ft_strlcat.c ├── ft_substr.c ├── ft_strjoinfree.c ├── get_next_line.h ├── ft_putnbr_fd.c ├── ft_atoi.c ├── ft_substrfree.c ├── ft_itoa.c ├── Makefile ├── ft_split.c ├── get_next_line.c └── libft.h ├── Bonus ├── src │ ├── ft_free_bonus.c │ ├── generate_map_array_bonus.c │ ├── check_valid_path_bonus.c │ ├── so_long_bonus.c │ ├── errors_bonus.c │ ├── scan_monster_bonus.c │ ├── animation_monster_bonus.c │ ├── end_screen_bonus.c │ ├── key_hook_bonus.c │ ├── file_to_image_bonus.c │ ├── map_printer_bonus.c │ ├── move_animation_bonus.c │ ├── checker_bonus.c │ ├── movements_bonus.c │ └── movements_monster_bonus.c └── inc │ └── so_long_bonus.h ├── Mandatory ├── src │ ├── ft_free.c │ ├── end_screen.c │ ├── generate_map_array.c │ ├── so_long.c │ ├── key_hook.c │ ├── check_valid_path.c │ ├── errors.c │ ├── map_printer.c │ ├── file_to_image.c │ ├── checker.c │ └── movements.c └── inc │ └── so_long.h ├── Resources ├── left-1-40.xpm ├── left-2-40.xpm ├── right-1-40.xpm ├── right-2-40.xpm ├── up-1-40.xpm ├── up-2-40.xpm ├── down-1-40.xpm ├── down-2-40.xpm ├── enemy-2-2.xpm ├── enemy.xpm ├── enemy-1-1.xpm ├── enemy-1-2.xpm ├── wall.xpm ├── empty.xpm ├── door.xpm └── Estrellita.xpm ├── README.md └── Makefile /maps/min.ber: -------------------------------------------------------------------------------- 1 | 11111 2 | 1PCE1 3 | 11111 -------------------------------------------------------------------------------- /maps/mapmini.ber: -------------------------------------------------------------------------------- 1 | 11111 2 | 1CPE1 3 | 11111 -------------------------------------------------------------------------------- /maps/Bonus/map_1.ber: -------------------------------------------------------------------------------- 1 | 111111111 2 | 100C00001 3 | 1P000X0E1 4 | 100C00001 5 | 111111111 -------------------------------------------------------------------------------- /maps/map_0.ber: -------------------------------------------------------------------------------- 1 | 111111111 2 | 100000001 3 | 100010111 4 | 1100P0C11 5 | 1010000E1 6 | 111111111 -------------------------------------------------------------------------------- /maps/classic.ber: -------------------------------------------------------------------------------- 1 | 1111111111111 2 | 1001000000001 3 | 1000011111001 4 | 1P0011E0000C1 5 | 1111111111111 -------------------------------------------------------------------------------- /maps/CollectibleFail.ber: -------------------------------------------------------------------------------- 1 | 1111111111111 2 | 100C000C00001 3 | 1000110000001 4 | 1P010C10000E1 5 | 1111111111111 -------------------------------------------------------------------------------- /maps/map_empty_line.ber: -------------------------------------------------------------------------------- 1 | 2 | 1111111111111 3 | 100100C0000C1 4 | 1C00011111001 5 | 1P0011E000001 6 | 1111111111111 -------------------------------------------------------------------------------- /maps/Bonus/classic.ber: -------------------------------------------------------------------------------- 1 | 1111111111111 2 | 1X010000000X1 3 | 1000011111001 4 | 1P0X11100X0C1 5 | 10001E0000001 6 | 1111111111111 -------------------------------------------------------------------------------- /maps/Bonus/map_3.ber: -------------------------------------------------------------------------------- 1 | 111111111111111 2 | 100000X0000C001 3 | 100C0000P0X0001 4 | 11X1110X0011111 5 | 1E00000C0011111 6 | 111111111111111 -------------------------------------------------------------------------------- /maps/Bonus/map_4.ber: -------------------------------------------------------------------------------- 1 | 11111111111111111111 2 | 100000000000C0000001 3 | 1X000P000C00000000E1 4 | 100000000000000C0001 5 | 11111111111111111111 -------------------------------------------------------------------------------- /maps/Bonus/map2_enemy.ber: -------------------------------------------------------------------------------- 1 | 1111111111111111111111 2 | 1010001111101110101111 3 | 1X101011100C1111111011 4 | 10X0000P00E00000X01111 5 | 1111111111111111111111 -------------------------------------------------------------------------------- /maps/Bonus/map_5.ber: -------------------------------------------------------------------------------- 1 | 11111111111 2 | 1P0000000E1 3 | 10110001101 4 | 1010C000101 5 | 10000100001 6 | 10001110001 7 | 100001X0001 8 | 10100000101 9 | 1C110001101 10 | 100000C0001 11 | 11111111111 -------------------------------------------------------------------------------- /maps/Bonus/map.ber: -------------------------------------------------------------------------------- 1 | 11111111111 2 | 11110C01111 3 | 11110001111 4 | 11110X01111 5 | 11110001111 6 | 10000000001 7 | 1C0X0P0X0E1 8 | 10000000001 9 | 11110X01111 10 | 11110001111 11 | 11110E01111 12 | 11111111111 -------------------------------------------------------------------------------- /maps/map_42.ber: -------------------------------------------------------------------------------- 1 | 1111111111111 2 | 10C10000000C1 3 | 100001000C001 4 | 1P0C01E000001 5 | 1111111111111 6 | 1101101000111 7 | 1101101111011 8 | 1110001000011 9 | 1111101011111 10 | 1111101100011 11 | 1111111111111 12 | 1111111111111 -------------------------------------------------------------------------------- /maps/Bonus/long.ber: -------------------------------------------------------------------------------- 1 | 1111111111111111111111111111111111 2 | 1E0000000000000C000X0C0000000000X1 3 | 10100101001000001010010X0000010101 4 | 1010X1001010101X001001000X00010101 5 | 1P00000X0C00C00000000000000X0000C1 6 | 1111111111111111111111111111111111 -------------------------------------------------------------------------------- /maps/NoExit.ber: -------------------------------------------------------------------------------- 1 | 1111111111111111111111 2 | 1010001111101110101111 3 | 1010101111111111111011 4 | 1000000P00000000001111 5 | 1011101011111010111011 6 | 1111111011101010001011 7 | 1000111011111010111011 8 | 1010101011111110101011 9 | 1110111010001010111011 10 | 1000C00C101010000001E1 11 | 1111111111111111111111 -------------------------------------------------------------------------------- /maps/Bonus/map_6.ber: -------------------------------------------------------------------------------- 1 | 11111111111111111111111 2 | 1C000000000000100000001 3 | 1000000000000000000C001 4 | 11011100X0111100C000001 5 | 1E00000000111100000X001 6 | 111111110X011100P000001 7 | 10000000000001000000001 8 | 10C00000000001000000001 9 | 11011100X0111100000C001 10 | 10000000000C00000000001 11 | 11111111111111111111111 -------------------------------------------------------------------------------- /maps/Bonus/map4.ber: -------------------------------------------------------------------------------- 1 | 1111111111111111111 2 | 1CCCCCCCCCCCCCCCCC1 3 | 1C111111C1C111111C1 4 | 1C1CCCCCC1CCCCCCEC1 5 | 1CCC1C11CCC1101CCC1 6 | 11111C1111111011111 7 | 10CCCC11111110000X1 8 | 1011111111111111111 9 | 1CCCCCCCCCCCCCCCCC1 10 | 1C111111C1C111111C1 11 | 1C1CCCCCC1CCCCCC1C1 12 | 1CCC1C11CCC1101CCC1 13 | 11111C1111111011111 14 | 1PCCCC11111110000X1 15 | 1011111111111111111 16 | 1CCCCCCCCCCCCCCCCC1 17 | 1C111111C1C111111C1 18 | 1C1CCCCCC1CCCCCC1C1 19 | 1CCC1C11CCC1101CCC1 20 | 11111C1111111011111 21 | 10CCCC11111110000X1 22 | 1111111111111111111 -------------------------------------------------------------------------------- /maps/big.ber: -------------------------------------------------------------------------------- 1 | 1111111111111111111111111111111111 2 | 1000000000000000000000000000000001 3 | 10P00000000000000000000000C0000001 4 | 1000000000000000000000000000000001 5 | 10000C0000000000000000000000000001 6 | 1000000000000000000000000000000001 7 | 1000000000000000000000000000000001 8 | 1000000000000000000000000000000001 9 | 100000000C000000000000000000000001 10 | 1000000000000000000000000000000001 11 | 1000000000000000000000000000000001 12 | 1000000000000000000000000000000001 13 | 1000000000000000000C00000000000001 14 | 1000000000000000000000000000000001 15 | 1000000000000000000000000000000001 16 | 10000000000000000000000000000C0001 17 | 1000000000000000000000000000000001 18 | 1000000C00000000000000000000000E01 19 | 1000000000000000000000000000000001 20 | 1111111111111111111111111111111111 -------------------------------------------------------------------------------- /libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n = '0' && c <= '9'); 17 | } 18 | -------------------------------------------------------------------------------- /libft/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n = 65 && c <= 90) 16 | { 17 | c += 32; 18 | } 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n = 0 && c <= 127) 17 | return (1); 18 | else 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n = 32 && c <= 126) 17 | return (1); 18 | else 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n = 97 && c <= 122) 17 | { 18 | c -= 32; 19 | } 20 | return (c); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n next = *lst; 19 | *lst = new; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n = 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) 17 | return (1); 18 | else 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n content); 19 | free(lst); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/11 19:14:00 by jcheel-n #+# #+# */ 9 | /* Updated: 2022/07/14 01:16:58 by josephcheel ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlen(const char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | if (!str) 21 | return (0); 22 | while (str[i] != '\0') 23 | ++i; 24 | return (i); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n content); 22 | ptr = ptr->next; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n next; 23 | } 24 | return (counter); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 0) 22 | lst = lst->next; 23 | return (lst); 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n next; 22 | ft_lstdelone(*lst, del); 23 | *lst = ptr; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n content = content; 22 | str->next = NULL; 23 | return (str); 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n next = new; 23 | } 24 | else 25 | *lst = new; 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n = 0) 22 | { 23 | if (s[i] == (char)c) 24 | return ((char *)(s + i)); 25 | i--; 26 | } 27 | return (NULL); 28 | } 29 | -------------------------------------------------------------------------------- /Bonus/src/ft_free_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_free_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 0) 17 | free(ret[--max]); 18 | free(ret); 19 | return (0); 20 | } 21 | 22 | void ft_exit_free(char *str) 23 | { 24 | free(str); 25 | exit(EXIT_FAILURE); 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 0) 26 | { 27 | if (*str == find) 28 | return (str); 29 | str++; 30 | len--; 31 | } 32 | return (NULL); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n len) 27 | return (ft_strdup("")); 28 | str = ft_substr((char *)s1, i, len - i + 1); 29 | return (str); 30 | } 31 | -------------------------------------------------------------------------------- /Mandatory/src/ft_free.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_free.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 0) 17 | free(ret[--i]); 18 | free(ret); 19 | return (0); 20 | } 21 | 22 | void ft_exit_free(t_map *map) 23 | { 24 | if (map->array) 25 | free(map->array); 26 | if (map->copy) 27 | free(map->copy); 28 | if (map->file) 29 | free(map->file); 30 | if (map->line) 31 | free(map->file); 32 | exit(EXIT_FAILURE); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n needlelen 22 | && ft_strncmp(haystack, needle, needlelen)) 23 | { 24 | haystack++; 25 | len--; 26 | } 27 | if (len >= needlelen && !ft_strncmp(haystack, needle, needlelen)) 28 | return ((char *)haystack); 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n content)); 25 | if (!element) 26 | { 27 | ft_lstclear(&newlst, del); 28 | return (NULL); 29 | } 30 | else 31 | { 32 | ft_lstadd_back(&newlst, element); 33 | ptr = ptr->next; 34 | } 35 | } 36 | return (newlst); 37 | } 38 | -------------------------------------------------------------------------------- /libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n s_len) 24 | return (ft_strdup("")); 25 | if (start + len > s_len) 26 | len = s_len - start; 27 | size = len + 1; 28 | str = (char *) malloc(size * sizeof(char)); 29 | if (!str) 30 | return (NULL); 31 | ft_memcpy(str, s + start, len); 32 | str[len] = '\0'; 33 | return (str); 34 | } 35 | -------------------------------------------------------------------------------- /libft/ft_strjoinfree.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoinfree.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 17 | # include 18 | # include 19 | # include "libft.h" 20 | # define BUFFER_SIZE 1048 21 | 22 | char *get_next_line(int fd); 23 | 24 | // void *ft_memcpy(void *dst, const void *src, size_t n); 25 | // char *ft_strchr(const char *s, int c); 26 | // size_t ft_strlen(char const *str); 27 | //char *ft_substr(char const *s, unsigned int start, size_t len, int freeme); 28 | //char *ft_strjoin(char *s1, char *s2); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n -2147483648 || n <= 2147483647) 17 | { 18 | if (n == -2147483648) 19 | { 20 | ft_putchar_fd('-', fd); 21 | ft_putchar_fd('2', fd); 22 | ft_putnbr_fd(147483648, fd); 23 | return ; 24 | } 25 | else if (n >= 10) 26 | { 27 | ft_putnbr_fd(n / 10, fd); 28 | ft_putnbr_fd(n % 10, fd); 29 | } 30 | else if (n < 0) 31 | { 32 | n = -n; 33 | ft_putchar_fd('-', fd); 34 | ft_putnbr_fd(n, fd); 35 | } 36 | else 37 | ft_putchar_fd(n + '0', fd); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Mandatory/src/end_screen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* end_screen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n mlx, map->wnd); 17 | ft_free_array(map->array, map->y); 18 | exit(EXIT_SUCCESS); 19 | return (0); 20 | } 21 | 22 | void ft_win(t_map *map) 23 | { 24 | map->exit = 1; 25 | map->moves++; 26 | mlx_clear_window(map->mlx, map->wnd); 27 | mlx_string_put(map->mlx, map->wnd, 28 | map->x / 2 * IMG_PXL, map->y / 2 * IMG_PXL, 0xFFFA9E, "YOU WON"); 29 | write(1, "\n", 1); 30 | write(1, "\x1b[32;01m", 9); 31 | write(1, "🏆🏆YOU WON!!🏆🏆\n", 27); 32 | write(1, "\x1b[0m", 5); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n INT_MAX) 38 | return (0); 39 | return (result * sign); 40 | } 41 | -------------------------------------------------------------------------------- /libft/ft_substrfree.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substrfree.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n s_len) 25 | return (malloc(sizeof(char))); 26 | if (start + len > s_len) 27 | len = s_len - start; 28 | size = len + 1; 29 | str = (char *) malloc(size * sizeof(char)); 30 | if (!str) 31 | return (NULL); 32 | ft_memcpy(str, s + start, len); 33 | str[len] = '\0'; 34 | if (freeme == 1) 35 | free((void *)s); 36 | return (str); 37 | } 38 | -------------------------------------------------------------------------------- /Bonus/src/generate_map_array_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* generate_map_array_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n y = 0; 21 | line = ""; 22 | file = NULL; 23 | fd = open(map->filename, O_RDONLY); 24 | if (fd == -1) 25 | error_openfile(); 26 | while (line) 27 | { 28 | line = get_next_line(fd); 29 | if (line == NULL) 30 | break ; 31 | file = ft_strjoinfree(file, line); 32 | if (file == NULL) 33 | free(file); 34 | free(line); 35 | map->y++; 36 | } 37 | close(fd); 38 | map->array = ft_split(file, '\n'); 39 | map->copy = ft_split(file, '\n'); 40 | free(file); 41 | } 42 | -------------------------------------------------------------------------------- /Resources/left-1-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "26 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXX oo", 18 | " XXXXXXXXXXXXXXXXXXXXXX ", 19 | " XXXXXXXXXXXXXXXXXXXXXX ", 20 | " XXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXX ", 23 | " XXXXXXXXXXXXXXXXXXXXXX ", 24 | " ..XXXX XXXXXXXXXXXX.. ", 25 | " ..XXXX XXXXXXXXXXXX.. ", 26 | "oo XXXX XXXXXXXXXXXX oo", 27 | "oo XXXX XXXXXXXXXXXX oo", 28 | "oo ..XXXXXXXXXXXXXX.. oo", 29 | "oo ..XXXXXXXXXXXXXX.. oo", 30 | "oooo ..XXXXXXXXXX.. oooo", 31 | "oooo ..XXXXXXXXXX.. oooo", 32 | "oooooo ..XXXX.. oooooo", 33 | "oooooo ..XXXX.. oooooo", 34 | "oooo ..XXXXXX oooooo", 35 | "oooo ..XXXXXX oooooo", 36 | "oooo XXXXXX XX.. oooo", 37 | "oooo XXXXXX XX.. oooo", 38 | "oooooo XXXXXX XXXX oooo", 39 | "oooooo XXXXXX XXXX oooo", 40 | "oooo XXXXXX.... oooooo", 41 | "oooo XXXXXX.... oooooo", 42 | "oo ..XX.... ...... oooo", 43 | "oo ..XX.... ...... oooo", 44 | "oo ...... .... oooo", 45 | "oo ...... .... oooo", 46 | "oooo oooooo oooooo", 47 | "oooo oooooo oooooo", 48 | "oooooooooooooooooooooooooo", 49 | "oooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /Resources/left-2-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "26 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXX oo", 18 | " XXXXXXXXXXXXXXXXXXXXXX ", 19 | " XXXXXXXXXXXXXXXXXXXXXX ", 20 | " XXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXX ", 23 | " XXXXXXXXXXXXXXXXXXXXXX ", 24 | " ..XXXX XXXXXXXXXXXX.. ", 25 | " ..XXXX XXXXXXXXXXXX.. ", 26 | "oo XXXX XXXXXXXXXXXX oo", 27 | "oo XXXX XXXXXXXXXXXX oo", 28 | "oo ..XXXXXXXXXXXXXX.. oo", 29 | "oo ..XXXXXXXXXXXXXX.. oo", 30 | "oooo ..XXXXXXXXXX.. oooo", 31 | "oooo ..XXXXXXXXXX.. oooo", 32 | "oooooo ..XX.. oooooo", 33 | "oooooo ..XX.. oooooo", 34 | "oooo XX.. XXXX.. oooooo", 35 | "oooo XX.. XXXX.. oooooo", 36 | "oooo XXXX XXXX.. oooo", 37 | "oooo XXXX XXXX.. oooo", 38 | "oooooo ..XX.... oooo", 39 | "oooooo ..XX.... oooo", 40 | "oooooo ........ oooooo", 41 | "oooooo ........ oooooo", 42 | "oooo XX.. ...... oooo", 43 | "oooo XX.. ...... oooo", 44 | "oooo .... .... oooo", 45 | "oooo .... .... oooo", 46 | "oooooo oooooo oooooo", 47 | "oooooo oooooo oooooo", 48 | "oooooooooooooooooooooooooo", 49 | "oooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /Resources/right-1-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "26 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXX oo", 18 | " XXXXXXXXXXXXXXXXXXXXXX ", 19 | " XXXXXXXXXXXXXXXXXXXXXX ", 20 | " XXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXX ", 23 | " XXXXXXXXXXXXXXXXXXXXXX ", 24 | " ..XXXXXXXXXXXX XXXX.. ", 25 | " ..XXXXXXXXXXXX XXXX.. ", 26 | "oo XXXXXXXXXXXX XXXX oo", 27 | "oo XXXXXXXXXXXX XXXX oo", 28 | "oo ..XXXXXXXXXXXXXX.. oo", 29 | "oo ..XXXXXXXXXXXXXX.. oo", 30 | "oooo ..XXXXXXXXXX.. oooo", 31 | "oooo ..XXXXXXXXXX.. oooo", 32 | "oooooo ..XX.. oooooo", 33 | "oooooo ..XX.. oooooo", 34 | "oooooo ..XXXX ..XX oooo", 35 | "oooooo ..XXXX ..XX oooo", 36 | "oooo ..XXXX XXXX oooo", 37 | "oooo ..XXXX XXXX oooo", 38 | "oooo ....XX.. oooooo", 39 | "oooo ....XX.. oooooo", 40 | "oooooo ........ oooooo", 41 | "oooooo ........ oooooo", 42 | "oooo ...... ..XX oooo", 43 | "oooo ...... ..XX oooo", 44 | "oooo .... .... oooo", 45 | "oooo .... .... oooo", 46 | "oooooo oooooo oooooo", 47 | "oooooo oooooo oooooo", 48 | "oooooooooooooooooooooooooo", 49 | "oooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /Resources/right-2-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "26 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXX oo", 18 | " XXXXXXXXXXXXXXXXXXXXXX ", 19 | " XXXXXXXXXXXXXXXXXXXXXX ", 20 | " XXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXX ", 23 | " XXXXXXXXXXXXXXXXXXXXXX ", 24 | " ..XXXXXXXXXXXX XXXX.. ", 25 | " ..XXXXXXXXXXXX XXXX.. ", 26 | "oo XXXXXXXXXXXX XXXX oo", 27 | "oo XXXXXXXXXXXX XXXX oo", 28 | "oo ..XXXXXXXXXXXXXX.. oo", 29 | "oo ..XXXXXXXXXXXXXX.. oo", 30 | "oooo ..XXXXXXXXXX.. oooo", 31 | "oooo ..XXXXXXXXXX.. oooo", 32 | "oooooo ..XXXX.. oooooo", 33 | "oooooo ..XXXX.. oooooo", 34 | "oooooo XXXXXX.. oooo", 35 | "oooooo XXXXXX.. oooo", 36 | "oooo ..XX XXXXXX oooo", 37 | "oooo ..XX XXXXXX oooo", 38 | "oooo XXXX XXXXXX oooooo", 39 | "oooo XXXX XXXXXX oooooo", 40 | "oooooo ....XXXXXX oooo", 41 | "oooooo ....XXXXXX oooo", 42 | "oooo ...... ....XX.. oo", 43 | "oooo ...... ....XX.. oo", 44 | "oooo .... ...... oo", 45 | "oooo .... ...... oo", 46 | "oooooo oooooo oooo", 47 | "oooooo oooooo oooo", 48 | "oooooooooooooooooooooooooo", 49 | "oooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /Resources/up-1-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "27 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXXX oo", 18 | " ..XXXXXXXXXXXXXXXXXXX.. ", 19 | " ..XXXXXXXXXXXXXXXXXXX.. ", 20 | " XXXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXXX ", 23 | " ..XXXXXXXXXXXXXXXXXXX.. ", 24 | " ..XXXXXXXXXXXXXXXXXXX.. ", 25 | "oo XXXXXXXXXXXXXXXXXXX oo", 26 | "oo XXXXXXXXXXXXXXXXXXX oo", 27 | "oo ..XXXXXXXXXXXXXXX.. oo", 28 | "oo ..XXXXXXXXXXXXXXX.. oo", 29 | "oooo ..XXXXXXXXXXX.. oooo", 30 | "oooo ..XXXXXXXXXXX.. oooo", 31 | "oo ..XXXXXXXXXXXXXXXXX oo", 32 | "oo ..XXXXXXXXXXXXXXXXX oo", 33 | "oo .. XXXXXXXXX XXXX oo", 34 | "oo .. XXXXXXXXX XXXX oo", 35 | "oooo XXXXXXXXX ..XX oo", 36 | "oooo XXXXXXXXX ..XX oo", 37 | "oooooo XXXXXXXXX .... oo", 38 | "oooooo XXXXXXXXX .... oo", 39 | "oooooo XXXX....... oooo", 40 | "oooooo XX.. .... oooooo", 41 | "oooooo XX.. .... oooooo", 42 | "oooooo .... o oooooooo", 43 | "oooooo .... o oooooooo", 44 | "oooooooo ooooooooooooooo", 45 | "oooooooo ooooooooooooooo", 46 | "ooooooooooooooooooooooooooo", 47 | "ooooooooooooooooooooooooooo", 48 | "ooooooooooooooooooooooooooo", 49 | "ooooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /Resources/up-2-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "27 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXXX oo", 18 | " ..XXXXXXXXXXXXXXXXXXX.. ", 19 | " ..XXXXXXXXXXXXXXXXXXX.. ", 20 | " XXXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXXX ", 23 | " ..XXXXXXXXXXXXXXXXXXX.. ", 24 | " ..XXXXXXXXXXXXXXXXXXX.. ", 25 | "oo XXXXXXXXXXXXXXXXXXX oo", 26 | "oo XXXXXXXXXXXXXXXXXXX oo", 27 | "oo ..XXXXXXXXXXXXXXX.. oo", 28 | "oo ..XXXXXXXXXXXXXXX.. oo", 29 | "oooo ..XXXXXXXXXXX.. oooo", 30 | "oooo ..XXXXXXXXXXX.. oooo", 31 | "oo XXXXXXXXXXXXXXXXX.. oo", 32 | "oo XXXXXXXXXXXXXXXXX.. oo", 33 | "oo XXXX XXXXXXXXX .. oo", 34 | "oo XXXX XXXXXXXXX .. oo", 35 | "oo XX.. XXXXXXXXX oooo", 36 | "oo XX.. XXXXXXXXX oooo", 37 | "oo .... XXXXXXXXX oooooo", 38 | "oo .... XXXXXXXXX oooooo", 39 | "oooo .......XXXX oooooo", 40 | "oooooo .... ..XX oooooo", 41 | "oooooo .... ..XX oooooo", 42 | "oooooooo oo .... oooooo", 43 | "oooooooo oo .... oooooo", 44 | "ooooooooooooooo oooooooo", 45 | "ooooooooooooooo oooooooo", 46 | "ooooooooooooooooooooooooooo", 47 | "ooooooooooooooooooooooooooo", 48 | "ooooooooooooooooooooooooooo", 49 | "ooooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /Mandatory/src/generate_map_array.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* generate_map_array.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n y = 0; 20 | map->line = ""; 21 | map->file = NULL; 22 | fd = open(map->filename, O_RDONLY); 23 | if (fd == -1) 24 | error_openfile(); 25 | while (map->line) 26 | { 27 | map->line = get_next_line(fd); 28 | if (map->line == NULL) 29 | break ; 30 | map->file = ft_strjoinfree(map->file, map->line); 31 | free(map->line); 32 | if (!map->file) 33 | ft_exit_free(map); 34 | map->y++; 35 | } 36 | close(fd); 37 | map->array = ft_split(map->file, '\n'); 38 | map->copy = ft_split(map->file, '\n'); 39 | if (!map->array || !map->copy) 40 | ft_exit_free(map); 41 | free(map->file); 42 | } 43 | -------------------------------------------------------------------------------- /Resources/down-1-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "28 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXXXX oo", 18 | " ..XXXXXXXXXXXXXXXXXXXX.. ", 19 | " ..XXXXXXXXXXXXXXXXXXXX.. ", 20 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 23 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 24 | " ..XXXX XXXXXXXX XXXX.. ", 25 | " ..XXXX XXXXXXXX XXXX.. ", 26 | "oo XXXX XXXXXXXX XXXX oo", 27 | "oo XXXX XXXXXXXX XXXX oo", 28 | "oo ..XXXXXXXXXXXXXXXX.. oo", 29 | "oo ..XXXXXXXXXXXXXXXX.. oo", 30 | "oooo ..XXXXXXXXXXXX.. oooo", 31 | "oooo ..XXXXXXXXXXXX.. oooo", 32 | "oo XXXXXXXXXXXXXXXXXX.. oo", 33 | "oo XXXXXXXXXXXXXXXXXX.. oo", 34 | "oo XXXX XXXXXXXXXX .. oo", 35 | "oo XXXX XXXXXXXXXX .. oo", 36 | "oo XX.. XXXXXXXXXX oooo", 37 | "oo XX.. XXXXXXXXXX oooo", 38 | "oo .... XXXXXXXXXX oooooo", 39 | "oo .... XXXXXXXXXX oooooo", 40 | "oooo ........XXXX oooooo", 41 | "oooo ........XXXX oooooo", 42 | "oooooo .... ..XX oooooo", 43 | "oooooo .... ..XX oooooo", 44 | "oooooooo oo .... oooooo", 45 | "oooooooo oo .... oooooo", 46 | "oooooooooooooooo oooooooo", 47 | "oooooooooooooooo oooooooo", 48 | "oooooooooooooooooooooooooooo", 49 | "oooooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /Resources/down-2-40.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "28 40 4 1 ", 5 | " c gray9", 6 | ". c #BFA787", 7 | "X c #E8D4B2", 8 | "o c None", 9 | /* pixels */ 10 | "oooooooo oooooooo", 11 | "oooooooo oooooooo", 12 | "oooo XXXXXXXXXXXX oooo", 13 | "oooo XXXXXXXXXXXX oooo", 14 | "oo XXXXXXXXXXXXXXXXXXXX oo", 15 | "oo XXXXXXXXXXXXXXXXXXXX oo", 16 | "oo XXXXXXXXXXXXXXXXXXXX oo", 17 | "oo XXXXXXXXXXXXXXXXXXXX oo", 18 | " ..XXXXXXXXXXXXXXXXXXXX.. ", 19 | " ..XXXXXXXXXXXXXXXXXXXX.. ", 20 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 21 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 22 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 23 | " XXXXXXXXXXXXXXXXXXXXXXXX ", 24 | " ..XXXX XXXXXXXX XXXX.. ", 25 | " ..XXXX XXXXXXXX XXXX.. ", 26 | "oo XXXX XXXXXXXX XXXX oo", 27 | "oo XXXX XXXXXXXX XXXX oo", 28 | "oo ..XXXXXXXXXXXXXXXX.. oo", 29 | "oo ..XXXXXXXXXXXXXXXX.. oo", 30 | "oooo ..XXXXXXXXXXXX.. oooo", 31 | "oooo ..XXXXXXXXXXXX.. oooo", 32 | "oo ..XXXXXXXXXXXXXXXXXX oo", 33 | "oo ..XXXXXXXXXXXXXXXXXX oo", 34 | "oo .. XXXXXXXXXX XXXX oo", 35 | "oo .. XXXXXXXXXX XXXX oo", 36 | "oooo XXXXXXXXXX ..XX oo", 37 | "oooo XXXXXXXXXX ..XX oo", 38 | "oooooo XXXXXXXXXX .... oo", 39 | "oooooo XXXXXXXXXX .... oo", 40 | "oooooo XXXX........ oooo", 41 | "oooooo XXXX........ oooo", 42 | "oooooo XX.. .... oooooo", 43 | "oooooo XX.. .... oooooo", 44 | "oooooo .... oo oooooooo", 45 | "oooooo .... oo oooooooo", 46 | "oooooooo oooooooooooooooo", 47 | "oooooooo oooooooooooooooo", 48 | "oooooooooooooooooooooooooooo", 49 | "oooooooooooooooooooooooooooo" 50 | }; 51 | -------------------------------------------------------------------------------- /libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n INT_MAX || n < INT_MIN) 40 | return (NULL); 41 | str[lenght] = '\0'; 42 | if (n < 0) 43 | { 44 | str[0] = '-'; 45 | i = 1; 46 | } 47 | else 48 | i = 0; 49 | while (lenght-- > i) 50 | { 51 | if (n < 0) 52 | str[lenght] = 48 + (n % 10) * (-1); 53 | else 54 | str[lenght] = (n % 10) + 48; 55 | n = n / 10; 56 | } 57 | return (str); 58 | } 59 | -------------------------------------------------------------------------------- /Mandatory/src/so_long.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* so_long.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: josephcheel +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/13 15:55:50 by jcheel-n #+# #+# */ 9 | /* Updated: 2022/07/21 14:39:12 by jcheel-n ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../inc/so_long.h" 14 | 15 | void map_initializer(t_map *map, char **av) 16 | { 17 | map->filename = av[1]; 18 | map->moves = 0; 19 | map->e = 0; 20 | map->c = 0; 21 | map->p = 0; 22 | map->y = 0; 23 | map->player.y = 0; 24 | map->player.x = 0; 25 | map->exit = 0; 26 | } 27 | 28 | int main(int ac, char **av) 29 | { 30 | t_map map; 31 | 32 | if (ac == 2) 33 | { 34 | map_initializer(&map, av); 35 | map_checker(&map); 36 | map.mlx = mlx_init(); 37 | map.wnd = mlx_new_window(map.mlx, map.x 38 | * IMG_PXL, map.y * IMG_PXL, WND_NAME); 39 | file_to_image(&map); 40 | map_printer(&map); 41 | mlx_hook(map.wnd, 17, 0, ft_close, &map); 42 | mlx_key_hook(map.wnd, key_hook, &map); 43 | mlx_loop(map.mlx); 44 | } 45 | write(2, "\033[1;31m🛑ERROR:", 18); 46 | write(2, "Usage: ./so_long mapfile\n\033[0m", 30); 47 | exit(EXIT_FAILURE); 48 | } 49 | -------------------------------------------------------------------------------- /Mandatory/src/key_hook.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key_hook.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n player.y = 0; 17 | map->player.x = 0; 18 | while (map->player.y < map->y) 19 | { 20 | while (map->player.x < map->x) 21 | { 22 | if (map->array[map->player.y][map->player.x] == 'P') 23 | break ; 24 | map->player.x++; 25 | } 26 | if (map->array[map->player.y][map->player.x] == 'P') 27 | break ; 28 | map->player.x = 0; 29 | map->player.y++; 30 | } 31 | } 32 | 33 | int key_hook(int keycode, t_map *map) 34 | { 35 | scan_player(map); 36 | if (keycode == ESC) 37 | return (ft_close(map)); 38 | else if (map->exit == 1) 39 | return (0); 40 | else if (keycode == LEFT) 41 | move_left(map); 42 | else if (keycode == DOWN) 43 | move_down(map); 44 | else if (keycode == RIGHT) 45 | move_right(map); 46 | else if (keycode == UP) 47 | move_up(map); 48 | return (0); 49 | } 50 | -------------------------------------------------------------------------------- /libft/Makefile: -------------------------------------------------------------------------------- 1 | NAME = libft.a 2 | 3 | SRCS = ft_strlcat.c ft_substr.c ft_atoi.c ft_strdup.c ft_calloc.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isprint.c ft_strlen.c ft_memset.c ft_isascii.c ft_bzero.c ft_memcpy.c ft_toupper.c ft_tolower.c ft_strchr.c ft_memcmp.c ft_memchr.c ft_isdigit.c ft_strrchr.c ft_strncmp.c ft_strlcpy.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_strjoin.c ft_strtrim.c ft_itoa.c ft_strmapi.c ft_striteri.c ft_memmove.c ft_split.c ft_strnstr.c ft_substr.c 4 | 5 | SRCS_EXTRA = ft_substrfree.c ft_strjoinfree.c get_next_line.c 6 | BONUS = 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 7 | 8 | BONUS_OBJS = ${BONUS:.c=.o} 9 | 10 | OBJS = ${SRCS:.c=.o} $(SRCS_EXTRA:.c=.o) 11 | 12 | CC = gcc 13 | 14 | CFLAGS = -Wall -Werror -Wextra 15 | 16 | RM = rm -f 17 | 18 | .c.o: 19 | $(CC) $(CFLAGS) -c $< -o $(<:.c=.o) 20 | 21 | $(NAME): $(OBJS) $(BONUS_OBJS) 22 | ar rcs $(NAME) $(OBJS) $(BONUS_OBJS) 23 | @echo "$(OK_COLOR)libft compiled!$(NO_COLOR)" 24 | 25 | all: $(NAME) 26 | 27 | bonus: ${BONUS_OBJS} ${OBJS} 28 | ar rcs ${NAME} ${BONUS_OBJS} ${OBJS} 29 | clean: 30 | $(RM) $(OBJS) $(BONUS_OBJS) 31 | 32 | fclean: clean 33 | $(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | 39 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 40 | #•❅──────✧❅✦❅✧──────❅••❅──────✧❅✦❅✧─COLOR──✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──────❅•# 41 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 42 | 43 | NO_COLOR=\x1b[0m 44 | OK_COLOR=\x1b[32;01m 45 | ERROR_COLOR=\x1b[31;01m 46 | WARN_COLOR=\x1b[33;01m 47 | 48 | OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR) 49 | ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR) 50 | WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR) 51 | 52 | 53 | -------------------------------------------------------------------------------- /Bonus/src/check_valid_path_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* check_valid_path_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n copy[y][x]; 19 | if (type == 'C') 20 | map->c_check -= 1; 21 | else if (type == 'E') 22 | map->e_check -= 1; 23 | else if (type == '0' || type == 'P' || type == 'X') 24 | ; 25 | else 26 | return ; 27 | map->copy[y][x] = '1'; 28 | move_on_paths(x + 1, y, map); 29 | move_on_paths(x - 1, y, map); 30 | move_on_paths(x, y + 1, map); 31 | move_on_paths(x, y - 1, map); 32 | } 33 | 34 | void check_valid_path(t_map *map) 35 | { 36 | int x; 37 | int y; 38 | 39 | map->c_check = map->c; 40 | map->e_check = map->e; 41 | scan_player(map); 42 | x = map->player.x; 43 | y = map->player.y; 44 | move_on_paths(x, y, map); 45 | if (map->c_check != 0 || map->e_check == map->e) 46 | { 47 | write(2, "\033[1;31m🛑ERROR: ", 19); 48 | write(2, "NO VALID PATH\n\033[0m", 19); 49 | ft_free_array(map->array, map->y); 50 | ft_free_array(map->copy, map->y); 51 | exit(EXIT_FAILURE); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Mandatory/src/check_valid_path.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* check_valid_path.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n copy[y][x]; 19 | if (type == 'C') 20 | { 21 | map->c_check -= 1; 22 | map->copy[y][x] = '1'; 23 | } 24 | else if (type == 'E') 25 | { 26 | map->e_check -= 1; 27 | map->copy[y][x] = '1'; 28 | } 29 | else if (type == '0' || type == 'P') 30 | map->copy[y][x] = '1'; 31 | else 32 | return ; 33 | move_on_paths(x + 1, y, map); 34 | move_on_paths(x - 1, y, map); 35 | move_on_paths(x, y + 1, map); 36 | move_on_paths(x, y - 1, map); 37 | } 38 | 39 | void check_valid_path(t_map *map) 40 | { 41 | map->c_check = map->c; 42 | map->e_check = map->e; 43 | scan_player(map); 44 | move_on_paths(map->player.x, map->player.y, map); 45 | if (map->c_check != 0 || map->e_check >= map->e) 46 | { 47 | write(2, "\033[1;31m🛑ERROR: ", 19); 48 | write(2, "NO VALID PATH\n\033[0m", 19); 49 | ft_free_array(map->array, map->y); 50 | ft_free_array(map->copy, map->y); 51 | exit(EXIT_FAILURE); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Bonus/src/so_long_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* so_long_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: josephcheel +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/13 15:55:50 by jcheel-n #+# #+# */ 9 | /* Updated: 2022/09/30 13:56:36 by jcheel-n ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | #include "../inc/so_long_bonus.h" 13 | 14 | void map_initializer(t_map *map) 15 | { 16 | map->moves = 0; 17 | map->z = 0; 18 | map->action = 0; 19 | map->enemy.pos = 0; 20 | map->enemy.nbr = 0; 21 | map->e = 0; 22 | map->c = 0; 23 | map->p = 0; 24 | map->y = 0; 25 | map->player.y = 0; 26 | map->player.x = 0; 27 | map->exit = 0; 28 | } 29 | 30 | int main(int ac, char **av) 31 | { 32 | t_map map; 33 | 34 | if (ac == 2) 35 | { 36 | map.filename = av[1]; 37 | map_initializer(&map); 38 | map_checker(&map); 39 | map.mlx = mlx_init(); 40 | map.wnd = mlx_new_window(map.mlx, map.x * IMG_PXL, 41 | map.y * IMG_PXL + IMG_PXL * 1.25, WND_NAME); 42 | map_printer(&map); 43 | scan_monster(&map); 44 | if (map.enemy.nbr > 0) 45 | mlx_loop_hook(map.mlx, move_monster, &map); 46 | mlx_hook(map.wnd, 17, 0, ft_close, &map); 47 | mlx_key_hook(map.wnd, key_hook, &map); 48 | mlx_loop(map.mlx); 49 | } 50 | write(2, "\033[1;31m🛑ERROR: ", 19); 51 | write(2, "Usage: ./so_long mapfile\n\033[0m", 30); 52 | exit(EXIT_FAILURE); 53 | } 54 | -------------------------------------------------------------------------------- /Mandatory/src/errors.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* errors.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n array, map->y); 27 | ft_free_array(map->copy, map->y); 28 | exit(EXIT_FAILURE); 29 | } 30 | 31 | void error_openfile(void) 32 | { 33 | write(2, "\033[1;31m🛑ERROR: ", 19); 34 | write(2, "failed open\n\033[0m", 17); 35 | exit(EXIT_FAILURE); 36 | } 37 | 38 | void error_size(t_map *map) 39 | { 40 | write(2, "\033[1;31m🛑ERROR: ", 19); 41 | write(2, "failed size\n\033[0m", 17); 42 | ft_free_array(map->array, map->y); 43 | ft_free_array(map->copy, map->y); 44 | exit(EXIT_FAILURE); 45 | } 46 | 47 | void error_map_elements(t_map *map) 48 | { 49 | write(2, "\033[1;31m🛑ERROR: ", 19); 50 | write(2, "failed elements\n\033[0m", 21); 51 | ft_free_array(map->array, map->y); 52 | ft_free_array(map->copy, map->y); 53 | exit(EXIT_FAILURE); 54 | } 55 | -------------------------------------------------------------------------------- /Bonus/src/errors_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* errors_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n array, map->y); 26 | ft_free_array(map->copy, map->y); 27 | exit(EXIT_FAILURE); 28 | } 29 | 30 | void error_openfile(void) 31 | { 32 | write(2, "\033[1;31m🛑ERROR: ", 19); 33 | write(2, "failed open\n\033[0m", 17); 34 | exit(EXIT_FAILURE); 35 | } 36 | 37 | void error_size(t_map *map) 38 | { 39 | write(2, "\033[1;31m🛑ERROR: ", 19); 40 | write(2, "failed size\n\033[0m", 17); 41 | ft_free_array(map->array, map->y); 42 | ft_free_array(map->copy, map->y); 43 | exit(EXIT_FAILURE); 44 | } 45 | 46 | void error_map_elements(t_map *map) 47 | { 48 | write(2, "\033[1;31m🛑ERROR: ", 19); 49 | write(2, "failed elements\n\033[0m", 21); 50 | ft_free_array(map->array, map->y); 51 | ft_free_array(map->copy, map->y); 52 | exit(EXIT_FAILURE); 53 | } 54 | -------------------------------------------------------------------------------- /Resources/enemy-2-2.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "40 40 6 1 ", 5 | " c #04193F", 6 | ". c #780BF7", 7 | "X c #D840FB", 8 | "o c #F489F6", 9 | "O c #FCFEFE", 10 | "+ c None", 11 | /* pixels */ 12 | "++++++++++++++++++++++++++++++++++++++++", 13 | "++++++++++++++++++++++++++++++++++++++++", 14 | "++++++++++++++++++++++++++++++++++++++++", 15 | "++++++++++++++++++++++++++++++++++++++++", 16 | "++++++++++++++++++++++++++++++++++++++++", 17 | "++++++++++++++++++++++++++++++++++++++++", 18 | "+++++++++ + +++++++++++++++++++", 19 | "+++++++++ + +++++++++++++++++++", 20 | "+++++++ ooooooo .... ++++++++++++++++", 21 | "+++++++ ooooooXXXXX.... +++++++++++++++", 22 | "+++++++++ XXXoooooXXX... ++++++++++++++", 23 | "+++++++++ XoooooooooXXXX. ++++++++++++++", 24 | "+++++++++ XoooooooooXXXX. ++++++++++++++", 25 | "+++++++++ ooooooOOOOOOOO.. +++++++++++++", 26 | "+++++++ XoooooOOOOOOOOOO. +++++++++++++", 27 | "+++++++ oooooOO OOOO . +++++++++++", 28 | "+++++++ oooooO OOO O O +++++++++++", 29 | "+++++++ oooooO OOO O O +++++++++++", 30 | "+++++++ oooooO OOO O O +++++++++++", 31 | "+++++++ oooooO OOO O O +++++++++++", 32 | "+++++++ XoooooO OOOO . +++++++++++", 33 | "+++++++++ oooooOOOOOOOOOOO +++++++++++++", 34 | "+++++++++ oooooOOOOOOOOOOO +++++++++++++", 35 | "+++++++++ XoooooXOOOOOOOO. ++ ++++", 36 | "+++++++++ oooooooXXXX.... ....... +++", 37 | "+++++++ ooooooooooOOO.............. +++", 38 | "++++++ ooooooo.ooOOOOO.............. +++", 39 | "++++++ ooooooo.ooOOOOO.............. +++", 40 | "++++++ ooooo..XooOOOOOOO........... ++++", 41 | "+++++ ooooo.XXXoOOOOOOOO........... ++++", 42 | "+++++ ooooo.XXooOOOOOOOO. .... +++++", 43 | "+++++ oooo.XXXooOOOOOOOO +++++ ++++++", 44 | "+++++ oooo.XXXooOOOOOOOO +++++ ++++++", 45 | "++++++ .XooooOOOOOOOO +++++++++++++++", 46 | "++++++++++ ooooooOOOOO.. +++++++++++++++", 47 | "+++++++++ oooooooXXXX... +++++++++++++++", 48 | "+++++++++ ooooo ... ++++++++++++++++", 49 | "+++++++++ ooooo ... ++++++++++++++++", 50 | "+++++++ ooooo + ..... ++++++++++++++++", 51 | "+++++++ ooo ++ .... ++++++++++++++++++" 52 | }; 53 | -------------------------------------------------------------------------------- /Resources/enemy.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "40 40 6 1 ", 5 | " c #04193F", 6 | ". c #780BF7", 7 | "X c #D840FB", 8 | "o c #F489F6", 9 | "O c #FCFEFE", 10 | "+ c None", 11 | /* pixels */ 12 | "++++++++++++++++++++++++++++++++++++++++", 13 | "++++++++++++++++++++++++++++++++++++++++", 14 | "++++++++++++++++++++++++++++++++++++++++", 15 | "++++++++++++++++++++++++++++++++++++++++", 16 | "++++++++++++++++++++++++++++++++++++++++", 17 | "+++++++++++++ +++++++ ++++++++++++++++", 18 | "+++++++++++ oo ++++ .. +++++++++++++++", 19 | "++++++++++ ooooo .... +++++++++++++++", 20 | "++++++++++ ooooo .... +++++++++++++++", 21 | "++++++++++ ooooooo ..... ++++++++++++++", 22 | "+++++++++++ oooXXXXXX... ++++++++++++++", 23 | "+++++++++++ XooooooXXXX.. +++++++++++++", 24 | "+++++++++++ XooooooXXXX.. +++++++++++++", 25 | "++++++++++ XXoooooooooXXX. +++++++++++++", 26 | "++++++++++ oooooooOOOOOOO.. +++++++++++", 27 | "+++++++++ XoooooOOOOOOOOOO. +++++++++++", 28 | "+++++++++ oooooOOO OOO .. ++++++++++", 29 | "+++++++++ oooooOOO OOO .. ++++++++++", 30 | "+++++++++ oooooO OOOOOO O ++++++++++", 31 | "+++++++++ oooooO OOOOOO O ++++++++++", 32 | "+++++++++ oooooO OO ++++++++++", 33 | "+++++++++ oooooO OO ++++++++++", 34 | "++++++++++ oooooOOOOOOOOOOO +++++++++++", 35 | "++++++++++ oooooOOOOOOOOOOO +++++++++++", 36 | "++++++++++ XXoooooOOOOOOOO. +++++++++++", 37 | "+++++++++++ oooooXXXX.... +++++++++++++", 38 | "+++++++++++ oooooooOOOO. ++++++++++++++", 39 | "++++++++++ ooooo..OOOOOO.. +++++++++++++", 40 | "++++++++++ ooooo..OOOOOO.. +++++++++++++", 41 | "++++++++++ ooooo..OOOOOOO. +++++++++++++", 42 | "+++++++++ ooooo.XXOOOOOOO.. +++++++++++", 43 | "+++++++++ ooooo.XXOOOOOOO.. +++++++++++", 44 | "+++++++++ ooooo.XXOOOOOOO.. +++++++++++", 45 | "+++++++++ oooo.XooOOOOOOO.. +++++++++++", 46 | "++++++++++ ...XXooOOOOOO. +++++++++++++", 47 | "+++++++++++ XXoooXXXX... ++++++++++++++", 48 | "+++++++++++ ooooo ..... ++++++++++++++", 49 | "+++++++++++ ooooo ..... ++++++++++++++", 50 | "+++++++++++ ooo .... +++++++++++++++", 51 | "+++++++++++ ooo .... +++++++++++++++" 52 | }; 53 | -------------------------------------------------------------------------------- /maps/map3.ber: -------------------------------------------------------------------------------- 1 | 111111111111111111111111111111111111111111111111111111111111 2 | 1E00000000000000000000000000000000000000000000000000000000E1 3 | 100000000000000000000000000000000000000000000000000000000001 4 | 100000000000000000000000000000000000000000000000000000000001 5 | 100000000C00000000000000000000000000000000000000000000000001 6 | 100000000000000000000000000000000000000000000000000000000001 7 | 100000000000000000000000000000000000000000000000000000000001 8 | 100000000000000000000000000000000000000000000000000000000001 9 | 100000000000000000000000000000000000000000000000000000000001 10 | 100000000000000000000000000000000000000000000000000000000001 11 | 100000000000000000000000000000000000000000000000000000000001 12 | 10000000000000000000000000000000000C000000000000000000000001 13 | 100000000000000000000000000000000000000000000000000000000001 14 | 100000000000000000000000000000000000000010000000000000000001 15 | 10000000000000000000C000000000000000000010000000000000000001 16 | 100000000000000000000000000000000000000010000000000000000001 17 | 100000000000000000000000000000000000000010000000000000000001 18 | 100000000000011111000000000000000000000010000000000000000001 19 | 100000000000000000000000000000000000000010000000000000000001 20 | 1000000000000000000000000000000000000000C0000000000000000001 21 | 100000000000000000000000000000000000000000000000000000000001 22 | 100000000000000000000000000000000000000000000000000000000001 23 | 100000000000000C00000000000000000000000000000000000000000001 24 | 100000000000000000000000000000000000000000000000000000000001 25 | 100000000000000000000000000000000000000000000000000000000001 26 | 1C0000000000000000000000000000000000000000000000000000000001 27 | 1C0000000000000000000000000000000000000000000000000000000001 28 | 1000000000000000000000000000000C0000000000000000000000000001 29 | 1000000000000000000000000000000C0000000000000000000000000001 30 | 1000000000000000000000000000000C0000000000000000000000000001 31 | 100000000000000000000000000000000000000000000000000000000001 32 | 100000000000000000000000000000000000000000000000000000000001 33 | 1P00000000000000000000000000000000000000000000000000000C00E1 34 | 111111111111111111111111111111111111111111111111111111111111 -------------------------------------------------------------------------------- /Bonus/src/scan_monster_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* scan_monster_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n y) 24 | { 25 | while (x < map->x) 26 | { 27 | if (map->array[y][x] == 'X') 28 | m++; 29 | x++; 30 | } 31 | x = 0; 32 | y++; 33 | } 34 | return (m); 35 | } 36 | 37 | void alloc_monster(t_map *map) 38 | { 39 | int y; 40 | int x; 41 | int m; 42 | 43 | m = 0; 44 | y = 0; 45 | x = 0; 46 | while (y < map->y) 47 | { 48 | while (x < map->x && m < map->enemy.nbr) 49 | { 50 | if (map->array[y][x] == 'X') 51 | { 52 | map->enemy.array[0][m] = y; 53 | map->enemy.array[1][m] = x; 54 | m++; 55 | } 56 | x++; 57 | } 58 | x = 0; 59 | y++; 60 | } 61 | } 62 | 63 | void scan_monster(t_map *map) 64 | { 65 | map->enemy.nbr = count_monster(map); 66 | if (map->enemy.nbr <= 0) 67 | return ; 68 | map->enemy.array = malloc(sizeof(int **) * 3); 69 | map->enemy.array[0] = malloc(sizeof(int *) * map->enemy.nbr + 1); 70 | map->enemy.array[1] = malloc(sizeof(int *) * map->enemy.nbr + 1); 71 | map->enemy.array[2] = 0; 72 | map->enemy.array[0][map->enemy.nbr] = 0; 73 | map->enemy.array[1][map->enemy.nbr] = 0; 74 | alloc_monster(map); 75 | } 76 | -------------------------------------------------------------------------------- /Resources/enemy-1-1.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "40 40 8 1 ", 5 | " c #04193F", 6 | ". c #03396B", 7 | "X c #C3242F", 8 | "o c #E7333B", 9 | "O c #0696DB", 10 | "+ c #0FEFFB", 11 | "@ c #FCFEFE", 12 | "# c None", 13 | /* pixels */ 14 | "########################################", 15 | "########################################", 16 | "########################################", 17 | "########################################", 18 | "########################################", 19 | "########################################", 20 | "############### ###################", 21 | "############### ###################", 22 | "############ ++++OO ################", 23 | "########### ++++++++O... ###############", 24 | "########## +++++++++ ... ##############", 25 | "######### ++++++++++ .... #############", 26 | "######### ++++++++++ .... #############", 27 | "######### ++++ +++OO... #############", 28 | "####### +++ @@ +OOOO @ ###########", 29 | "####### +++ @@ +OOOO @ ###########", 30 | "####### +++ @@ +OOOO @ ###########", 31 | "####### +++ @@ +OOOO @ ###########", 32 | "####### +++++ ++OOOOO. ###########", 33 | "####### ++++++++++OOOOO... ###########", 34 | "######### +++++++OOOOO.... #############", 35 | "######### +++++OOOOO .... #############", 36 | "######### +++++OOOOO .... #############", 37 | "######### OOOOOOOOOOO... ## ####", 38 | "######### XXXOOOOOOO.... ....... ###", 39 | "####### O oooXXXOO.....X .......... ###", 40 | "###### OOO. oooooXXXXXXXo........... ###", 41 | "###### OOO. oooooXXXXXXXo........... ###", 42 | "###### OOOO. oooooooooo........... ####", 43 | "##### OOOOO... ooooooooo........... ####", 44 | "##### OOOOO.OO. oooooo . .... #####", 45 | "##### OOOO.OOOO. ooo .. ##### ######", 46 | "##### OOOO.OOOO. ooo .. ##### ######", 47 | "###### .OOOOO. .... ###############", 48 | "########## OOOOOO....... ###############", 49 | "######### OOOOOOOOO..... ###############", 50 | "######### OOOOO ... ################", 51 | "######### OOOOO ... ################", 52 | "####### OOOOO # ..... ################", 53 | "####### OOO ## .... ##################" 54 | }; 55 | -------------------------------------------------------------------------------- /Resources/enemy-1-2.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "40 40 8 1 ", 5 | " c #04193F", 6 | ". c #03396B", 7 | "X c #C3242F", 8 | "o c #E7333B", 9 | "O c #0696DB", 10 | "+ c #0FEFFB", 11 | "@ c #FCFEFE", 12 | "# c None", 13 | /* pixels */ 14 | "########################################", 15 | "########################################", 16 | "########################################", 17 | "########################################", 18 | "########################################", 19 | "########################################", 20 | "########################################", 21 | "########################################", 22 | "################ ##################", 23 | "############## ++++OO ###############", 24 | "############ +++++++O... ##############", 25 | "########### +++++++++ .. #############", 26 | "########### +++++++++ .. #############", 27 | "########## ++++++++++ ... ###########", 28 | "########## ++++ ++OOO.. ###########", 29 | "######### ++++ @@@ +OOOO @@ ##########", 30 | "######### ++++ @@@ +OOOO @@ ##########", 31 | "######### ++++ @@@ +OOOO @@ ##########", 32 | "######### ++++ +OOOO ##########", 33 | "######### +++++ +OOOOO. ##########", 34 | "######### ++++++++++OOOOO.... ##########", 35 | "########## ++++++++OOOOO... ###########", 36 | "########## ++++++++OOOOO... ###########", 37 | "########## +++++OOOOO ... ###########", 38 | "########### OOOOOOOOOOOO.. #############", 39 | "########### XXXOOOOOOO.... #############", 40 | "########### oooXXXXO.....X #############", 41 | "########### oooXXXXO.....X #############", 42 | "########## . oooooXXXXXXo #############", 43 | "########## O.. oooooooooo #############", 44 | "######### OOOO.. oooooooo . ###########", 45 | "######### OOOOO.. ooooo.. ###########", 46 | "######### OOOOO.. ooooo.. ###########", 47 | "######### OOOO.OO... oo .. ###########", 48 | "########## ...OOOOOO.. . #############", 49 | "########### OOOOOOO...... ##############", 50 | "########### OOOOO ..... ##############", 51 | "########### OOOOO ..... ##############", 52 | "########### OOOOO .... ###############", 53 | "########### OOOO ## .... ###############" 54 | }; 55 | -------------------------------------------------------------------------------- /Mandatory/src/map_printer.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_printer.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n array[y / IMG_PXL][x / IMG_PXL]; 20 | if (type == 'C' || type == 'P' || type == 'E' || type == '0') 21 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, x, y); 22 | if (type == 'C') 23 | mlx_put_image_to_window(map->mlx, map->wnd, 24 | map->img.collectible, x, y); 25 | else if (type == 'P') 26 | mlx_put_image_to_window(map->mlx, map->wnd, 27 | map->img.player_down1, x + 8, y); 28 | else if (type == 'E') 29 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.exit, x, y); 30 | else if (type == '1') 31 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, x, y); 32 | } 33 | 34 | void map_printer(t_map *map) 35 | { 36 | int x; 37 | int y; 38 | 39 | x = 0; 40 | y = 0; 41 | while (y < map->y) 42 | { 43 | while (x < map->x) 44 | { 45 | map_type(map, x * IMG_PXL, y * IMG_PXL); 46 | x++; 47 | } 48 | x = 0; 49 | y++; 50 | } 51 | } 52 | 53 | void print_movements(t_map *map) 54 | { 55 | char *move; 56 | 57 | move = ft_itoa(map->moves); 58 | write(1, "\r", 1); 59 | write(1, "\x1b[33;01m", 9); 60 | write(1, move, ft_strlen(move)); 61 | write(1, "\x1b[0m", 5); 62 | write(1, " movements", 11); 63 | free(move); 64 | } 65 | -------------------------------------------------------------------------------- /libft/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 0) 59 | free(ret[--i]); 60 | free(ret); 61 | return (0); 62 | } 63 | 64 | char **ft_split(char const *s, char c) 65 | { 66 | char **ret; 67 | int i; 68 | int string; 69 | 70 | string = wordcounter(s, c); 71 | i = 0; 72 | ret = malloc(sizeof(char **) * (string + 1)); 73 | if (!ret || !s) 74 | return (NULL); 75 | while (i < string) 76 | { 77 | while (*s == c) 78 | s++; 79 | ret[i] = stringreturn(s, c); 80 | if (ret[i] == NULL) 81 | ft_free(ret, i); 82 | s += ft_strlen(ret[i]); 83 | i++; 84 | } 85 | ret[i] = NULL; 86 | return (ret); 87 | } 88 | -------------------------------------------------------------------------------- /Bonus/src/animation_monster_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* animation_monster_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n enemy.pos == 0) 17 | { 18 | move_right_m(map, m); 19 | map->enemy.pos++; 20 | } 21 | else if (map->enemy.pos == 1) 22 | { 23 | move_down_m(map, m); 24 | map->enemy.pos++; 25 | } 26 | else if (map->enemy.pos == 2) 27 | { 28 | move_left_m(map, m); 29 | map->enemy.pos++; 30 | } 31 | else if (map->enemy.pos == 3) 32 | { 33 | move_up_m(map, m); 34 | map->enemy.pos++; 35 | } 36 | else 37 | map->enemy.pos = 0; 38 | } 39 | 40 | static void monster_animation(t_map *map, int x, int y) 41 | { 42 | if (map->action % 1000 == 0) 43 | { 44 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 45 | x * IMG_PXL, y * IMG_PXL); 46 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.enemy, 47 | x * IMG_PXL + 8, y * IMG_PXL); 48 | } 49 | if (map->action % 3000 == 0) 50 | { 51 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 52 | x * IMG_PXL, y * IMG_PXL); 53 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.enemy2, 54 | x * IMG_PXL + 8, y * IMG_PXL); 55 | } 56 | } 57 | 58 | int move_monster(t_map *map) 59 | { 60 | int m; 61 | int x; 62 | int y; 63 | 64 | m = 0; 65 | if (map->exit == 1) 66 | return (0); 67 | while (m < map->enemy.nbr) 68 | { 69 | y = map->enemy.array[0][m]; 70 | x = map->enemy.array[1][m]; 71 | monster_animation(map, x, y); 72 | if (map->action % 5000 == 0) 73 | randomize_enemy(map, m); 74 | m++; 75 | } 76 | map->action++; 77 | return (0); 78 | } 79 | -------------------------------------------------------------------------------- /Mandatory/src/file_to_image.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* file_to_image.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n img.empty = mlx_xpm_file_to_image(map->mlx, 21 | "Resources/empty.xpm", &a, &a); 22 | map->img.wall = mlx_xpm_file_to_image(map->mlx, 23 | "Resources/wall.xpm", &a, &a); 24 | map->img.exit = mlx_xpm_file_to_image(map->mlx, 25 | "Resources/door.xpm", &a, &a); 26 | map->img.collectible = mlx_xpm_file_to_image(map->mlx, 27 | "Resources/Estrellita.xpm", &a, &a); 28 | map->img.enemy = mlx_xpm_file_to_image(map->mlx, 29 | "Resources/enemy.xpm", &a, &a); 30 | file_to_image_player(map); 31 | } 32 | 33 | void file_to_image_player(t_map *map) 34 | { 35 | int a; 36 | 37 | a = IMG_PXL; 38 | map->img.player_right1 = mlx_xpm_file_to_image(map->mlx, 39 | "Resources/right-1-40.xpm", &a, &a); 40 | map->img.player_right2 = mlx_xpm_file_to_image(map->mlx, 41 | "Resources/right-2-40.xpm", &a, &a); 42 | map->img.player_up1 = mlx_xpm_file_to_image(map->mlx, 43 | "Resources/up-1-40.xpm", &a, &a); 44 | map->img.player_up2 = mlx_xpm_file_to_image(map->mlx, 45 | "Resources/up-2-40.xpm", &a, &a); 46 | map->img.player_down1 = mlx_xpm_file_to_image(map->mlx, 47 | "Resources/down-1-40.xpm", &a, &a); 48 | map->img.player_down2 = mlx_xpm_file_to_image(map->mlx, 49 | "Resources/down-2-40.xpm", &a, &a); 50 | map->img.player_left1 = mlx_xpm_file_to_image(map->mlx, 51 | "Resources/left-1-40.xpm", &a, &a); 52 | map->img.player_left2 = mlx_xpm_file_to_image(map->mlx, 53 | "Resources/left-2-40.xpm", &a, &a); 54 | } 55 | -------------------------------------------------------------------------------- /Bonus/src/end_screen_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* end_screen_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n mlx, map->wnd); 17 | ft_free_array(map->array, map->y); 18 | exit(EXIT_SUCCESS); 19 | return (0); 20 | } 21 | 22 | void ft_win(t_map *map) 23 | { 24 | map->exit = 1; 25 | mlx_clear_window(map->mlx, map->wnd); 26 | print_wall(map); 27 | mlx_string_put(map->mlx, map->wnd, 28 | map->x / 2 * IMG_PXL, map->y / 2 * IMG_PXL, 0xFFFA9E, "YOU WON"); 29 | write(1, "\n", 1); 30 | write(1, "\x1b[32;01m", 9); 31 | write(1, "🏆🏆YOU WON!!🏆🏆\n", 27); 32 | write(1, "\x1b[0m", 5); 33 | } 34 | 35 | void ft_lose(t_map *map) 36 | { 37 | map->exit = 1; 38 | mlx_clear_window(map->mlx, map->wnd); 39 | print_wall(map); 40 | mlx_string_put(map->mlx, map->wnd, 41 | map->x / 2 * IMG_PXL, map->y / 2 * IMG_PXL, 0xF52200, "YOU LOSE"); 42 | write(1, "\n", 1); 43 | write(1, "\x1b[31;01m", 9); 44 | write(1, "👾👾YOU LOSE👾👾\n", 26); 45 | write(1, "\x1b[0m", 5); 46 | } 47 | 48 | void print_wall(t_map *map) 49 | { 50 | int x; 51 | int y; 52 | 53 | x = 0; 54 | y = 0; 55 | while (y < map->y) 56 | { 57 | while (x < map->x) 58 | { 59 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, 60 | x * IMG_PXL, y * IMG_PXL); 61 | x++; 62 | } 63 | x = 0; 64 | y++; 65 | } 66 | while (x <= map->x) 67 | { 68 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, 69 | x * IMG_PXL, map->y * IMG_PXL); 70 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, 71 | x * IMG_PXL, map->y * IMG_PXL + IMG_PXL); 72 | x++; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Bonus/src/key_hook_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key_hook_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n player.y = 0; 17 | map->player.x = 0; 18 | while (map->player.y < map->y) 19 | { 20 | while (map->player.x < map->x) 21 | { 22 | if (map->array[map->player.y][map->player.x] == 'P') 23 | break ; 24 | map->player.x++; 25 | } 26 | if (map->array[map->player.y][map->player.x] == 'P') 27 | break ; 28 | map->player.x = 0; 29 | map->player.y++; 30 | } 31 | } 32 | 33 | void print_counter(t_map *map) 34 | { 35 | int x; 36 | char *num; 37 | 38 | x = 0; 39 | while (x < map->x) 40 | { 41 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, 42 | x * IMG_PXL, map->y * IMG_PXL); 43 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, 44 | x * IMG_PXL, (map->y + 1) * IMG_PXL); 45 | x++; 46 | } 47 | num = ft_itoa(map->moves); 48 | mlx_string_put(map->mlx, map->wnd, (map->x / 2) * IMG_PXL / 5, 49 | map->y * IMG_PXL + IMG_PXL / 2, 0x00000, "MOVES:"); 50 | mlx_string_put(map->mlx, map->wnd, 51 | (map->x / 2) * (IMG_PXL / 4) + (IMG_PXL / 2) + (IMG_PXL / 4), 52 | map->y * IMG_PXL + IMG_PXL / 2, 0xFFFF01, num); 53 | free(num); 54 | } 55 | 56 | int key_hook(int keycode, t_map *map) 57 | { 58 | scan_player(map); 59 | if (keycode == ESC) 60 | exit(EXIT_SUCCESS); 61 | if (map->exit == 1) 62 | return (0); 63 | else if (keycode == LEFT) 64 | move_left(map); 65 | else if (keycode == DOWN) 66 | move_down(map); 67 | else if (keycode == RIGHT) 68 | move_right(map); 69 | else if (keycode == UP) 70 | move_up(map); 71 | print_counter(map); 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /Bonus/src/file_to_image_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* file_to_image_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n img.empty = mlx_xpm_file_to_image(map->mlx, 21 | "Resources/empty.xpm", &a, &a); 22 | map->img.wall = mlx_xpm_file_to_image(map->mlx, 23 | "Resources/wall.xpm", &a, &a); 24 | map->img.exit = mlx_xpm_file_to_image(map->mlx, 25 | "Resources/door.xpm", &a, &a); 26 | map->img.collectible = mlx_xpm_file_to_image(map->mlx, 27 | "Resources/estrellita.xpm", &a, &a); 28 | map->img.enemy = mlx_xpm_file_to_image(map->mlx, 29 | "Resources/enemy.xpm", &a, &a); 30 | map->img.enemy2 = mlx_xpm_file_to_image(map->mlx, 31 | "Resources/enemy-2-2.xpm", &a, &a); 32 | file_to_image_player(map); 33 | } 34 | 35 | void file_to_image_player(t_map *map) 36 | { 37 | int a; 38 | 39 | a = IMG_PXL; 40 | map->img.player_right1 = mlx_xpm_file_to_image(map->mlx, 41 | "Resources/right-1-40.xpm", &a, &a); 42 | map->img.player_right2 = mlx_xpm_file_to_image(map->mlx, 43 | "Resources/right-2-40.xpm", &a, &a); 44 | map->img.player_up1 = mlx_xpm_file_to_image(map->mlx, 45 | "Resources/up-1-40.xpm", &a, &a); 46 | map->img.player_up2 = mlx_xpm_file_to_image(map->mlx, 47 | "Resources/up-2-40.xpm", &a, &a); 48 | map->img.player_down1 = mlx_xpm_file_to_image(map->mlx, 49 | "Resources/down-1-40.xpm", &a, &a); 50 | map->img.player_down2 = mlx_xpm_file_to_image(map->mlx, 51 | "Resources/down-2-40.xpm", &a, &a); 52 | map->img.player_left1 = mlx_xpm_file_to_image(map->mlx, 53 | "Resources/left-1-40.xpm", &a, &a); 54 | map->img.player_left2 = mlx_xpm_file_to_image(map->mlx, 55 | "Resources/left-2-40.xpm", &a, &a); 56 | } 57 | -------------------------------------------------------------------------------- /Bonus/src/map_printer_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_printer_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n array[y / IMG_PXL][x / IMG_PXL]; 19 | if (type == 'C' || type == 'P' || type == 'E' || type == 'X' || type == '0') 20 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, x, y); 21 | if (type == 'C') 22 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.collectible, x, y); 23 | else if (type == 'P') 24 | mlx_put_image_to_window(map->mlx, map->wnd, 25 | map->img.player_down1, x + 8, y); 26 | else if (type == 'E') 27 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.exit, x, y); 28 | else if (type == '1') 29 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, x, y); 30 | else if (type == 'X') 31 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.enemy, x + 8, y); 32 | } 33 | 34 | void map_printer(t_map *map) 35 | { 36 | int x; 37 | int y; 38 | 39 | x = 0; 40 | y = 0; 41 | file_to_image(map); 42 | while (y < map->y) 43 | { 44 | while (x < map->x) 45 | { 46 | map_type(map, x * IMG_PXL, y * IMG_PXL); 47 | x++; 48 | } 49 | x = 0; 50 | y++; 51 | } 52 | x = 0; 53 | while (x <= map->x) 54 | { 55 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, 56 | x * IMG_PXL, map->y * IMG_PXL); 57 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.wall, 58 | x * IMG_PXL, map->y * IMG_PXL + IMG_PXL); 59 | x++; 60 | } 61 | } 62 | 63 | void print_movements(t_map *map) 64 | { 65 | char *move; 66 | 67 | move = ft_itoa(map->moves); 68 | write(1, "\r", 1); 69 | write(1, "\x1b[33;01m", 9); 70 | write(1, move, ft_strlen(move)); 71 | write(1, "\x1b[0m", 5); 72 | write(1, " movements", 11); 73 | free(move); 74 | } 75 | -------------------------------------------------------------------------------- /libft/get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 0 && !ft_strchr(buf, '\n')) 58 | { 59 | ret = read(fd, buf, BUFFER_SIZE); 60 | if (ret > 0) 61 | { 62 | buf[ret] = '\0'; 63 | recovery = ft_strjoinfree(recovery, buf); 64 | } 65 | } 66 | free(buf); 67 | if (ret < 0) 68 | { 69 | free(recovery); 70 | return (NULL); 71 | } 72 | return (recovery); 73 | } 74 | 75 | char *get_next_line(int fd) 76 | { 77 | static char *recovery = NULL; 78 | char *line; 79 | 80 | if (fd < 0 || fd > 255 || !BUFFER_SIZE) 81 | return (NULL); 82 | if (!recovery || !ft_strchr(recovery, '\n')) 83 | recovery = reader(fd, recovery); 84 | if (recovery == NULL) 85 | return (NULL); 86 | if (ft_strchr(recovery, '\n')) 87 | { 88 | line = returnstring(recovery); 89 | recovery = staticret(recovery); 90 | return (line); 91 | } 92 | line = recovery; 93 | recovery = NULL; 94 | return (line); 95 | } 96 | -------------------------------------------------------------------------------- /Bonus/src/move_animation_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_animation_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n mlx, map->wnd, map->img.empty, 18 | x * IMG_PXL, y * IMG_PXL); 19 | if (map->z == 0) 20 | { 21 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_right1, 22 | x * IMG_PXL + 8, y * IMG_PXL); 23 | map->z = 1; 24 | } 25 | else if (map->z == 1) 26 | { 27 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_right2, 28 | x * IMG_PXL + 8, y * IMG_PXL); 29 | map->z = 0; 30 | } 31 | } 32 | 33 | void move_animation_left(t_map *map, int x, int y) 34 | { 35 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 36 | x * IMG_PXL, y * IMG_PXL); 37 | if (map->z == 0) 38 | { 39 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_left1, 40 | x * IMG_PXL + 8, y * IMG_PXL); 41 | map->z = 1; 42 | } 43 | else if (map->z == 1) 44 | { 45 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_left2, 46 | x * IMG_PXL + 8, y * IMG_PXL); 47 | map->z = 0; 48 | } 49 | } 50 | 51 | void move_animation_up(t_map *map, int x, int y) 52 | { 53 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 54 | x * IMG_PXL, y * IMG_PXL); 55 | if (map->z == 0) 56 | { 57 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_up1, 58 | x * IMG_PXL + 8, y * IMG_PXL); 59 | map->z = 1; 60 | } 61 | else if (map->z == 1) 62 | { 63 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_up2, 64 | x * IMG_PXL + 8, y * IMG_PXL); 65 | map->z = 0; 66 | } 67 | } 68 | 69 | void move_animation_down(t_map *map, int x, int y) 70 | { 71 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 72 | x * IMG_PXL, y * IMG_PXL); 73 | if (map->z == 0) 74 | { 75 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_down1, 76 | x * IMG_PXL + 8, y * IMG_PXL); 77 | map->z = 1; 78 | } 79 | else if (map->z == 1) 80 | { 81 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_down2, 82 | x * IMG_PXL + 8, y * IMG_PXL); 83 | map->z = 0; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Resources/wall.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *result[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "50 50 3 1 ", 5 | " c #1E7CB8", 6 | ". c #2996DB", 7 | "X c #5AAEE4", 8 | /* pixels */ 9 | " ", 10 | " ", 11 | " ..XXX.. ", 12 | " ..XXXXX. . ", 13 | " ..XXXXX. . ", 14 | " X.. XX. ..X X.. ", 15 | " .. .. . . ", 16 | " .. .. . . ", 17 | " ", 18 | " ", 19 | " ", 20 | " . . ", 21 | " . . . .. .. ..", 22 | " . . . .. .. ..", 23 | " ", 24 | " ", 25 | " ", 26 | " .. .. ", 27 | " .. .. ", 28 | " .XX XX. . . ", 29 | " .XXXXXXX. ..X X.. ", 30 | " .XXXXXXX. ..X X.. ", 31 | " ..XXX.. ", 32 | " ", 33 | " ", 34 | " .. . .. .. ", 35 | " .. . .. .. ", 36 | " . .. . . ", 37 | " ", 38 | " ", 39 | " ", 40 | " .XXXX.XX. ", 41 | " .XXXX.XX. ", 42 | " . . ", 43 | " ..XXX.. .. .. ", 44 | " ..XXX.. .. .. ", 45 | " .. . . ", 46 | " .. . . ", 47 | " .. . . ", 48 | " . .. .. ", 49 | " . .. .. ", 50 | " ... ... X XX. ", 51 | " . XXX... ", 52 | " . XXX... ", 53 | " ", 54 | " ", 55 | " ", 56 | " . .. . . ", 57 | " .. . .. .. ", 58 | " .. . .. .. " 59 | }; 60 | -------------------------------------------------------------------------------- /Resources/empty.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *_d93b1d1644945218863d3f72e85a7c2C1EyJhYb69es6axP[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "50 50 7 1 ", 5 | " c #328E41", 6 | ". c #3ABE41", 7 | "X c #6ADD4B", 8 | "o c #165C88", 9 | "O c #1E7CB8", 10 | "+ c #5AAEE4", 11 | "@ c white", 12 | /* pixels */ 13 | "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", 14 | "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", 15 | "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", 16 | "OOOOOOOOO@@@@@@@+OOO++@@@++OOOOOOOOO++@@@+OOOOOOOO", 17 | "OOOOOOOOO@@@@@@@+OOO++@@@++OOOOOOOOO++@@@+OOOOOOOO", 18 | "OOOOOO@@@ ... @@@@@@ @@@++O++@@@@@ @@@+OOOOO", 19 | "OOOOO@ ................... @@@@@ ........ @++OOO", 20 | "OOOOO@ ................... @@@@@ ........ @++OOO", 21 | "OOO@@ ................................X..... @@OOO", 22 | "OOO@@........................................@@OOO", 23 | "OOO@@........................................@@OOO", 24 | "OOO@@ ..............XX...................... @@OOO", 25 | "OOO@@ .................................XX... @@OOO", 26 | "OOO@@ .................................XX... @@OOO", 27 | "OOO++@................................X ...@++OOO", 28 | "OOO++@................................X ...@++OOO", 29 | "OOOoo@ ..........................XX..X.....@++OOO", 30 | "OOOoo@ .........XX............... .. ..... @@OOO", 31 | "OOOoo@ .........XX............... .. ..... @@OOO", 32 | "OOOOO+@@.........XX..........................@@OOO", 33 | "OOOOO+@@......... ......................... @@OOO", 34 | "OOOOO+@@......... ......................... @@OOO", 35 | "OOO++@ .......................XX........... @@OOO", 36 | "OOO@@ ......................................@++OOO", 37 | "OOO@@ ......................................@++OOO", 38 | "OOO@@ ......................................@ooOOO", 39 | "OOO@@ ......................................@ooOOO", 40 | "OOO++@......................................@ooOOO", 41 | "OOOoo@ ....................XX..............@++OOO", 42 | "OOOoo@ ....................XX..............@++OOO", 43 | "OOOoo@ .................XX.XXX..X.......... @@OOO", 44 | "OOOOO+@@.................XXXXXXXXX.......... @@OOO", 45 | "OOOOO+@@.................XXXXXXXXX.......... @@OOO", 46 | "OOOOO+@@................. X XXX ..........@++OOO", 47 | "OOO++@ ................... ...........@++OOO", 48 | "OOO++@ ................... ...........@++OOO", 49 | "OOO@@ ...................................... @@OOO", 50 | "OOO@@......XX................................@@OOO", 51 | "OOO@@......XX................................@@OOO", 52 | "OOO@@ ..X..XX..............X ........... @@OOO", 53 | "OOO@@ ..X..XX..............X ........... @@OOO", 54 | "OOO@@ .. ... XX... ... @@OOO", 55 | "OOO++@ @@@@@ @++OOO", 56 | "OOO++@ @@@@@ @++OOO", 57 | "OOOoo+@@@ @@@@ @@@++O++@@@@@ @@@+ooOOO", 58 | "OOOoooOO+@@@@@@@+OO+@@@@@++OooooooOO++@@@+oooooOOO", 59 | "OOOoooOO+@@@@@@@+OO+@@@@@++OooooooOO++@@@+oooooOOO", 60 | "OOOOOooooooooooooooooooooooooooooooooooooooooOOOOO", 61 | "OOOOOOOOoooooooooooooooooooOOOOOOOOOooooooOOOOOOOO", 62 | "OOOOOOOOoooooooooooooooooooOOOOOOOOOooooooOOOOOOOO" 63 | }; 64 | -------------------------------------------------------------------------------- /Resources/door.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *_3feeaca089343b5a3789f141d2d7e3fDC5H3SU9POQrEHcX[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "50 50 9 1 ", 5 | " c None", 6 | ". c black", 7 | "X c #482D1E", 8 | "o c #5F3A27", 9 | "O c #744730", 10 | "+ c #5F5F5F", 11 | "@ c #727272", 12 | "# c gray50", 13 | "$ c #865337", 14 | /* pixels */ 15 | " ", 16 | " ", 17 | " ", 18 | " ", 19 | " ", 20 | " +++++ ", 21 | " ++++#####+++ ", 22 | " ++++#####+++ ", 23 | " +++############+++ ", 24 | " +@@################+ ", 25 | " +@@######....#######+ ", 26 | " +@#####....X....######++ ", 27 | " +@#####....X....######+ ", 28 | " +@####.XXXX$$$oO.#####+ ", 29 | " +++@####.XXXX$$$$oOO..####++ ", 30 | " +@@######.XOOX$$$$oOO..######+ ", 31 | " +@@#####.XXOOX$$$$oOOOO.#####+ ", 32 | " +@@#####.XXOOX$$$$oOOOOO.#####+ ", 33 | " +@@@###..XXOOOX$$$$oOOOOO.#####+ ", 34 | " +@#####..XOOOOX$$$$oOOOOO.#####+ ", 35 | " +@####.XXXOOOOX$$$$oOoOOOo.####+ ", 36 | " +@####.XXoOOOOX$$$$oOooOOo.####+ ", 37 | " +@####.XXoOOOOX$$$ooOOOOOo.####+ ", 38 | " +@####.XXoOOOOX$$$ooOOOOOo.####+ ", 39 | " +@####.XXoOOOOX$$$ooOOOOOo.####+ ", 40 | " +@@####.XXoOOOOX$o$ooOOOOOo.#####+ ", 41 | " +@@####.XXoOOOOX$o$ooOOOOOo.#####+ ", 42 | " +@@####.XXoOOOXX$$$ooOOOOOo$.####+ ", 43 | " +@@###.XXXoOOOXX$$$ooOOOOOo$.####+ ", 44 | " +@@###.XOOoOOOXX$$$ooOOOOOo$.####+ ", 45 | " +@@###.XOOoOOOXX$$$ooOOOOOo$.####+ ", 46 | " +@@###.XOOoOOOXX$$$ooOOOOOo$.####+ ", 47 | " +@@###.XOooOOOXX$$$ooOOO..o$.####+ ", 48 | " +@@###.XOooOOOXX$$$ooOOO..o$.####+ ", 49 | " +++@####.XOooOOOXX$$$ooOO....$.####+++ ", 50 | " ++@@####.XOooOOOXX$$$ooO....o$.#####++ ", 51 | " ++@@###..XOooOOOXX$$$ooOOOooo$...###++ ", 52 | " ++@@##..XXOooOOOXX$$$ooOOOooo$$..###++ ", 53 | " ++@@##..XXOooOOOXX$$$ooOOOooo$$..###++ ", 54 | " ++@@##..XOOooOOOXX$$$ooOOOOOo$$..###++ ", 55 | " ++@###..XOOooOOOXX$$$ooOOOOOo$$..###++ ", 56 | " ++@###..XOOooOOOXX$$$ooOOOOOo$$..###++ ", 57 | " +@@###..XOOoooOOXX$$$ooOOOOOo$$..###++ ", 58 | " +@@###..XOOoooOOXX$$$ooOOOOOo$$..###++ ", 59 | " +@@###..XOOoooOOXX$$oooOOOOOo$$..###++ ", 60 | " ", 61 | " ", 62 | " ", 63 | " ", 64 | " " 65 | }; 66 | -------------------------------------------------------------------------------- /Bonus/src/checker_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* checker_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: josephcheel +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/13 15:55:37 by jcheel-n #+# #+# */ 9 | /* Updated: 2022/07/28 17:50:53 by jcheel-n ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | #include "../inc/so_long_bonus.h" 13 | 14 | static void checker_file(char *map) 15 | { 16 | size_t len; 17 | 18 | len = ft_strlen(map); 19 | if (map[len - 1] != 'r') 20 | error_filename(); 21 | if (map[len - 2] != 'e') 22 | error_filename(); 23 | if (map[len - 3] != 'b') 24 | error_filename(); 25 | if (map[len - 4] != '.') 26 | error_filename(); 27 | if (!ft_strnstr(map, ".ber", ft_strlen(map))) 28 | error_filename(); 29 | } 30 | 31 | static void checker_params(t_map *map) 32 | { 33 | int y; 34 | int x; 35 | 36 | y = 0; 37 | while (y < map->y) 38 | { 39 | while (x < map->x) 40 | { 41 | if (map->array[y][x] == 'C') 42 | map->c += 1; 43 | else if (map->array[y][x] == 'E') 44 | map->e += 1; 45 | else if (map->array[y][x] == 'P') 46 | map->p += 1; 47 | else if (map->array[y][x] == '0' || map->array[y][x] == '1' 48 | || map->array[y][x] == 'X'); 49 | else 50 | error_map_elements(map); 51 | x++; 52 | } 53 | x = 0; 54 | y++; 55 | } 56 | if (map->c < 1 || map->e < 1 || map->p != 1) 57 | error_map_elements(map); 58 | } 59 | 60 | static void checker_wall(t_map *map) 61 | { 62 | int x; 63 | int y; 64 | 65 | x = 0; 66 | while (map->array[0][x] == '1' && map->array[1][x]) 67 | x++; 68 | if (map->array[1][x] != '\0') 69 | error_wall(map); 70 | y = 1; 71 | while (y < map->y) 72 | { 73 | if (map->array[y][0] != '1' || 74 | map->array[y][map->x - 1] != '1') 75 | error_wall(map); 76 | y++; 77 | } 78 | x = 0; 79 | while (map->array[map->y - 1][x] == '1') 80 | x++; 81 | if (map->array[map->y - 1][x] != '\0') 82 | error_wall(map); 83 | } 84 | 85 | void checker_size(t_map *map) 86 | { 87 | int y; 88 | int x; 89 | int max; 90 | 91 | y = 0; 92 | x = 0; 93 | max = ft_strlen(map->array[y]); 94 | while (y < map->y) 95 | { 96 | x = ft_strlen(map->array[y]); 97 | if (max != x) 98 | error_size(map); 99 | y++; 100 | } 101 | map->x = max; 102 | } 103 | 104 | void map_checker(t_map *map) 105 | { 106 | checker_file(map->filename); 107 | map_array(map); 108 | checker_size(map); 109 | checker_wall(map); 110 | checker_params(map); 111 | check_valid_path(map); 112 | ft_free_array(map->copy, map->y); 113 | } 114 | -------------------------------------------------------------------------------- /Mandatory/src/checker.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* checker.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: josephcheel +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/13 15:55:37 by jcheel-n #+# #+# */ 9 | /* Updated: 2022/07/28 17:38:37 by jcheel-n ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | #include "../inc/so_long.h" 13 | 14 | static void checker_file(t_map *map) 15 | { 16 | size_t len; 17 | 18 | len = ft_strlen(map->filename); 19 | if (map->filename[len - 1] != 'r') 20 | error_filename(); 21 | if (map->filename[len - 2] != 'e') 22 | error_filename(); 23 | if (map->filename[len - 3] != 'b') 24 | error_filename(); 25 | if (map->filename[len - 4] != '.') 26 | error_filename(); 27 | if (!ft_strnstr(map->filename, ".ber", ft_strlen(map->filename))) 28 | error_filename(); 29 | } 30 | 31 | static void checker_params(t_map *map) 32 | { 33 | int y; 34 | int x; 35 | 36 | y = 0; 37 | while (y < map->y) 38 | { 39 | while (x < map->x) 40 | { 41 | if (map->array[y][x] == 'C') 42 | map->c += 1; 43 | else if (map->array[y][x] == 'E') 44 | map->e += 1; 45 | else if (map->array[y][x] == 'P') 46 | map->p += 1; 47 | else if (map->array[y][x] == '0' || map->array[y][x] == '1') 48 | ; 49 | else 50 | error_map_elements(map); 51 | x++; 52 | } 53 | x = 0; 54 | y++; 55 | } 56 | if (map->c < 1 || map->e < 1 || map->p != 1) 57 | error_map_elements(map); 58 | } 59 | 60 | static void checker_wall(t_map *map) 61 | { 62 | int x; 63 | int y; 64 | 65 | x = 0; 66 | while (map->array[0][x] == '1' && map->array[1][x]) 67 | x++; 68 | if (map->array[1][x] != '\0') 69 | error_wall(map); 70 | y = 1; 71 | while (y < map->y) 72 | { 73 | if (map->array[y][0] != '1' || 74 | map->array[y][map->x - 1] != '1') 75 | error_wall(map); 76 | y++; 77 | } 78 | x = 0; 79 | while (map->array[map->y - 1][x] == '1') 80 | x++; 81 | if (map->array[map->y - 1][x] != '\0') 82 | error_wall(map); 83 | } 84 | 85 | void checker_size(t_map *map) 86 | { 87 | int y; 88 | int x; 89 | int max; 90 | 91 | y = 0; 92 | x = 0; 93 | max = ft_strlen(map->array[y]); 94 | while (y < map->y) 95 | { 96 | x = ft_strlen(map->array[y]); 97 | if (max != x) 98 | error_size(map); 99 | y++; 100 | } 101 | map->x = max; 102 | } 103 | 104 | void map_checker(t_map *map) 105 | { 106 | checker_file(map); 107 | map_array(map); 108 | checker_size(map); 109 | checker_wall(map); 110 | checker_params(map); 111 | check_valid_path(map); 112 | ft_free_array(map->copy, map->y); 113 | } 114 | -------------------------------------------------------------------------------- /Mandatory/inc/so_long.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* so_long.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 19 | # include 20 | # include 21 | # include 22 | # include 23 | # include 24 | 25 | # define UP 13 26 | # define DOWN 1 27 | # define LEFT 0 28 | # define RIGHT 2 29 | # define ESC 53 30 | # define IMG_PXL 50 31 | # define WND_NAME "so_long" 32 | 33 | typedef struct s_player 34 | { 35 | int y; 36 | int x; 37 | 38 | }t_player; 39 | 40 | typedef struct s_img 41 | { 42 | void *empty; 43 | void *collectible; 44 | void *wall; 45 | void *exit; 46 | void *player_left1; 47 | void *player_right1; 48 | void *player_up1; 49 | void *player_down1; 50 | void *player_left2; 51 | void *player_right2; 52 | void *player_up2; 53 | void *player_down2; 54 | void *enemy; 55 | }t_img; 56 | 57 | typedef struct s_map 58 | { 59 | int fd; 60 | char *line; 61 | char *file; 62 | char **array; 63 | char **copy; 64 | char *filename; 65 | int y; 66 | int x; 67 | int e; 68 | int c; 69 | int c_check; 70 | int e_check; 71 | int p; 72 | int exit; 73 | int moves; 74 | void *mlx; 75 | void *wnd; 76 | t_img img; 77 | t_player player; 78 | 79 | }t_map; 80 | 81 | void map_checker(t_map *map); 82 | void map_array(t_map *mapper); 83 | void file_to_image(t_map *mapper); 84 | void map_printer(t_map *mapper); 85 | int key_hook(int keycode, t_map *map); 86 | 87 | void error_array(t_map *map); 88 | void error_filename(void); 89 | void error_wall(t_map *map); 90 | void error_openfile(void); 91 | void error_size(t_map *map); 92 | 93 | void error_map_elements(t_map *map); 94 | void error_empty_line(t_map *map); 95 | void error_struct(void); 96 | 97 | int ft_free(char **ret, int i); 98 | void ft_exit_free(t_map *map); 99 | int ft_free_array(char **ret, int i); 100 | 101 | void move_up(t_map *map); 102 | void move_left(t_map *map); 103 | void move_down(t_map *map); 104 | void move_right(t_map *map); 105 | 106 | void file_to_image_player(t_map *map); 107 | 108 | void ft_win(t_map *map); 109 | int ft_close(t_map *map); 110 | 111 | void print_movements(t_map *map); 112 | void map_initializer(t_map *map, char **av); 113 | 114 | void check_valid_path(t_map *map); 115 | void scan_player(t_map *map); 116 | #endif 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

So_long |  3 | 4 | 5 | 42 6 | 7 | Cursus 8 | Complete 9 |

10 | 11 | 12 | 13 | > A project involving the creation of a ***small 2D game*** with a graphical library. Using MiniLibX, the 42 graphical library. 14 | 15 |
16 | 17 |
18 |
19 |
20 | 21 | 22 | ### What is the project about 23 | 24 | This project is focused on developing a 2D game that can be interacted with using your keyboard. The task is divided into two parts: the mandatory and the bonus. Each of these parts is compiled and executed separately. The bonus section includes the same features as the mandatory part, along with some additional enhancements. 25 | 26 | ## General Instrucctions 27 | * Makefile will compile your source files. It must include 'all' and 'bonus' rules for the Mandatory and Bonus parts, respectively. It should not relink. 28 | * You are required to use MiniLibX for this project. 29 | * The program should be compiled using the following commands: 30 | 31 | ```shell 32 | > ./so_long map.ber 33 | > ./so_long_bonus map.ber 34 | ``` 35 | 36 | 37 | > [!WARNING] 38 | > Maps must have the ***.ber*** extension 39 | 40 | ## Mandatory Instrucctions 41 | * The number of movements must be displayed in the shell. 42 | * Pressing ESC or closing the window should result in quitting the program. 43 | 44 | 45 | 46 | * The map must be constructed using five components: **walls**, **collectibles** (at least one), **empty spaces**, **exits** (at least one), and **the player** (only one). These five characters compose the map: 47 | * **0** for an empty space 48 | * **1** for a wall 49 | * **C** for a collectible 50 | * **E** for a map exit 51 | * **P** for the player’s starting position 52 | 53 | 54 | 55 | * To move the main character, use the W A S D keys: 56 | * W to move up ↑ 57 | * S to move down ↓ 58 | * D to move right ➞ 59 | * A to move left ← 60 | 61 | ## Bonus Instrucctions 62 | 63 | * Add **X** to the map for spawn patrols 64 | * Make the player lose when they touch an enemy patrol 65 | * Add some sprite animation. 66 | * Display the movement count directly on screen instead of writing it in the shell. 67 | 68 | ### How to compile it 69 | > Compilation is managed through the Makefile rules. 70 | 71 | 72 |
73 | 74 |
75 | 76 | * If you use make command, the ***./so_long*** executable file, will be generated. 77 | * You can use make bonus command to generate the ***./so_long_bonus*** executable file 78 | 79 | ```shell 80 | > 81 | > make 82 | > make bonus 83 | ``` 84 | -------------------------------------------------------------------------------- /libft/libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 17 | # include 18 | # include 19 | 20 | //**************** LIBFT FUNCTIONS *******************// 21 | 22 | int ft_atoi(const char *str); 23 | void ft_bzero(void *s, size_t n); 24 | void *ft_calloc(size_t count, size_t size); 25 | int ft_isalnum(int c); 26 | int ft_isalpha(int c); 27 | int ft_isascii(int c); 28 | int ft_isdigit(int c); 29 | int ft_isprint(int c); 30 | char *ft_itoa(int n); 31 | void *ft_memccpy(void *dst, const void *src, int c, size_t n); 32 | void *ft_memchr(const void *s, int c, size_t n); 33 | int ft_memcmp(const void *s1, const void *s2, size_t n); 34 | void *ft_memcpy(void *dst, const void *src, size_t n); 35 | void *ft_memmove(void *dst, const void *src, size_t len); 36 | void *ft_memset(void *b, int c, size_t len); 37 | void ft_putchar_fd(char c, int fd); 38 | void ft_putendl_fd(char *s, int fd); 39 | void ft_putnbr_fd(int n, int fd); 40 | void ft_putstr_fd(char *s, int fd); 41 | char **ft_split(char const *s, char c); 42 | char *ft_strchr(const char *s, int c); 43 | char *ft_strdup(const char *s1); 44 | char *ft_strjoin(char const *s1, char const *s2); 45 | size_t ft_strlcat(char *dst, const char *src, size_t size); 46 | size_t ft_strlcpy(char *dst, const char *src, size_t size); 47 | size_t ft_strlen(const char *s); 48 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 49 | int ft_strncmp(const char *s1, const char *s2, size_t n); 50 | char *ft_strnstr(const char *haystack, const char *needle, 51 | size_t len); 52 | char *ft_strrchr(const char *s, int c); 53 | char *ft_strtrim(char const *s1, char const *set); 54 | char *ft_substr(char const *s, unsigned int start, size_t len); 55 | int ft_tolower(int c); 56 | int ft_toupper(int c); 57 | void ft_striteri(char *s, void (*f)(unsigned int, char*)); 58 | 59 | //************* LINKED LIST ************************// 60 | 61 | typedef struct s_list 62 | { 63 | void *content; 64 | struct s_list *next; 65 | }t_list; 66 | 67 | t_list *ft_lstnew(void *content); 68 | void ft_lstadd_front(t_list **alst, t_list *new); 69 | int ft_lstsize(t_list *lst); 70 | t_list *ft_lstlast(t_list *lst); 71 | void ft_lstadd_back(t_list **lst, t_list *new); 72 | void ft_lstdelone(t_list *lst, void (*del)(void *)); 73 | void ft_lstclear(t_list **lst, void (*del)(void *)); 74 | void ft_lstiter(t_list *lst, void (*f)(void *)); 75 | t_list *ft_lstmap(t_list *lst, void *(*f)(void*), void (*del)(void *)); 76 | 77 | //*************** EXTRA FUNCTIONS *****************// 78 | 79 | char *ft_substrfree(char const *s, unsigned int start, size_t len, 80 | int freeme); 81 | char *ft_strjoinfree(char *s1, char *s2); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /Bonus/src/movements_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* movements_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n array[y][x] == 'E' && map->c == 0) 25 | return (ft_win(map)); 26 | if (map->array[y][x] == 'X') 27 | return (ft_lose(map)); 28 | if (map->array[y][x] == 'C') 29 | { 30 | map->array[y][x] = '0'; 31 | map->c--; 32 | } 33 | map->moves++; 34 | } 35 | 36 | void move_up(t_map *map) 37 | { 38 | int x; 39 | int y; 40 | 41 | x = map->player.x; 42 | y = map->player.y; 43 | if (y > 0 && map->array[y - 1][x] != '1') 44 | { 45 | move_resume(map, x, y, UP); 46 | if ((map->array[y - 1][x] == 'E' && map->c != 0) || map->exit == 1) 47 | return ; 48 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 49 | x * IMG_PXL, y * IMG_PXL); 50 | map->array[y][x] = '0'; 51 | y--; 52 | print_movements(map); 53 | } 54 | move_animation_up(map, x, y); 55 | map->array[y][x] = 'P'; 56 | map->player.x = x; 57 | } 58 | 59 | void move_left(t_map *map) 60 | { 61 | int x; 62 | int y; 63 | 64 | x = map->player.x; 65 | y = map->player.y; 66 | if (x > 0 && map->array[y][x - 1] != '1') 67 | { 68 | move_resume(map, x, y, LEFT); 69 | if ((map->array[y][x - 1] == 'E' && map->c != 0) || map->exit == 1) 70 | return ; 71 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 72 | x * IMG_PXL, y * IMG_PXL); 73 | map->array[y][x] = '0'; 74 | x--; 75 | print_movements(map); 76 | } 77 | move_animation_left(map, x, y); 78 | map->array[y][x] = 'P'; 79 | map->player.y = y; 80 | } 81 | 82 | void move_down(t_map *map) 83 | { 84 | int x; 85 | int y; 86 | 87 | x = map->player.x; 88 | y = map->player.y; 89 | if (y < map->y && map->array[y + 1][x] != '1') 90 | { 91 | move_resume(map, x, y, DOWN); 92 | if ((map->array[y + 1][x] == 'E' && map->c != 0) || map->exit == 1) 93 | return ; 94 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 95 | x * IMG_PXL, y * IMG_PXL); 96 | map->array[y][x] = '0'; 97 | y++; 98 | print_movements(map); 99 | } 100 | move_animation_down(map, x, y); 101 | map->array[y][x] = 'P'; 102 | map->player.y = y; 103 | } 104 | 105 | void move_right(t_map *map) 106 | { 107 | int x; 108 | int y; 109 | 110 | x = map->player.x; 111 | y = map->player.y; 112 | if (x < map->x && map->array[y][x + 1] != '1') 113 | { 114 | move_resume(map, x, y, RIGHT); 115 | if ((map->array[y][x + 1] == 'E' && map->c != 0) || map->exit == 1) 116 | return ; 117 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 118 | x * IMG_PXL, y * IMG_PXL); 119 | map->array[y][x] = '0'; 120 | x++; 121 | print_movements(map); 122 | } 123 | move_animation_right(map, x, y); 124 | map->array[y][x] = 'P'; 125 | map->player.x = x; 126 | } 127 | -------------------------------------------------------------------------------- /Bonus/inc/so_long_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* so_long_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n 19 | # include 20 | # include 21 | # include 22 | # include 23 | # include 24 | 25 | # define UP 13 26 | # define DOWN 1 27 | # define LEFT 0 28 | # define RIGHT 2 29 | # define ESC 53 30 | # define IMG_PXL 50 31 | # define WND_NAME "so_long" 32 | 33 | typedef struct s_enemy 34 | { 35 | int **array; 36 | int nbr; 37 | int pos; 38 | }t_enemy; 39 | 40 | typedef struct s_player 41 | { 42 | int y; 43 | int x; 44 | }t_player; 45 | 46 | typedef struct s_img 47 | { 48 | void *empty; 49 | void *collectible; 50 | void *wall; 51 | void *exit; 52 | void *player_left1; 53 | void *player_right1; 54 | void *player_up1; 55 | void *player_down1; 56 | void *player_left2; 57 | void *player_right2; 58 | void *player_up2; 59 | void *player_down2; 60 | void *enemy; 61 | void *enemy2; 62 | 63 | }t_img; 64 | 65 | typedef struct s_map 66 | { 67 | int fd; 68 | char **array; 69 | char **copy; 70 | char *filename; 71 | int y; 72 | int x; 73 | int e; 74 | int c; 75 | int c_check; 76 | int e_check; 77 | int p; 78 | int z; 79 | int action; 80 | int moves; 81 | int exit; 82 | void *mlx; 83 | void *wnd; 84 | t_img img; 85 | t_player player; 86 | t_enemy enemy; 87 | 88 | }t_map; 89 | 90 | void map_checker(t_map *map); 91 | void check_valid_path(t_map *map); 92 | void map_array(t_map *mapper); 93 | void file_to_image(t_map *mapper); 94 | void file_to_image_player(t_map *map); 95 | void map_printer(t_map *mapper); 96 | int key_hook(int keycode, t_map *map); 97 | 98 | void error_array(void); 99 | void error_filename(void); 100 | void error_wall(t_map *map); 101 | void error_openfile(void); 102 | void error_size(t_map *map); 103 | void error_map_elements(t_map *map); 104 | void error_empty_line(void); 105 | void error_malloc(void); 106 | int ft_free(char **ret, int i); 107 | void ft_exit_free(char *str); 108 | int ft_free_array(char **ret, int max); 109 | 110 | void scan_player(t_map *map); 111 | 112 | void scan_monster(t_map *map); 113 | 114 | void move_up(t_map *map); 115 | void move_left(t_map *map); 116 | void move_down(t_map *map); 117 | void move_right(t_map *map); 118 | 119 | int monster_hook(t_map *map); 120 | 121 | void print_counter(t_map *map); 122 | 123 | void map_initializer(t_map *map); 124 | 125 | int count_monster(t_map *map); 126 | void alloc_monster(t_map *map); 127 | void scan_monster(t_map *map); 128 | 129 | void scan_monster(t_map *map); 130 | void scan_monster(t_map *map); 131 | 132 | void move_up_m(t_map *map, int m); 133 | void move_left_m(t_map *map, int m); 134 | void move_down_m(t_map *map, int m); 135 | void move_right_m(t_map *map, int m); 136 | 137 | int move_monster(t_map *map); 138 | 139 | void print_movements(t_map *map); 140 | 141 | void ft_win(t_map *map); 142 | void ft_lose(t_map *map); 143 | int ft_close(t_map *map); 144 | 145 | void print_wall(t_map *map); 146 | 147 | void move_animation_right(t_map *map, int x, int y); 148 | void move_animation_left(t_map *map, int x, int y); 149 | void move_animation_down(t_map *map, int x, int y); 150 | void move_animation_up(t_map *map, int x, int y); 151 | 152 | #endif -------------------------------------------------------------------------------- /Mandatory/src/movements.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* movements.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n array[y][x] == 'E' && map->c == 0) 25 | return (ft_win(map)); 26 | if (map->array[y][x] == 'C') 27 | { 28 | map->array[y][x] = '0'; 29 | map->c--; 30 | } 31 | } 32 | 33 | void move_up(t_map *map) 34 | { 35 | int x; 36 | int y; 37 | 38 | x = map->player.x; 39 | y = map->player.y; 40 | if (y > 0 && map->array[y - 1][x] != '1') 41 | { 42 | move_resume(map, x, y, UP); 43 | if (map->array[y - 1][x] == 'E' && (map->c != 0 || map->exit == 1)) 44 | return ; 45 | map->moves++; 46 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 47 | x * IMG_PXL, y * IMG_PXL); 48 | map->array[y][x] = '0'; 49 | y--; 50 | print_movements(map); 51 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 52 | x * IMG_PXL, y * IMG_PXL); 53 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_up1, 54 | x * IMG_PXL + 8, y * IMG_PXL); 55 | map->array[y][x] = 'P'; 56 | map->player.x = x; 57 | } 58 | } 59 | 60 | void move_left(t_map *map) 61 | { 62 | int x; 63 | int y; 64 | 65 | x = map->player.x; 66 | y = map->player.y; 67 | if (x > 0 && map->array[y][x - 1] != '1') 68 | { 69 | move_resume(map, x, y, LEFT); 70 | if (map->array[y][x - 1] == 'E' && (map->c != 0 || map->exit == 1)) 71 | return ; 72 | map->moves++; 73 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 74 | x * IMG_PXL, y * IMG_PXL); 75 | map->array[y][x] = '0'; 76 | x--; 77 | print_movements(map); 78 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 79 | x * IMG_PXL, y * IMG_PXL); 80 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_left1, 81 | x * IMG_PXL + 8, y * IMG_PXL); 82 | map->array[y][x] = 'P'; 83 | map->player.y = y; 84 | } 85 | } 86 | 87 | void move_down(t_map *map) 88 | { 89 | int x; 90 | int y; 91 | 92 | x = map->player.x; 93 | y = map->player.y; 94 | if (y < map->y && map->array[y + 1][x] != '1') 95 | { 96 | move_resume(map, x, y, DOWN); 97 | if (map->array[y + 1][x] == 'E' && (map->c != 0 || map->exit == 1)) 98 | return ; 99 | map->moves++; 100 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 101 | x * IMG_PXL, y * IMG_PXL); 102 | map->array[y][x] = '0'; 103 | y++; 104 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 105 | x * IMG_PXL, y * IMG_PXL); 106 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_down1, 107 | x * IMG_PXL + 8, y * IMG_PXL); 108 | map->array[y][x] = 'P'; 109 | print_movements(map); 110 | map->player.y = y; 111 | } 112 | } 113 | 114 | void move_right(t_map *map) 115 | { 116 | int x; 117 | int y; 118 | 119 | x = map->player.x; 120 | y = map->player.y; 121 | if (x < map->x && map->array[y][x + 1] != '1') 122 | { 123 | move_resume(map, x, y, RIGHT); 124 | if (map->array[y][x + 1] == 'E' && (map->c != 0 || map->exit == 1)) 125 | return ; 126 | map->moves++; 127 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 128 | x * IMG_PXL, y * IMG_PXL); 129 | map->array[y][x] = '0'; 130 | x++; 131 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 132 | x * IMG_PXL, y * IMG_PXL); 133 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.player_right1, 134 | x * IMG_PXL + 8, y * IMG_PXL); 135 | map->array[y][x] = 'P'; 136 | print_movements(map); 137 | } 138 | map->player.x = x; 139 | } 140 | -------------------------------------------------------------------------------- /Bonus/src/movements_monster_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* movements_monster_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jcheel-n array[y][x] == 'P') 26 | return (ft_lose(map)); 27 | } 28 | 29 | void move_up_m(t_map *map, int m) 30 | { 31 | int x; 32 | int y; 33 | 34 | y = map->enemy.array[0][m]; 35 | x = map->enemy.array[1][m]; 36 | if (y > 0 && map->array[y - 1][x] != '1') 37 | { 38 | move_resume_monster(map, x, y, UP); 39 | if (map->array[y - 1][x] == 'E' || map->array[y - 1][x] == 'C' 40 | || map->array[y - 1][x] == 'X' || map->exit == 1) 41 | return ; 42 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 43 | x * IMG_PXL, y * IMG_PXL); 44 | map->array[y][x] = '0'; 45 | y--; 46 | } 47 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 48 | x * IMG_PXL, y * IMG_PXL); 49 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.enemy, 50 | x * IMG_PXL + 8, y * IMG_PXL); 51 | map->array[y][x] = 'X'; 52 | map->enemy.array[0][m] = y; 53 | } 54 | 55 | void move_left_m(t_map *map, int m) 56 | { 57 | int x; 58 | int y; 59 | 60 | y = map->enemy.array[0][m]; 61 | x = map->enemy.array[1][m]; 62 | if (x > 0 && map->array[y][x - 1] != '1') 63 | { 64 | move_resume_monster(map, x, y, LEFT); 65 | if (map->array[y][x - 1] == 'E' || map->array[y][x - 1] == 'C' 66 | || map->array[y][x - 1] == 'X' || map->exit == 1) 67 | return ; 68 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 69 | x * IMG_PXL, y * IMG_PXL); 70 | map->array[y][x] = '0'; 71 | x--; 72 | } 73 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 74 | x * IMG_PXL, y * IMG_PXL); 75 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.enemy, 76 | x * IMG_PXL + 8, y * IMG_PXL); 77 | map->array[y][x] = 'X'; 78 | map->enemy.array[1][m] = x; 79 | } 80 | 81 | void move_down_m(t_map *map, int m) 82 | { 83 | int x; 84 | int y; 85 | 86 | y = map->enemy.array[0][m]; 87 | x = map->enemy.array[1][m]; 88 | if (y < map->y && map->array[y + 1][x] != '1') 89 | { 90 | move_resume_monster(map, x, y, DOWN); 91 | if (map->array[y + 1][x] == 'E' || map->array[y + 1][x] == 'C' 92 | || map->array[y + 1][x] == 'X' || map->exit == 1) 93 | return ; 94 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 95 | x * IMG_PXL, y * IMG_PXL); 96 | map->array[y][x] = '0'; 97 | y++; 98 | } 99 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 100 | x * IMG_PXL, y * IMG_PXL); 101 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.enemy, 102 | x * IMG_PXL + 8, y * IMG_PXL); 103 | map->array[y][x] = 'X'; 104 | map->enemy.array[0][m] = y; 105 | } 106 | 107 | void move_right_m(t_map *map, int m) 108 | { 109 | int x; 110 | int y; 111 | 112 | y = map->enemy.array[0][m]; 113 | x = map->enemy.array[1][m]; 114 | if (x < map->x && map->array[y][x + 1] != '1') 115 | { 116 | move_resume_monster(map, x, y, RIGHT); 117 | if (map->array[y][x + 1] == 'E' || map->array[y][x + 1] == 'C' 118 | || map->array[y][x + 1] == 'X' || map->exit == 1) 119 | return ; 120 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 121 | x * IMG_PXL, y * IMG_PXL); 122 | map->array[y][x] = '0'; 123 | x++; 124 | } 125 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.empty, 126 | x * IMG_PXL, y * IMG_PXL); 127 | mlx_put_image_to_window(map->mlx, map->wnd, map->img.enemy, 128 | x * IMG_PXL + 8, y * IMG_PXL); 129 | map->array[y][x] = 'X'; 130 | map->enemy.array[1][m] = x; 131 | } 132 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 2 | # __ __ __ _ _ ____ ____ ____ __ ____ # 3 | # ( \/ ) /__\ ( )/ )( ___)( ___)(_ _)( ) ( ___) # 4 | # ) ( /(__)\ ) ( )__) )__) _)(_ )(__ )__) # 5 | # (_/\/\_)(__)(__)(_)\_)(____)(__) (____)(____)(____) 𝕓𝕪 𝕁𝕠𝕤𝕖𝕡𝕙 ℂ𝕙𝕖𝕖𝕝 # 6 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 7 | 8 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 9 | #•❅──────✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──NAME──✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──────❅•# 10 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 11 | 12 | NAME = so_long 13 | NAME_BONUS = so_long_bonus 14 | 15 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 16 | #•❅──────✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──CMD───✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──────❅•# 17 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 18 | 19 | CC = gcc 20 | CFLAGS = -Wall -Werror -Wextra -g $(SYSTEM) 21 | 22 | # System Detection 23 | UNAME_S := $(shell uname -s) 24 | ifeq ($(UNAME_S), Linux) 25 | MLXFLAGS = -Lmlx_Linux -lmlx_Linux -L ./mlx -Imlx_Linux -L ./libft -lft -lXext -lX11 -lm -lz 26 | endif 27 | ifeq ($(UNAME_S), Darwin) 28 | MLXFLAGS = -Lmlx -lmlx -framework OpenGL -framework AppKit 29 | endif 30 | 31 | AR = ar rcs 32 | RM = rm -f 33 | MD = mkdir -p 34 | CP = cp -f 35 | 36 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 37 | #•❅──────✧❅✦❅✧──────❅••❅──────✧❅✦❅DIRECTORIES✦❅✧──────❅••❅──────✧❅✦❅✧──────❅•# 38 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 39 | 40 | MDT_DIR = Mandatory/ 41 | BONUS_DIR = Bonus/ 42 | 43 | SRC_DIR = src/ 44 | OBJ_DIR = obj/ 45 | INC_DIR = inc/ 46 | 47 | LIBFT = libft/libft.a 48 | 49 | INC = $(addprefix $(MDT_DIR), $(INC_DIR)) 50 | 51 | INC_BONUS = $(addprefix $(BONUS_DIR), $(INC_DIR)) 52 | 53 | INCLUDE += -I $(INC) 54 | INCLUDE += -I $(INC_BONUS) 55 | 56 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 57 | #•❅──────✧❅✦❅✧──────❅••❅──────✧❅✦❅✧─SORCES─✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──────❅•# 58 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 59 | 60 | SL_SRCS = so_long.c check_valid_path.c checker.c end_screen.c \ 61 | errors.c file_to_image.c ft_free.c \ 62 | generate_map_array.c key_hook.c\ 63 | map_printer.c movements.c \ 64 | 65 | SL_SRCS_BONUS = so_long_bonus.c animation_monster_bonus.c checker_bonus.c \ 66 | errors_bonus.c file_to_image_bonus.c ft_free_bonus.c \ 67 | generate_map_array_bonus.c key_hook_bonus.c \ 68 | map_printer_bonus.c move_animation_bonus.c movements_bonus.c \ 69 | movements_monster_bonus.c \ 70 | scan_monster_bonus.c end_screen_bonus.c check_valid_path_bonus.c\ 71 | 72 | SRCS += $(addprefix $(MDT_DIR), $(addprefix $(SRC_DIR), $(SL_SRCS))) 73 | SRCS_BONUS += $(addprefix $(BONUS_DIR), $(addprefix $(SRC_DIR), $(SL_SRCS_BONUS))) 74 | 75 | OBJS = $(addprefix $(OBJ_DIR), $(SRCS:.c=.o)) 76 | OBJS_BONUS = $(addprefix $(OBJ_DIR), $(SRCS_BONUS:.c=.o)) 77 | 78 | DEPS += $(addsuffix .d, $(basename $(OBJS))) 79 | DEPS_BONUS += $(addsuffix .d, $(basename $(OBJS_BONUS))) 80 | 81 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 82 | #•❅──────✧❅✦❅✧──────❅••❅───OBJECT DEPENDENCY TARGET───❅••❅──────✧❅✦❅✧──────❅•# 83 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 84 | 85 | $(OBJ_DIR)%.o : %.c Makefile 86 | @$(MD) $(dir $@) 87 | @make -sC mlx 88 | @make -sC libft 89 | @echo "$(WARN_COLOR)Compiling: $<$(NO_COLOR)" 90 | @$(CC) -MT $@ -MMD -MP -c $(CFLAGS) $(INCLUDE) -Imlx $< -o $@ 91 | 92 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 93 | #•❅──────✧❅✦❅✧──────❅••❅──────✧❅✦❅✧─TARGET─✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──────❅•# 94 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 95 | 96 | all: $(NAME) 97 | 98 | $(NAME): $(OBJS) 99 | @$(CC) $(CFLAGS) $(LIBFT) $(OBJS) -o $(NAME) $(MLXFLAGS) 100 | @echo "$(OK_COLOR)So Long Compiled!$(NO_COLOR)" 101 | 102 | bonus: $(NAME_BONUS) 103 | 104 | $(NAME_BONUS): $(OBJS_BONUS) 105 | @$(CC) $(CFLAGS) $(LIBFT) $(OBJS_BONUS) -o $(NAME_BONUS) $(MLXFLAGS) 106 | @echo "$(OK_COLOR)So Long Bonus Compiled!$(NO_COLOR)" 107 | clean: 108 | @make clean -sC mlx 109 | @make clean -sC libft 110 | @$(RM) -r $(OBJ_DIR) 111 | @$(RM) get_next_line/get_next_line.o 112 | @echo "$(ERROR_COLOR)Dependencies and objects removed$(NO_COLOR)" 113 | 114 | fclean: clean 115 | @make fclean -sC libft 116 | @$(RM) $(NAME) $(NAME_BONUS) 117 | @echo "$(ERROR_COLOR)Programs removed$(NO_COLOR)" 118 | 119 | re: fclean all 120 | 121 | 122 | -include $(DEPS) 123 | -include $(DEPS_BONUS) 124 | 125 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○IGNORE○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 126 | 127 | .PHONY: all bonus clean fclean re 128 | 129 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 130 | #•❅──────✧❅✦❅✧──────❅••❅──────✧❅✦❅✧─COLOR──✧❅✦❅✧──────❅••❅──────✧❅✦❅✧──────❅•# 131 | #●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●●○●○●○●○●○●○●○●○●○●# 132 | 133 | NO_COLOR = \x1b[0m 134 | OK_COLOR = \x1b[32;01m 135 | ERROR_COLOR = \x1b[31;01m 136 | WARN_COLOR = \x1b[33;01m 137 | 138 | OK_STRING = $(OK_COLOR)[OK]$(NO_COLOR) 139 | ERROR_STRING = $(ERROR_COLOR)[ERRORS]$(NO_COLOR) 140 | WARN_STRING = $(WARN_COLOR)[WARNINGS]$(NO_COLOR) 141 | 142 | 143 | -------------------------------------------------------------------------------- /Resources/Estrellita.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *_851423ae0984d19ac3293daa476026ekadH6BrC9s96RtXZ[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "48 50 206 2 ", 5 | " c None", 6 | ". c #242109", 7 | "X c #23261F", 8 | "o c #282012", 9 | "O c #3A2E1C", 10 | "+ c #362B18", 11 | "@ c #39321D", 12 | "# c #3D3421", 13 | "$ c #393429", 14 | "% c #282922", 15 | "& c #402F00", 16 | "* c #4B361C", 17 | "= c #523A07", 18 | "- c #473920", 19 | "; c #5F431D", 20 | ": c #6A6100", 21 | "> c #7A7313", 22 | ", c #594829", 23 | "< c #664C27", 24 | "1 c #69542B", 25 | "2 c #735426", 26 | "3 c #775C31", 27 | "4 c #6E6421", 28 | "5 c #706343", 29 | "6 c #8C5200", 30 | "7 c #8E5800", 31 | "8 c #935C00", 32 | "9 c #975A03", 33 | "0 c #9B6101", 34 | "q c #98610B", 35 | "w c #A46901", 36 | "e c #AA6D00", 37 | "r c #AE7101", 38 | "t c #B47502", 39 | "y c #B67A01", 40 | "u c #BC7C01", 41 | "i c #A87416", 42 | "p c #B67B14", 43 | "a c #805F2F", 44 | "s c #876737", 45 | "d c #C07E00", 46 | "f c #BF900E", 47 | "g c #AF870F", 48 | "h c #B88823", 49 | "j c #B79221", 50 | "k c #BE9535", 51 | "l c #C48304", 52 | "z c #C88706", 53 | "x c #CC8B06", 54 | "c c #CE8D0A", 55 | "v c #C08F05", 56 | "b c #D18E0A", 57 | "n c #C4960D", 58 | "m c #CF960E", 59 | "M c #D29307", 60 | "N c #D3930A", 61 | "B c #D7990E", 62 | "V c #DA9B0B", 63 | "C c #C78813", 64 | "Z c #CB9917", 65 | "A c #D39813", 66 | "S c #DEA00E", 67 | "D c #C6A31C", 68 | "F c #C9A41C", 69 | "G c #CDAB1C", 70 | "H c #DCA414", 71 | "J c #D1AB1D", 72 | "K c #DDAB1D", 73 | "L c #D8A117", 74 | "P c #D1B31E", 75 | "I c #E2A30E", 76 | "U c #E0A612", 77 | "Y c #E4AA13", 78 | "T c #EAAF11", 79 | "R c #E7B217", 80 | "E c #E9B214", 81 | "W c #E4B41C", 82 | "Q c #EBB61A", 83 | "! c #ECBC1C", 84 | "~ c #C79427", 85 | "^ c #D39825", 86 | "/ c #D09830", 87 | "( c #C99E39", 88 | ") c #C7A523", 89 | "_ c #CEA729", 90 | "` c #D9AF22", 91 | "' c #CFB225", 92 | "] c #CFB628", 93 | "[ c #D1B322", 94 | "{ c #DFB12D", 95 | "} c #D4B929", 96 | "| c #CDA637", 97 | " . c #DAAB3A", 98 | ".. c #D8A735", 99 | "X. c #DDB133", 100 | "o. c #EABD24", 101 | "O. c #E2B42D", 102 | "+. c #E6BB2D", 103 | "@. c #E9BE2B", 104 | "#. c #E5B723", 105 | "$. c #E0B335", 106 | "%. c #EFC01E", 107 | "&. c #F0C01C", 108 | "*. c #DCC425", 109 | "=. c #D7C32B", 110 | "-. c #DCC22C", 111 | ";. c #DAC82C", 112 | ":. c #EDC323", 113 | ">. c #EBC32B", 114 | ",. c #E2CD2B", 115 | "<. c #EEC92A", 116 | "1. c #E8C82A", 117 | "2. c #F1C521", 118 | "3. c #F3CD25", 119 | "4. c #F3CE2A", 120 | "5. c #F0C72C", 121 | "6. c #E5D42E", 122 | "7. c #ECDE2D", 123 | "8. c #F3D32A", 124 | "9. c #F8D329", 125 | "0. c #F9DC2D", 126 | "q. c #F4D026", 127 | "w. c #EFCA30", 128 | "e. c #EFCA36", 129 | "r. c #F1CD39", 130 | "t. c #E6D433", 131 | "y. c #E6D936", 132 | "u. c #F5DC31", 133 | "i. c #FEF82D", 134 | "p. c #EAE134", 135 | "a. c #EDE53C", 136 | "s. c #EFEB3A", 137 | "d. c #FBE434", 138 | "f. c #FEE936", 139 | "g. c #F2EB3B", 140 | "h. c #FEEB3B", 141 | "j. c #F0E636", 142 | "k. c #FDF43C", 143 | "l. c #FEFD3F", 144 | "z. c #F4F03D", 145 | "x. c #9D9576", 146 | "c. c #DBAA48", 147 | "v. c #D0A250", 148 | "b. c #DCB459", 149 | "n. c #CAAA4C", 150 | "m. c #E4BE4A", 151 | "M. c #E2B843", 152 | "N. c #E2BC53", 153 | "B. c #E0BD5C", 154 | "V. c #E1B257", 155 | "C. c #DAB769", 156 | "Z. c #D8BB75", 157 | "A. c #D2C557", 158 | "S. c #E9C446", 159 | "D. c #E9C34C", 160 | "F. c #E8CA46", 161 | "G. c #E7C455", 162 | "H. c #F1DA55", 163 | "J. c #ECE146", 164 | "K. c #FFEF41", 165 | "L. c #FEE648", 166 | "P. c #FEF344", 167 | "I. c #FEFD44", 168 | "U. c #FDFD4C", 169 | "Y. c #FFF14A", 170 | "T. c #FBFE53", 171 | "R. c #F6FF5C", 172 | "E. c #FCFF5B", 173 | "W. c #F7FF53", 174 | "Q. c #E9E257", 175 | "!. c #E4C56C", 176 | "~. c #E4C260", 177 | "^. c #ECD969", 178 | "/. c #F0D367", 179 | "(. c #F3DA68", 180 | "). c #E8CA76", 181 | "_. c #F2D777", 182 | "`. c #FCFF63", 183 | "'. c #FEFF6B", 184 | "]. c #F5FF61", 185 | "[. c #FFFF75", 186 | "{. c #FFFF7C", 187 | "}. c #C0AE82", 188 | "|. c #E3C284", 189 | " X c #EAD28A", 190 | ".X c #E8CE93", 191 | "XX c #E8D297", 192 | "oX c #FFFF83", 193 | "OX c #FFFE8B", 194 | "+X c #F1E693", 195 | "@X c #FEFF95", 196 | "#X c #FEFE9C", 197 | "$X c #FAE684", 198 | "%X c #DCD1BA", 199 | "&X c #D6CBAA", 200 | "*X c #FFFFA9", 201 | "=X c #FEFFA6", 202 | "-X c #FEFFBA", 203 | ";X c #FEFEC8", 204 | ":X c #FFFFD8", 205 | ">X c #FFFFE5", 206 | ",X c #FFFFF3", 207 | "X2X2Xa.t.XX ", 222 | " _.w.` -.2X2X2X`.j.t. ", 223 | " F.<.Z t.2X2X2X[.I.p. ", 224 | " w.>.D p.2X2X2XoXT.g.^. ", 225 | " _.5.) ] `.2X2X2XOX`.U.p.J. ", 226 | " F.>.) } OX2X2X2XOX`.W.s.p.Q. ", 227 | " /.w.[ ' =.>X2X2X2XoX'.].I.s.y. ", 228 | " r.@.) [ =.s.2X2X2X*X[.[.`.W.I.z.6.;.*.P P J P [ } C. ", 229 | " H.n n F } ;.oX2X2X:X@X[.'.'.R.W.I.p.6.,.*.*.*.*.*.,.J.+X ", 230 | " S.Z g n F G 6.[.2X2X3X*XoX[.'.'.].R.W.z.z.p.6.6.6.p.s.z.h.(. ", 231 | " $Xm.f v m J G P ,.E.;X2X2X2X:X@XoX[.'.`.`.R.W.W.U.U.U.I.l.l.l.k.f.5.|. ", 232 | " ) D D G [ } 7.T.@X2X2X2X2X2X2X#XoX[.'.`.`.].T.. # l.U.U.I.I.l.f.d.7... ", 233 | " F.[ *.6.[.=X,X2X2X2X2X2X2X2X,X-XoXo + E.`.E.E.T.o x.i.I.I.k.h.h.u.8.:.C. ", 234 | " /.1.I.U.R.[.[.{.OX@X@X#X#X#XoX[.[.A., 3X5 T.U.U.P.+ &XY.j.d.0.0.9.o.U ^ ", 235 | " Xe.g.I.U.`.`.`.[.[.{.{.{.[.[.'.E.> 1 3X%XU.P.P.k.O 1 g u.0.8.8.:.U A C. ", 236 | " B.W W 5.P.U.T.`.`.'.'.'.`.E.E.T.: , %X}.P.P.h.f.@ ; = 4.4.2.2.o.N / ", 237 | " G.O.@.B L o.u.f.h.P.Y.P.P.h.k.J.* < 2 0.0.0.3.- < 1 ! :.Q Y B v. ", 238 | " ~.$.@.A N R o.4.d.f.f.f.f.f.L.* 2 a 9.9.q.&.$ < 1 ! Q Y S N ", 239 | " ).O.@.` N B H :.3.9.0.0.0.8.* a s 3.&.&.! + , 1 R Y U B b ", 240 | " XXM.{ @.` c N V Y %.&.&.&.X 3 s Q E E T Y $ U U V B b / ", 241 | " M.O.@.` c N V R ! ! &.@ X % E Y T Y S S S S B V c c. ", 242 | " .X{ +.+.c c B Y T E E T 4 j Y T Y I I S V V V M c b. ", 243 | " $.X.+.#.N c B I I Y Y Y I I V S V V V N N N N b V. ", 244 | " M.O.+.@.A b B V H I I I I V V V V N N N N b b b c. ", 245 | " N.O.+.<.H N N V V S V V V V V V N M M N x x x b . ", 246 | " G.@.>.>.H N N N M N N M M M M b x z x z z z z C ^ ", 247 | " G.+.>.:.L N b x b M M M M x l l d d d l d z l z ^ ", 248 | " G.@.>.o.A N x x x x x x x d u t e e t u u u l l C ", 249 | " D.@.<.#.m c l l l l l t w 7 6 9 9 6 6 7 9 e t u C ", 250 | " D.>.<.Y c l l l u y w 8 7 h | ./ j i 6 7 9 t t p ", 251 | " D.>.<.L z l u y t 9 7 9 ( !.N. .h q 6 9 e p ", 252 | " D.<.<.c u t 0 0 0 B. Xb.Z. ", 253 | " D.<.>.l t e 0 8 k ", 254 | " G.>.>.y r w i ~. ", 255 | " S.O.~ | !. ", 256 | " ). X ", 257 | " ", 258 | " ", 259 | " ", 260 | " ", 261 | " " 262 | }; 263 | --------------------------------------------------------------------------------