├── lib ├── libft │ ├── get-next-line │ │ ├── files │ │ │ ├── empty │ │ │ ├── nl │ │ │ ├── multiple_nlx5 │ │ │ ├── 41_no_nl │ │ │ ├── 42_no_nl │ │ │ ├── 43_no_nl │ │ │ ├── 41_with_nl │ │ │ ├── 42_with_nl │ │ │ ├── 43_with_nl │ │ │ ├── multiple_line_no_nl │ │ │ ├── multiple_line_with_nl │ │ │ ├── alternate_line_nl_no_nl │ │ │ └── alternate_line_nl_with_nl │ │ ├── get_next_line_utils.c │ │ └── get_next_line.h │ ├── libft42.a │ ├── ft_printf │ │ ├── libft │ │ │ ├── libft.a │ │ │ ├── ft_putchar_fd.c │ │ │ ├── ft_isascii.c │ │ │ ├── ft_isdigit.c │ │ │ ├── ft_isprint.c │ │ │ ├── ft_tolower.c │ │ │ ├── ft_toupper.c │ │ │ ├── ft_lstdelone.c │ │ │ ├── ft_putstr_fd.c │ │ │ ├── ft_strlen.c │ │ │ ├── ft_isalpha.c │ │ │ ├── ft_lstiter.c │ │ │ ├── ft_putendl_fd.c │ │ │ ├── ft_isalnum.c │ │ │ ├── ft_lstadd_front.c │ │ │ ├── ft_lstlast.c │ │ │ ├── ft_bzero.c │ │ │ ├── ft_lstadd_back.c │ │ │ ├── ft_memset.c │ │ │ ├── ft_lstsize.c │ │ │ ├── ft_lstnew.c │ │ │ ├── ft_memcpy.c │ │ │ ├── ft_memchr.c │ │ │ ├── ft_strchr.c │ │ │ ├── ft_strncmp.c │ │ │ ├── ft_calloc.c │ │ │ ├── ft_lstclear.c │ │ │ ├── ft_strdup.c │ │ │ ├── ft_strrchr.c │ │ │ ├── ft_putnbr_fd.c │ │ │ ├── ft_strjoin.c │ │ │ ├── ft_strlcpy.c │ │ │ ├── ft_strmapi.c │ │ │ ├── ft_memccpy.c │ │ │ ├── ft_memmove.c │ │ │ ├── ft_memcmp.c │ │ │ ├── ft_substr.c │ │ │ ├── ft_strlcat.c │ │ │ ├── ft_strnstr.c │ │ │ ├── ft_lstmap.c │ │ │ ├── ft_itoa.c │ │ │ ├── Makefile │ │ │ ├── ft_atoi.c │ │ │ └── ft_strtrim.c │ │ ├── libftprintf.a │ │ ├── print_string.c │ │ ├── ft_printf.h │ │ ├── Makefile │ │ ├── print_number.c │ │ ├── utils.c │ │ └── ft_printf.c │ ├── .gitignore │ ├── libft │ │ ├── ft_putchar_fd.c │ │ ├── ft_isascii.c │ │ ├── ft_isdigit.c │ │ ├── ft_isprint.c │ │ ├── ft_tolower.c │ │ ├── ft_toupper.c │ │ ├── ft_lstdelone.c │ │ ├── ft_putstr_fd.c │ │ ├── ft_strlen.c │ │ ├── ft_isalpha.c │ │ ├── ft_lstiter.c │ │ ├── ft_putendl_fd.c │ │ ├── ft_isalnum.c │ │ ├── ft_lstadd_front.c │ │ ├── ft_lstlast.c │ │ ├── ft_bzero.c │ │ ├── ft_lstadd_back.c │ │ ├── ft_memset.c │ │ ├── ft_lstsize.c │ │ ├── ft_lstnew.c │ │ ├── ft_memcpy.c │ │ ├── ft_memchr.c │ │ ├── ft_strchr.c │ │ ├── ft_strncmp.c │ │ ├── ft_calloc.c │ │ ├── ft_lstclear.c │ │ ├── ft_strdup.c │ │ ├── ft_strrchr.c │ │ ├── ft_putnbr_fd.c │ │ ├── ft_strlcpy.c │ │ ├── ft_strjoin.c │ │ ├── ft_strmapi.c │ │ ├── ft_memccpy.c │ │ ├── ft_memmove.c │ │ ├── ft_memcmp.c │ │ ├── ft_substr.c │ │ ├── ft_strlcat.c │ │ ├── ft_strnstr.c │ │ ├── ft_lstmap.c │ │ ├── ft_itoa.c │ │ ├── Makefile │ │ ├── ft_atoi.c │ │ └── ft_strtrim.c │ ├── include │ │ ├── libft42.h │ │ ├── ft_printf.h │ │ └── get_next_line.h │ └── Makefile └── mlx │ ├── font.xcf │ ├── mlx_png.h │ ├── Makefile │ ├── mlx_opengl.h │ ├── mlx_mouse.m │ ├── mlx_opengl.m │ ├── mlx_new_window.h │ ├── mlx_int_str_to_wordtab.c │ └── mlx_int.h ├── map_file ├── map_wall_error.ber ├── map_no_exit.ber ├── map_no_player.ber ├── map_no_rect.ber ├── map.ber ├── map_no_collection.ber ├── map_bonus.ber ├── map_big.ber ├── map_bigger_bonus.ber └── map_biggest_bonus.ber ├── .gitignore ├── include_bonus ├── error_bonus.h ├── game_bonus.h ├── parse_bonus.h ├── hook_bonus.h ├── draw_bonus.h └── utils_bonus.h ├── src ├── utils │ ├── ft_put_img.c │ ├── ft_get_line.c │ ├── ft_ptr_realloc.c │ ├── ft_make_xpm_img.c │ ├── ft_make_iterable_sprites.c │ └── ft_lst_component.c ├── error │ └── error.c ├── main.c ├── hook │ ├── loop_hook.c │ └── key_hook.c ├── draw │ └── draw_animate.c └── game │ └── game.c ├── LICENSE ├── src_bonus ├── utils_bonus │ ├── ft_put_img_bonus.c │ ├── ft_get_line_bonus.c │ ├── ft_ptr_realloc_bonus.c │ ├── ft_make_iterable_sprites_bonus.c │ ├── ft_make_xpm_img_bonus.c │ └── ft_lst_component_bonus.c ├── error_bonus │ └── error_bonus.c ├── game_bonus │ ├── close_game_bonus.c │ ├── start_game_bonus.c │ └── restart_game_bonus.c ├── hook_bonus │ ├── loop_hook_bonus.c │ ├── key_hook_bonus.c │ └── handle_player_bonus.c ├── draw_bonus │ ├── draw_step_bonus.c │ ├── draw_screen_bonus.c │ ├── draw_partial_bonus.c │ └── draw_animate_bonus.c └── main_bonus.c └── README.md /lib/libft/get-next-line/files/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/nl: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /map_file/map_wall_error.ber: -------------------------------------------------------------------------------- 1 | 1011 2 | 1001 3 | 1111 4 | -------------------------------------------------------------------------------- /map_file/map_no_exit.ber: -------------------------------------------------------------------------------- 1 | 1111 2 | 1001 3 | 1PC1 4 | 1111 5 | -------------------------------------------------------------------------------- /map_file/map_no_player.ber: -------------------------------------------------------------------------------- 1 | 1111 2 | 10C1 3 | 1E01 4 | 1111 5 | -------------------------------------------------------------------------------- /map_file/map_no_rect.ber: -------------------------------------------------------------------------------- 1 | 11111 2 | 10P1 3 | 1CE1 4 | 1111 5 | -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/multiple_nlx5: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /map_file/map.ber: -------------------------------------------------------------------------------- 1 | 11111111 2 | 1P000C01 3 | 1C0E0C01 4 | 11111111 5 | -------------------------------------------------------------------------------- /map_file/map_no_collection.ber: -------------------------------------------------------------------------------- 1 | 1111 2 | 10P1 3 | 1E11 4 | 1111 5 | -------------------------------------------------------------------------------- /map_file/map_bonus.ber: -------------------------------------------------------------------------------- 1 | 11111111 2 | 1P0F0CF1 3 | 1CFE0C01 4 | 11111111 5 | -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/41_no_nl: -------------------------------------------------------------------------------- 1 | 01234567890123456789012345678901234567890 -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/42_no_nl: -------------------------------------------------------------------------------- 1 | 012345678901234567890123456789012345678901 -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/43_no_nl: -------------------------------------------------------------------------------- 1 | 0123456789012345678901234567890123456789012 -------------------------------------------------------------------------------- /lib/mlx/font.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nyeoni/so_long/HEAD/lib/mlx/font.xcf -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/41_with_nl: -------------------------------------------------------------------------------- 1 | 0123456789012345678901234567890123456789 2 | 0 -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/42_with_nl: -------------------------------------------------------------------------------- 1 | 01234567890123456789012345678901234567890 2 | 1 -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/43_with_nl: -------------------------------------------------------------------------------- 1 | 012345678901234567890123456789012345678901 2 | 2 -------------------------------------------------------------------------------- /lib/libft/libft42.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nyeoni/so_long/HEAD/lib/libft/libft42.a -------------------------------------------------------------------------------- /map_file/map_big.ber: -------------------------------------------------------------------------------- 1 | 11111111111 2 | 1PCF0CF0CF1 3 | 1C0EC000C01 4 | 10C0C01CF01 5 | 11111111111 6 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/libft.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nyeoni/so_long/HEAD/lib/libft/ft_printf/libft/libft.a -------------------------------------------------------------------------------- /lib/libft/ft_printf/libftprintf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nyeoni/so_long/HEAD/lib/libft/ft_printf/libftprintf.a -------------------------------------------------------------------------------- /lib/mlx/mlx_png.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | void *mlx_png_file_to_image(void *xvar, char *file, int *width, int *height); 5 | -------------------------------------------------------------------------------- /lib/libft/.gitignore: -------------------------------------------------------------------------------- 1 | *.pdf 2 | pdf/ 3 | images/ 4 | *.dSYM 5 | a.out 6 | .vscode 7 | .vscode/ 8 | .vscode/* 9 | .idea 10 | born2beroot/* 11 | ./.vscode/* 12 | *.o 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | .vscode/ 7 | .vscode 8 | 9 | # Execute File 10 | a.out 11 | *.dSYM 12 | so_long 13 | so_long_bonus 14 | 15 | *.a -------------------------------------------------------------------------------- /map_file/map_bigger_bonus.ber: -------------------------------------------------------------------------------- 1 | 111111111111111111111111 2 | 1PCF0CF0CF0CF0CF0CF00001 3 | 1C0EC000C00CF0CF0CF00001 4 | 10C0C01CF00C00CF0C000001 5 | 10000000000CF0CF0CF00001 6 | 100C000C000CF0C00CF00001 7 | 1F00C0F0000C00CF0CF00001 8 | 111111111111111111111111 9 | -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/multiple_line_no_nl: -------------------------------------------------------------------------------- 1 | 01234567890123456789012345678901234567890 2 | 987654321098765432109876543210987654321098 3 | 0123456789012345678901234567890123456789012 4 | 987654321098765432109876543210987654321098 5 | 01234567890123456789012345678901234567890 -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/multiple_line_with_nl: -------------------------------------------------------------------------------- 1 | 9876543210987654321098765432109876543210 2 | 01234567890123456789012345678901234567890 3 | 987654321098765432109876543210987654321098 4 | 01234567890123456789012345678901234567890 5 | 9876543210987654321098765432109876543210 6 | -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/alternate_line_nl_no_nl: -------------------------------------------------------------------------------- 1 | 98765432109876543210987654321098765432109 2 | 3 | 012345678901234567890123456789012345678901 4 | 5 | 9876543210987654321098765432109876543210987 6 | 7 | 012345678901234567890123456789012345678901 8 | 9 | 98765432109876543210987654321098765432109 -------------------------------------------------------------------------------- /lib/libft/get-next-line/files/alternate_line_nl_with_nl: -------------------------------------------------------------------------------- 1 | 01234567890123456789012345678901234567890 2 | 3 | 987654321098765432109876543210987654321090 4 | 5 | 0123456789012345678901234567890123456789012 6 | 7 | 987654321098765432109876543210987654321090 8 | 9 | 01234567890123456789012345678901234567890 10 | -------------------------------------------------------------------------------- /map_file/map_biggest_bonus.ber: -------------------------------------------------------------------------------- 1 | 111111111111111111111111 2 | 1PCF0CF0CF0CF0CF0CF00001 3 | 1C0EC000C00CF0CF0CF00001 4 | 10C0C01CF00C00CF0C000001 5 | 10000000000CF0CF0CF00001 6 | 100C000C000CF0C00CF00001 7 | 1F00C0F0000C00CF0CF00001 8 | 100000C0000000C000000F01 9 | 100000C0000000C000000F01 10 | 100000C0000000C000000F01 11 | 111111111111111111111111 -------------------------------------------------------------------------------- /lib/mlx/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | 4 | NOM=libmlx.a 5 | SRC= mlx_shaders.c mlx_new_window.m mlx_init_loop.m mlx_new_image.m mlx_xpm.c mlx_int_str_to_wordtab.c 6 | SRC+= mlx_png.c mlx_mouse.m 7 | OBJ1=$(SRC:.c=.o) 8 | OBJ=$(OBJ1:.m=.o) 9 | CFLAGS+=-O2 10 | 11 | # add to match string put with X11 in size and position 12 | CFLAGS+= -DSTRINGPUTX11 13 | 14 | all: $(NOM) 15 | 16 | $(NOM): $(OBJ) 17 | ar -r $(NOM) $(OBJ) 18 | ranlib $(NOM) 19 | 20 | clean: 21 | rm -f $(NOM) $(OBJ) *~ 22 | rm -f mlx_app 23 | 24 | re: clean all 25 | -------------------------------------------------------------------------------- /lib/mlx/mlx_opengl.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | ** mlx_opengl.h 4 | ** 5 | ** public include, use it after mlx.h 6 | ** designed only for minilibx_macos 7 | ** 8 | */ 9 | 10 | void *mlx_new_opengl_window(void *mlx_ptr, int size_x, int size_y, char *title); 11 | 12 | /* create an opengl window. put_image & pixel_put & string_put do not work there. */ 13 | 14 | int mlx_opengl_swap_buffers(void *win_ptr); 15 | 16 | /* the created window is double buffered. Use this funct to swap buffers */ 17 | /* this funct will call glFlush(). Don't call it. */ 18 | 19 | int mlx_opengl_window_set_context(void *win_ptr); 20 | 21 | /* in case multiple opengl windows are present, change opengl active context */ 22 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:05:55 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:10:36 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:05:55 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:10:36 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:26:45 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:40:11 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isascii(int c) 14 | { 15 | if (c >= 0 && c <= 127) 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 19:19:12 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:41:01 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isdigit(int c) 14 | { 15 | if (c >= '0' && c <= '9') 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:28:01 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:41:24 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isprint(int c) 14 | { 15 | if (c >= 32 && c < 127) 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:31:36 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:16:02 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_tolower(int c) 14 | { 15 | if (c >= 'A' && c <= 'Z') 16 | return (c + 32); 17 | else 18 | return (c); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:29:35 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:16:18 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_toupper(int c) 14 | { 15 | if (c >= 'a' && c <= 'z') 16 | return (c - 32); 17 | else 18 | return (c); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:26:45 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:40:11 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isascii(int c) 14 | { 15 | if (c >= 0 && c <= 127) 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 19:19:12 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:41:01 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isdigit(int c) 14 | { 15 | if (c >= '0' && c <= '9') 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:28:01 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:41:24 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isprint(int c) 14 | { 15 | if (c >= 32 && c < 127) 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:31:36 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:16:02 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_tolower(int c) 14 | { 15 | if (c >= 'A' && c <= 'Z') 16 | return (c + 32); 17 | else 18 | return (c); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:29:35 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:16:18 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_toupper(int c) 14 | { 15 | if (c >= 'a' && c <= 'z') 16 | return (c - 32); 17 | else 18 | return (c); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/include/libft42.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft42.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/18 15:27:21 by nkim #+# #+# */ 9 | /* Updated: 2022/01/18 15:29:03 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT42_H 14 | # define LIBFT42_H 15 | 16 | # include "libft.h" 17 | # include "get_next_line.h" 18 | # include "ft_printf.h" 19 | 20 | #endif -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:11:19 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:05:45 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void *)) 16 | { 17 | (*del)(lst->content); 18 | free(lst); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:08:59 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:11:42 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr_fd(char *s, int fd) 16 | { 17 | if (!s) 18 | return ; 19 | write(fd, s, ft_strlen(s)); 20 | } 21 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:11:19 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:05:45 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void *)) 16 | { 17 | (*del)(lst->content); 18 | free(lst); 19 | } 20 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:08:59 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:11:42 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr_fd(char *s, int fd) 16 | { 17 | if (!s) 18 | return ; 19 | write(fd, s, ft_strlen(s)); 20 | } 21 | -------------------------------------------------------------------------------- /include_bonus/error_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* error_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:49:59 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:00:21 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ERROR_BONUS_H 14 | # define ERROR_BONUS_H 15 | 16 | # include "../lib/libft/include/libft42.h" 17 | 18 | void throw_error(char *message); 19 | 20 | #endif -------------------------------------------------------------------------------- /src/utils/ft_put_img.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_put_img.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 23:16:56 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:53:47 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void ft_put_img(t_game *game, void *img, int x, int y) 16 | { 17 | mlx_put_image_to_window(game->mlx_ptr, game->win_ptr, img, x, y); 18 | } 19 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:22:36 by nkim #+# #+# */ 9 | /* Updated: 2021/08/13 21:58:31 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | size_t len; 18 | 19 | len = 0; 20 | while (s[len]) 21 | len++; 22 | return (len); 23 | } 24 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 18:58:25 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:39:19 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isalpha(int c) 14 | { 15 | if ('A' <= c && c <= 'Z') 16 | return (1); 17 | else if ('a' <= c && c <= 'z') 18 | return (2); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 16:31:09 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:06:09 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | while (lst) 18 | { 19 | (*f)(lst->content); 20 | lst = lst->next; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:14:28 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:10:54 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl_fd(char *s, int fd) 16 | { 17 | if (!s) 18 | return ; 19 | write(fd, s, ft_strlen(s)); 20 | write(fd, "\n", 1); 21 | } 22 | -------------------------------------------------------------------------------- /src/error/error.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* error.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 16:50:10 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:29:53 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void throw_error(char *message) 16 | { 17 | ft_putstr_fd("\033[31mError\n\033[0m", 2); 18 | ft_putstr_fd(message, 2); 19 | exit(EXIT_FAILURE); 20 | } 21 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:22:36 by nkim #+# #+# */ 9 | /* Updated: 2021/08/13 21:58:31 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | size_t len; 18 | 19 | len = 0; 20 | while (s[len]) 21 | len++; 22 | return (len); 23 | } 24 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:23:33 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:37:31 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isalnum(int c) 14 | { 15 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 16 | || (c >= '0' && c <= '9')) 17 | return (1); 18 | else 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:53:59 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:00:30 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **lst, t_list *new) 16 | { 17 | t_list *tmp; 18 | 19 | tmp = *lst; 20 | *lst = new; 21 | new->next = tmp; 22 | } 23 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:05:34 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:06:30 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | if (!lst) 18 | return (0); 19 | while (lst->next) 20 | lst = lst->next; 21 | return (lst); 22 | } 23 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 18:58:25 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:39:19 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isalpha(int c) 14 | { 15 | if ('A' <= c && c <= 'Z') 16 | return (1); 17 | else if ('a' <= c && c <= 'z') 18 | return (2); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 16:31:09 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:06:09 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | while (lst) 18 | { 19 | (*f)(lst->content); 20 | lst = lst->next; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:14:28 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:10:54 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl_fd(char *s, int fd) 16 | { 17 | if (!s) 18 | return ; 19 | write(fd, s, ft_strlen(s)); 20 | write(fd, "\n", 1); 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 ChloeKim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 01:23:33 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:37:31 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isalnum(int c) 14 | { 15 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 16 | || (c >= '0' && c <= '9')) 17 | return (1); 18 | else 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:53:59 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:00:30 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **lst, t_list *new) 16 | { 17 | t_list *tmp; 18 | 19 | tmp = *lst; 20 | *lst = new; 21 | new->next = tmp; 22 | } 23 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:05:34 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:06:30 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | if (!lst) 18 | return (0); 19 | while (lst->next) 20 | lst = lst->next; 21 | return (lst); 22 | } 23 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 17:00:36 by nkim #+# #+# */ 9 | /* Updated: 2021/06/18 20:02:51 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | *((char *)src + i) = 0; 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src_bonus/utils_bonus/ft_put_img_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_put_img_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 23:16:56 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:05:54 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "utils_bonus.h" 14 | 15 | void ft_put_img(t_game *game, void *img, int x, int y) 16 | { 17 | mlx_put_image_to_window(game->mlx_ptr, game->win_ptr, img, x, y); 18 | } 19 | -------------------------------------------------------------------------------- /src_bonus/error_bonus/error_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* error_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 16:50:10 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:00:27 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "error_bonus.h" 14 | 15 | void throw_error(char *message) 16 | { 17 | ft_putstr_fd("\033[31mError\n\033[0m", 2); 18 | ft_putstr_fd(message, 2); 19 | exit(EXIT_FAILURE); 20 | } 21 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 17:00:36 by nkim #+# #+# */ 9 | /* Updated: 2021/06/18 20:02:51 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | *((char *)src + i) = 0; 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:07:35 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:59:52 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | if (!*lst) 18 | { 19 | *lst = new; 20 | return ; 21 | } 22 | ft_lstlast(*lst)->next = new; 23 | } 24 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:07:35 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 18:59:52 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | if (!*lst) 18 | { 19 | *lst = new; 20 | return ; 21 | } 22 | ft_lstlast(*lst)->next = new; 23 | } 24 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 14:22:20 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:10:08 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *dst, int value, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | *((char *)dst + i) = value; 23 | i++; 24 | } 25 | return (dst); 26 | } 27 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 14:22:20 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:10:08 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *dst, int value, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | *((char *)dst + i) = value; 23 | i++; 24 | } 25 | return (dst); 26 | } 27 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:01:05 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:07:27 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int cnt; 18 | 19 | if (!lst) 20 | return (0); 21 | cnt = 1; 22 | while (lst->next) 23 | { 24 | cnt++; 25 | lst = lst->next; 26 | } 27 | return (cnt); 28 | } 29 | -------------------------------------------------------------------------------- /src_bonus/game_bonus/close_game_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* close_game_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:44:44 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:30:44 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "game_bonus.h" 14 | #include 15 | #include 16 | 17 | int close_game(t_game *game) 18 | { 19 | printf("END\n"); 20 | mlx_destroy_window(game->mlx_ptr, game->win_ptr); 21 | exit(EXIT_SUCCESS); 22 | } 23 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:01:05 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:07:27 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int cnt; 18 | 19 | if (!lst) 20 | return (0); 21 | cnt = 1; 22 | while (lst->next) 23 | { 24 | cnt++; 25 | lst = lst->next; 26 | } 27 | return (cnt); 28 | } 29 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:49:19 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:58:48 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *res; 18 | 19 | res = (t_list *)malloc(sizeof(t_list)); 20 | if (!res) 21 | return (0); 22 | res->content = content; 23 | res->next = NULL; 24 | return (res); 25 | } 26 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:49:19 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:58:48 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *res; 18 | 19 | res = (t_list *)malloc(sizeof(t_list)); 20 | if (!res) 21 | return (0); 22 | res->content = content; 23 | res->next = NULL; 24 | return (res); 25 | } 26 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 15:56:08 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:09:06 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dst && !src) 21 | return (0); 22 | while (i < n) 23 | { 24 | *((char *)dst + i) = *((char *)src + i); 25 | i++; 26 | } 27 | return (dst); 28 | } 29 | -------------------------------------------------------------------------------- /lib/libft/get-next-line/get_next_line_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/19 18:25:54 by nkim #+# #+# */ 9 | /* Updated: 2022/01/20 18:05:48 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | 15 | char *ft_strndup(const char *s1, size_t n) 16 | { 17 | char *res; 18 | 19 | res = (char *)malloc(sizeof(char) * (n + 1)); 20 | if (!res) 21 | return (0); 22 | ft_memmove(res, s1, n); 23 | res[n] = '\0'; 24 | return (res); 25 | } 26 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 17:49:56 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:08:17 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memchr(const void *src, int c, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | if (*((unsigned char *)src + i) == (unsigned char)c) 23 | return ((unsigned char *)src + i); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 15:56:08 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:09:06 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dst && !src) 21 | return (0); 22 | while (i < n) 23 | { 24 | *((char *)dst + i) = *((char *)src + i); 25 | i++; 26 | } 27 | return (dst); 28 | } 29 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:25:51 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:59:48 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *src, int c) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (src[i]) 21 | { 22 | if (src[i] == (char)c) 23 | return ((char *)(&src[i])); 24 | i++; 25 | } 26 | if (c == 0) 27 | return ((char *)(&src[i])); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 17:49:56 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:08:17 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memchr(const void *src, int c, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | if (*((unsigned char *)src + i) == (unsigned char)c) 23 | return ((unsigned char *)src + i); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /src_bonus/hook_bonus/loop_hook_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* loop_hook_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 18:07:20 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 07:06:10 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "draw_bonus.h" 14 | #include "hook_bonus.h" 15 | 16 | int loop_hook(t_game *game) 17 | { 18 | if (game->status == NOTSTARTED) 19 | draw_screen(game); 20 | else if (game->status == SUCCESS) 21 | draw_screen(game); 22 | else 23 | handle_player(game); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:25:51 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:59:48 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *src, int c) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (src[i]) 21 | { 22 | if (src[i] == (char)c) 23 | return ((char *)(&src[i])); 24 | i++; 25 | } 26 | if (c == 0) 27 | return ((char *)(&src[i])); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 00:08:07 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:31:02 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (s1[i] == s2[i] && s1[i] && s2[i] && i < n) 21 | i++; 22 | if (!(i == n)) 23 | return ((unsigned char)s1[i] - (unsigned char)s2[i]); 24 | else 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /include_bonus/game_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* game_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:49:59 by nkim #+# #+# */ 9 | /* Updated: 2022/07/15 19:44:03 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GAME_BONUS_H 14 | # define GAME_BONUS_H 15 | 16 | # include "../lib/mlx/mlx.h" 17 | # include "so_long_bonus.h" 18 | 19 | void init_game(t_game *game); 20 | void init_props(t_game *game); 21 | void start_game(t_game *game); 22 | void restart_game(t_game *game); 23 | int close_game(t_game *game); 24 | 25 | #endif -------------------------------------------------------------------------------- /src/utils/ft_get_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_get_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/21 19:18:37 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:48:40 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | char *ft_get_line(int fd) 16 | { 17 | char *line; 18 | char eol; 19 | int len; 20 | 21 | line = get_next_line(fd); 22 | if (!line) 23 | return (NULL); 24 | len = ft_strlen(line); 25 | eol = line[len - 1]; 26 | if (eol == '\n') 27 | line[len - 1] = 0; 28 | return (line); 29 | } 30 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 00:08:07 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:31:02 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (s1[i] == s2[i] && s1[i] && s2[i] && i < n) 21 | i++; 22 | if (!(i == n)) 23 | return ((unsigned char)s1[i] - (unsigned char)s2[i]); 24 | else 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 20:49:59 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:34:12 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t count, size_t size) 16 | { 17 | size_t i; 18 | void *res; 19 | 20 | res = (void *)malloc(size * count); 21 | if (!(res)) 22 | return (0); 23 | i = 0; 24 | while (i < size * count) 25 | { 26 | *((char *)res + i) = '\0'; 27 | i++; 28 | } 29 | return (res); 30 | } 31 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:24:27 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:05:18 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void *)) 16 | { 17 | t_list *tmp; 18 | 19 | while ((*lst)->next) 20 | { 21 | tmp = *lst; 22 | *lst = tmp->next; 23 | (*del)(tmp->content); 24 | free(tmp); 25 | tmp = 0; 26 | } 27 | (*del)((*lst)->content); 28 | free(*lst); 29 | *lst = 0; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 20:49:59 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:34:12 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t count, size_t size) 16 | { 17 | size_t i; 18 | void *res; 19 | 20 | res = (void *)malloc(size * count); 21 | if (!(res)) 22 | return (0); 23 | i = 0; 24 | while (i < size * count) 25 | { 26 | *((char *)res + i) = '\0'; 27 | i++; 28 | } 29 | return (res); 30 | } 31 | -------------------------------------------------------------------------------- /src_bonus/game_bonus/start_game_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* start_game_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:44:26 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 08:07:46 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "draw_bonus.h" 14 | #include 15 | 16 | void start_game(t_game *game) 17 | { 18 | draw_tiles(game); 19 | draw_step(game); 20 | draw_sprites(game); 21 | draw_enemies(game); 22 | draw_exit(game); 23 | printf("\033[1;33m== Start Game ==\033[0m\n"); 24 | game->status = PLAYING; 25 | game->step = 0; 26 | } 27 | -------------------------------------------------------------------------------- /src_bonus/utils_bonus/ft_get_line_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_get_line_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/21 19:18:37 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:05:00 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "utils_bonus.h" 14 | 15 | char *ft_get_line(int fd) 16 | { 17 | char *line; 18 | char eol; 19 | int len; 20 | 21 | line = get_next_line(fd); 22 | if (!line) 23 | return (NULL); 24 | len = ft_strlen(line); 25 | eol = line[len - 1]; 26 | if (eol == '\n') 27 | line[len - 1] = 0; 28 | return (line); 29 | } 30 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 03:24:27 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:05:18 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void *)) 16 | { 17 | t_list *tmp; 18 | 19 | while ((*lst)->next) 20 | { 21 | tmp = *lst; 22 | *lst = tmp->next; 23 | (*del)(tmp->content); 24 | free(tmp); 25 | tmp = 0; 26 | } 27 | (*del)((*lst)->content); 28 | free(*lst); 29 | *lst = 0; 30 | } 31 | -------------------------------------------------------------------------------- /src_bonus/draw_bonus/draw_step_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_step_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 00:47:17 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 05:20:16 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "draw_bonus.h" 14 | #include "hook_bonus.h" 15 | #include "utils_bonus.h" 16 | 17 | void draw_step(t_game *game) 18 | { 19 | char *step; 20 | 21 | step = ft_itoa(game->step); 22 | ft_put_img(game, game->tiles.step, 0, 0); 23 | mlx_string_put(game->mlx_ptr, game->win_ptr, 25, 37, 0x00000000, step); 24 | free(step); 25 | } 26 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 21:17:03 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:34:36 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | int size; 18 | char *res; 19 | 20 | size = ft_strlen(s1); 21 | res = malloc(size + 1); 22 | if (!(res)) 23 | return (0); 24 | size = 0; 25 | while (s1[size]) 26 | { 27 | res[size] = s1[size]; 28 | size++; 29 | } 30 | res[size] = '\0'; 31 | return (res); 32 | } 33 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 21:17:03 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:34:36 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | int size; 18 | char *res; 19 | 20 | size = ft_strlen(s1); 21 | res = malloc(size + 1); 22 | if (!(res)) 23 | return (0); 24 | size = 0; 25 | while (s1[size]) 26 | { 27 | res[size] = s1[size]; 28 | size++; 29 | } 30 | res[size] = '\0'; 31 | return (res); 32 | } 33 | -------------------------------------------------------------------------------- /include_bonus/parse_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* parse_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:49:59 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:22:13 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PARSE_BONUS_H 14 | # define PARSE_BONUS_H 15 | 16 | # include "so_long_bonus.h" 17 | 18 | void parse_map(t_game *game, char *fileName); 19 | void valid_extension(char *fileName); 20 | void valid_characters(char *line); 21 | void valid_length(char *src, int length); 22 | void valid_wall(t_map *map, int row_idx); 23 | void valid_least(t_map *map); 24 | 25 | #endif -------------------------------------------------------------------------------- /lib/libft/libft/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:25:51 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:30:03 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *src, int c) 16 | { 17 | int size; 18 | int i; 19 | 20 | size = ft_strlen(src); 21 | if (c == 0) 22 | return ((char *)&src[size]); 23 | i = 0; 24 | while (i < size) 25 | { 26 | if (src[size - i - 1] == (char)c) 27 | return ((char *)&src[size - i - 1]); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/print_string.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* print_string.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/09/18 15:48:31 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:50:38 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_printf.h" 14 | 15 | int print_c(int arg) 16 | { 17 | int cnt; 18 | char c; 19 | 20 | c = (char)arg; 21 | cnt = write(1, &c, 1); 22 | return (cnt); 23 | } 24 | 25 | int print_s(char *arg) 26 | { 27 | int cnt; 28 | 29 | if (!arg) 30 | cnt = write(1, "(null)", 6); 31 | else 32 | cnt = write(1, arg, ft_strlen(arg)); 33 | return (cnt); 34 | } 35 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:25:51 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:30:03 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *src, int c) 16 | { 17 | int size; 18 | int i; 19 | 20 | size = ft_strlen(src); 21 | if (c == 0) 22 | return ((char *)&src[size]); 23 | i = 0; 24 | while (i < size) 25 | { 26 | if (src[size - i - 1] == (char)c) 27 | return ((char *)&src[size - i - 1]); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:16:20 by nkim #+# #+# */ 9 | /* Updated: 2021/06/22 22:58:22 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | char tmp; 18 | unsigned int nbr; 19 | 20 | nbr = n; 21 | if (n < 0) 22 | { 23 | write(fd, "-", 1); 24 | nbr = n * -1; 25 | } 26 | if (nbr < 10) 27 | tmp = '0' + nbr; 28 | else 29 | { 30 | ft_putnbr_fd(nbr / 10, fd); 31 | tmp = '0' + (nbr % 10); 32 | } 33 | write(fd, &tmp, 1); 34 | } 35 | -------------------------------------------------------------------------------- /lib/mlx/mlx_mouse.m: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #import 4 | #import 5 | 6 | #include "mlx_int.h" 7 | #include "mlx_new_window.h" 8 | 9 | int mlx_mouse_hide() 10 | { 11 | // CGDisplayHideCursor(kCGDirectMainDisplay); 12 | [NSCursor hide]; 13 | return (0); 14 | } 15 | 16 | int mlx_mouse_show() 17 | { 18 | // CGDisplayShowCursor(kCGDirectMainDisplay); 19 | [NSCursor unhide]; 20 | return (0); 21 | } 22 | 23 | int mlx_mouse_move(mlx_win_list_t *win, int x, int y) 24 | { 25 | CGPoint point; 26 | NSRect pos; 27 | id thewin; 28 | 29 | thewin = [(id)(win->winid) win]; 30 | pos = [thewin frame]; 31 | // printf("got win pos %f %f\n", pos.origin.x, pos.origin.y); 32 | point.x = pos.origin.x + x; 33 | point.y = NSHeight([[thewin screen] frame]) - NSHeight([(id)(win->winid) frame]) - pos.origin.y + 1 + y; 34 | CGWarpMouseCursorPosition(point); 35 | CGAssociateMouseAndMouseCursorPosition(true); 36 | return (0); 37 | } 38 | 39 | 40 | int mlx_mouse_get_pos(mlx_win_list_t *win, int *x, int *y) 41 | { 42 | CGPoint point; 43 | id thewin; 44 | NSRect pos; 45 | 46 | thewin = [(id)(win->winid) win]; 47 | pos = [(id)(win->winid) frame]; 48 | point = [thewin mouseLocationOutsideOfEventStream]; 49 | *x = point.x; 50 | *y = NSHeight(pos) - 1 - point.y; 51 | return (0); 52 | } 53 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:16:20 by nkim #+# #+# */ 9 | /* Updated: 2021/06/22 22:58:22 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | char tmp; 18 | unsigned int nbr; 19 | 20 | nbr = n; 21 | if (n < 0) 22 | { 23 | write(fd, "-", 1); 24 | nbr = n * -1; 25 | } 26 | if (nbr < 10) 27 | tmp = '0' + nbr; 28 | else 29 | { 30 | ft_putnbr_fd(nbr / 10, fd); 31 | tmp = '0' + (nbr % 10); 32 | } 33 | write(fd, &tmp, 1); 34 | } 35 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/07 17:00:36 by nkim #+# #+# */ 9 | /* Updated: 2022/02/04 15:10:26 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoin(char const *s1, char const *s2) 16 | { 17 | size_t len1; 18 | size_t len2; 19 | char *res; 20 | 21 | len1 = ft_strlen(s1); 22 | len2 = ft_strlen(s2); 23 | res = (char *)malloc(len1 + len2 + 1); 24 | ft_memccpy(res, s1, 0, len1); 25 | ft_memccpy(res + len1, s2, 0, len2); 26 | res[len1 + len2] = '\0'; 27 | return (res); 28 | } 29 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 00:04:39 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:13:35 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dst || !src) 21 | return (0); 22 | if (dstsize > 0) 23 | { 24 | while (i < dstsize - 1 && src[i]) 25 | { 26 | dst[i] = src[i]; 27 | i++; 28 | } 29 | dst[i] = '\0'; 30 | } 31 | while (src[i]) 32 | i++; 33 | return (i); 34 | } 35 | -------------------------------------------------------------------------------- /src/utils/ft_ptr_realloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ptr_realloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/21 19:10:03 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:53:41 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_ptr_realloc(void *buf, int before_size, int after_size) 16 | { 17 | int idx; 18 | char **src; 19 | char **dst; 20 | 21 | src = (char **)buf; 22 | dst = (char **)malloc(sizeof(char *) * after_size); 23 | idx = 0; 24 | while (idx < before_size) 25 | { 26 | dst[idx] = src[idx]; 27 | idx++; 28 | } 29 | free(buf); 30 | return ((void *)dst); 31 | } 32 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/09 00:04:39 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:13:35 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dst || !src) 21 | return (0); 22 | if (dstsize > 0) 23 | { 24 | while (i < dstsize - 1 && src[i]) 25 | { 26 | dst[i] = src[i]; 27 | i++; 28 | } 29 | dst[i] = '\0'; 30 | } 31 | while (src[i]) 32 | i++; 33 | return (i); 34 | } 35 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/07 17:00:36 by nkim #+# #+# */ 9 | /* Updated: 2022/02/04 15:10:41 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoin(char const *s1, char const *s2) 16 | { 17 | size_t len1; 18 | size_t len2; 19 | char *res; 20 | 21 | if (!s1 || !s2) 22 | return (0); 23 | len1 = ft_strlen(s1); 24 | len2 = ft_strlen(s2); 25 | res = (char *)malloc(len1 + len2 + 1); 26 | ft_memccpy(res, s1, 0, len1); 27 | ft_memccpy(res + len1, s2, 0, len2); 28 | res[len1 + len2] = '\0'; 29 | return (res); 30 | } 31 | -------------------------------------------------------------------------------- /src_bonus/utils_bonus/ft_ptr_realloc_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ptr_realloc_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/21 19:10:03 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:05:50 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "utils_bonus.h" 14 | 15 | void *ft_ptr_realloc(void *buf, int before_size, int after_size) 16 | { 17 | int idx; 18 | char **src; 19 | char **dst; 20 | 21 | src = (char **)buf; 22 | dst = (char **)malloc(sizeof(char *) * after_size); 23 | idx = 0; 24 | while (idx < before_size) 25 | { 26 | dst[idx] = src[idx]; 27 | idx++; 28 | } 29 | free(buf); 30 | return ((void *)dst); 31 | } 32 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/17 18:56:18 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:54:48 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | int main(int argc, char **argv) 16 | { 17 | t_game game; 18 | 19 | if (argc != 2) 20 | throw_error("ArgError : no / over argument!"); 21 | parse_map(&game, argv[1]); 22 | start_game(&game); 23 | mlx_hook(game.win_ptr, KEY_EXIT, 0, &close_game, &game); 24 | mlx_key_hook(game.win_ptr, &key_hook, &game); 25 | mlx_loop_hook(game.mlx_ptr, &loop_hook, &game); 26 | mlx_loop(game.mlx_ptr); 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:36:02 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:32:04 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | size_t size; 18 | size_t i; 19 | char *res; 20 | 21 | if (!s) 22 | return (0); 23 | size = ft_strlen(s); 24 | res = (char *)malloc(sizeof(char) * (size + 1)); 25 | if (!res) 26 | return (0); 27 | i = 0; 28 | while (i < size) 29 | { 30 | res[i] = (*f)(i, s[i]); 31 | i++; 32 | } 33 | res[i] = '\0'; 34 | return (res); 35 | } 36 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 02:36:02 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:32:04 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | size_t size; 18 | size_t i; 19 | char *res; 20 | 21 | if (!s) 22 | return (0); 23 | size = ft_strlen(s); 24 | res = (char *)malloc(sizeof(char) * (size + 1)); 25 | if (!res) 26 | return (0); 27 | i = 0; 28 | while (i < size) 29 | { 30 | res[i] = (*f)(i, s[i]); 31 | i++; 32 | } 33 | res[i] = '\0'; 34 | return (res); 35 | } 36 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 17:10:01 by nkim #+# #+# */ 9 | /* Updated: 2021/06/23 22:36:34 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memccpy(void *dst, const void *src, int c, size_t n) 16 | { 17 | size_t i; 18 | int flag; 19 | 20 | i = 0; 21 | flag = 0; 22 | while (i < n && !flag) 23 | { 24 | *((unsigned char *)dst + i) = *((unsigned char *)src + i); 25 | if (*((unsigned char *)src + i) == (unsigned char)c) 26 | flag = 1; 27 | i++; 28 | } 29 | if (flag) 30 | return ((unsigned char *)dst + i); 31 | else 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 17:10:01 by nkim #+# #+# */ 9 | /* Updated: 2021/06/23 22:36:34 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memccpy(void *dst, const void *src, int c, size_t n) 16 | { 17 | size_t i; 18 | int flag; 19 | 20 | i = 0; 21 | flag = 0; 22 | while (i < n && !flag) 23 | { 24 | *((unsigned char *)dst + i) = *((unsigned char *)src + i); 25 | if (*((unsigned char *)src + i) == (unsigned char)c) 26 | flag = 1; 27 | i++; 28 | } 29 | if (flag) 30 | return ((unsigned char *)dst + i); 31 | else 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /src_bonus/hook_bonus/key_hook_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key_hook_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 18:07:36 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 06:38:01 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "game_bonus.h" 14 | #include "hook_bonus.h" 15 | 16 | int key_hook(int keycode, t_game *game) 17 | { 18 | if (game->status == PLAYING) 19 | handle_moving(keycode, game); 20 | if (game->status == NOTSTARTED 21 | && keycode == KEY_ENTER) 22 | start_game(game); 23 | if ((game->status == FAIL || game->status == SUCCESS) 24 | && keycode == KEY_R) 25 | restart_game(game); 26 | if (keycode == KEY_ESC) 27 | close_game(game); 28 | return (1); 29 | } 30 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 22:56:37 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:09:47 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dst && !src) 21 | return (0); 22 | if (dst <= src) 23 | { 24 | while (i < n) 25 | { 26 | *((char *)dst + i) = *((char *)src + i); 27 | i++; 28 | } 29 | } 30 | else 31 | { 32 | while (i < n) 33 | { 34 | *((char *)dst + (n - i - 1)) = *((char *)src + (n - i - 1)); 35 | i++; 36 | } 37 | } 38 | return (dst); 39 | } 40 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 17:54:19 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:08:35 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | if (*((unsigned char *)s1 + i) > *((unsigned char *)s2 + i)) 23 | return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i)); 24 | else if (*((unsigned char *)s1 + i) < *((unsigned char *)s2 + i)) 25 | return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i)); 26 | i++; 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/04 22:56:37 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:09:47 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dst && !src) 21 | return (0); 22 | if (dst <= src) 23 | { 24 | while (i < n) 25 | { 26 | *((char *)dst + i) = *((char *)src + i); 27 | i++; 28 | } 29 | } 30 | else 31 | { 32 | while (i < n) 33 | { 34 | *((char *)dst + (n - i - 1)) = *((char *)src + (n - i - 1)); 35 | i++; 36 | } 37 | } 38 | return (dst); 39 | } 40 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 17:54:19 by nkim #+# #+# */ 9 | /* Updated: 2021/06/19 19:08:35 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n) 21 | { 22 | if (*((unsigned char *)s1 + i) > *((unsigned char *)s2 + i)) 23 | return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i)); 24 | else if (*((unsigned char *)s1 + i) < *((unsigned char *)s2 + i)) 25 | return (*((unsigned char *)s1 + i) - *((unsigned char *)s2 + i)); 26 | i++; 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /src/hook/loop_hook.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* loop_hook.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 18:07:20 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:43:07 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void move_player(t_game *game) 16 | { 17 | draw_tiles(game); 18 | draw_animate_collect(game); 19 | draw_exit(game); 20 | draw_animate_player(game); 21 | if (game->offset % TILE_SIZE == 0) 22 | draw_init(game); 23 | } 24 | 25 | int loop_hook(t_game *game) 26 | { 27 | static unsigned int frame; 28 | 29 | if (!(++frame % 500)) 30 | { 31 | if (game->move_status != NONE) 32 | move_player(game); 33 | else 34 | draw_animate_collect(game); 35 | } 36 | return (1); 37 | } 38 | -------------------------------------------------------------------------------- /lib/mlx/mlx_opengl.m: -------------------------------------------------------------------------------- 1 | // mlx_opengl.m 2 | 3 | #import 4 | #import 5 | #import 6 | 7 | #include 8 | 9 | #include "mlx_int.h" 10 | #include "mlx_new_window.h" 11 | 12 | 13 | 14 | 15 | 16 | NSOpenGLPixelFormatAttribute pfa_attrs_opengl[] = 17 | { 18 | NSOpenGLPFADepthSize, 32, 19 | NSOpenGLPFADoubleBuffer, 20 | NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core, 21 | 0 22 | }; 23 | 24 | 25 | 26 | void *mlx_new_opengl_window(mlx_ptr_t *mlx_ptr, int size_x, int size_y, char *title) 27 | { 28 | mlx_win_list_t *newwin; 29 | NSString *str; 30 | 31 | if ((newwin = malloc(sizeof(*newwin))) == NULL) 32 | return ((void *)0); 33 | newwin->img_list = NULL; 34 | newwin->next = mlx_ptr->win_list; 35 | newwin->nb_flush = 0; 36 | newwin->pixmgt = 0; 37 | mlx_ptr->win_list = newwin; 38 | 39 | NSRect windowRect = NSMakeRect(100, 100, size_x, size_y); 40 | str = [NSString stringWithCString:title encoding:NSASCIIStringEncoding]; 41 | newwin->winid = [[MlxWin alloc] initWithRect:windowRect andTitle:str pfaAttrs:pfa_attrs_opengl]; 42 | 43 | return ((void *)newwin); 44 | } 45 | 46 | 47 | int mlx_opengl_swap_buffers(mlx_win_list_t *win_ptr) 48 | { 49 | [(id)(win_ptr->winid) flushGLContext]; 50 | return (0); 51 | } 52 | 53 | int mlx_opengl_window_set_context(mlx_win_list_t *win_ptr) 54 | { 55 | [(id)(win_ptr->winid) selectGLContext]; 56 | return (0); 57 | } 58 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 21:35:06 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:30:39 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_substr(char const *str, unsigned int start, size_t len) 16 | { 17 | char *res; 18 | size_t size; 19 | size_t i; 20 | 21 | if (!str) 22 | return (0); 23 | size = ft_strlen(str + start); 24 | if (size > len) 25 | size = len; 26 | res = (char *)malloc(sizeof(char) * size + 1); 27 | if (!res) 28 | return (0); 29 | i = 0; 30 | while (i < len && (start + i) < ft_strlen(str)) 31 | { 32 | res[i] = str[start + i]; 33 | i++; 34 | } 35 | res[i] = '\0'; 36 | return (res); 37 | } 38 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 21:35:06 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:30:39 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_substr(char const *str, unsigned int start, size_t len) 16 | { 17 | char *res; 18 | size_t size; 19 | size_t i; 20 | 21 | if (!str) 22 | return (0); 23 | size = ft_strlen(str + start); 24 | if (size > len) 25 | size = len; 26 | res = (char *)malloc(sizeof(char) * size + 1); 27 | if (!res) 28 | return (0); 29 | i = 0; 30 | while (i < len && (start + i) < ft_strlen(str)) 31 | { 32 | res[i] = str[start + i]; 33 | i++; 34 | } 35 | res[i] = '\0'; 36 | return (res); 37 | } 38 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/08 23:58:42 by nkim #+# #+# */ 9 | /* Updated: 2021/06/22 18:00:32 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t rdata; 18 | size_t dest_len; 19 | size_t src_len; 20 | size_t i; 21 | 22 | dest_len = ft_strlen(dst); 23 | src_len = ft_strlen(src); 24 | i = 0; 25 | if (dest_len >= dstsize) 26 | rdata = src_len + dstsize; 27 | else 28 | { 29 | while (i < dstsize - dest_len - 1 && src[i]) 30 | { 31 | dst[dest_len + i] = src[i]; 32 | i++; 33 | } 34 | dst[dest_len + i] = '\0'; 35 | rdata = src_len + dest_len; 36 | } 37 | return (rdata); 38 | } 39 | -------------------------------------------------------------------------------- /src_bonus/main_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/17 18:56:18 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 06:24:00 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "error_bonus.h" 14 | #include "game_bonus.h" 15 | #include "hook_bonus.h" 16 | #include "parse_bonus.h" 17 | #include "so_long_bonus.h" 18 | 19 | int main(int argc, char **argv) 20 | { 21 | t_game game; 22 | 23 | if (argc != 2) 24 | throw_error("ArgError : no / over argument!"); 25 | parse_map(&game, argv[1]); 26 | init_game(&game); 27 | mlx_hook(game.win_ptr, KEY_EXIT, 0, &close_game, &game); 28 | mlx_key_hook(game.win_ptr, &key_hook, &game); 29 | mlx_loop_hook(game.mlx_ptr, &loop_hook, &game); 30 | mlx_loop(game.mlx_ptr); 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/08 23:58:42 by nkim #+# #+# */ 9 | /* Updated: 2021/06/22 18:00:32 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t rdata; 18 | size_t dest_len; 19 | size_t src_len; 20 | size_t i; 21 | 22 | dest_len = ft_strlen(dst); 23 | src_len = ft_strlen(src); 24 | i = 0; 25 | if (dest_len >= dstsize) 26 | rdata = src_len + dstsize; 27 | else 28 | { 29 | while (i < dstsize - dest_len - 1 && src[i]) 30 | { 31 | dst[dest_len + i] = src[i]; 32 | i++; 33 | } 34 | dst[dest_len + i] = '\0'; 35 | rdata = src_len + dest_len; 36 | } 37 | return (rdata); 38 | } 39 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:36:25 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:55:53 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *haystack, const char *needle, size_t len) 16 | { 17 | size_t i; 18 | size_t j; 19 | char *res; 20 | 21 | i = 0; 22 | if (needle[0] == '\0') 23 | return ((char *)haystack); 24 | while (i < len && haystack[i]) 25 | { 26 | if (haystack[i] == needle[0]) 27 | { 28 | res = (char *)&haystack[i]; 29 | j = 1; 30 | while ((haystack[i + j] == needle[j]) && needle[j] && (i + j) < len) 31 | j++; 32 | if (needle[j] == '\0') 33 | return (res); 34 | } 35 | i++; 36 | } 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/05 18:36:25 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:55:53 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *haystack, const char *needle, size_t len) 16 | { 17 | size_t i; 18 | size_t j; 19 | char *res; 20 | 21 | i = 0; 22 | if (needle[0] == '\0') 23 | return ((char *)haystack); 24 | while (i < len && haystack[i]) 25 | { 26 | if (haystack[i] == needle[0]) 27 | { 28 | res = (char *)&haystack[i]; 29 | j = 1; 30 | while ((haystack[i + j] == needle[j]) && needle[j] && (i + j) < len) 31 | j++; 32 | if (needle[j] == '\0') 33 | return (res); 34 | } 35 | i++; 36 | } 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /lib/libft/include/ft_printf.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/13 15:26:48 by nkim #+# #+# */ 9 | /* Updated: 2022/01/18 15:25:18 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_PRINTF_H 14 | # define FT_PRINTF_H 15 | 16 | # include "libft.h" 17 | # include 18 | # include 19 | # include 20 | 21 | int ft_putnbr(int n); 22 | int ft_putunnbr(unsigned int nbr); 23 | int ft_putunnbr_hex(unsigned long long nbr, char *base); 24 | int print_c(int arg); 25 | int print_s(char *arg); 26 | int print_decimal(int arg); 27 | int print_un_decimal(unsigned int arg); 28 | int print_pointer(unsigned long long arg); 29 | int print_un_hex(unsigned int arg, char type); 30 | int ft_printf(const char *string, ...); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/utils/ft_make_xpm_img.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_make_xpm_img.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/23 19:04:18 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:49:00 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void *ft_make_xpm_img(t_game *game, char *xpmFile) 16 | { 17 | char *path; 18 | void *img; 19 | int width; 20 | int height; 21 | 22 | path = ft_strjoin(ASSET_PATH, xpmFile); 23 | img = mlx_xpm_file_to_image(game->mlx_ptr, path, &width, &height); 24 | free(path); 25 | if (!img) 26 | { 27 | printf("fileName: %s\n", xpmFile); 28 | throw_error("XPM Error : check ASSET_PATH or fileName"); 29 | } 30 | else if (!(width == TILE_SIZE && height == TILE_SIZE)) 31 | throw_error("TILE SIZE Error : incorrect tile size"); 32 | return (img); 33 | } 34 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/ft_printf.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/13 15:26:48 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:38:44 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_PRINTF_H 14 | # define FT_PRINTF_H 15 | 16 | # include "libft/libft.h" 17 | # include 18 | # include 19 | # include 20 | 21 | int ft_putnbr(int n); 22 | int ft_putunnbr(unsigned int nbr); 23 | int ft_putunnbr_hex(unsigned long long nbr, char *base); 24 | int print_c(int arg); 25 | int print_s(char *arg); 26 | int print_decimal(int arg); 27 | int print_un_decimal(unsigned int arg); 28 | int print_pointer(unsigned long long arg); 29 | int print_un_hex(unsigned int arg, char type); 30 | int ft_printf(const char *string, ...); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include_bonus/hook_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* hook_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:49:59 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 18:46:16 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HOOK_BONUS_H 14 | # define HOOK_BONUS_H 15 | 16 | # include "so_long_bonus.h" 17 | 18 | # define KEY_EXIT 17 19 | # define KEY_W 13 20 | # define KEY_S 1 21 | # define KEY_D 2 22 | # define KEY_A 0 23 | # define KEY_RIGHT 123 24 | # define KEY_LEFT 124 25 | # define KEY_DOWN 125 26 | # define KEY_UP 126 27 | # define KEY_ESC 53 28 | # define KEY_SPACE 49 29 | # define KEY_ENTER 36 30 | # define KEY_B 11 31 | # define KEY_R 15 32 | 33 | int loop_hook(t_game *game); 34 | int key_hook(int keycode, t_game *game); 35 | void handle_location(t_game *game, int offsetX, int offsetY); 36 | void handle_moving(int keycode, t_game *game); 37 | void handle_player(t_game *game); 38 | 39 | #endif -------------------------------------------------------------------------------- /lib/libft/include/get_next_line.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/05 17:21:50 by nkim #+# #+# */ 9 | /* Updated: 2021/07/27 18:29:23 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_H 14 | # define GET_NEXT_LINE_H 15 | 16 | # ifndef BUFFER_SIZE 17 | # define BUFFER_SIZE 1 18 | # endif 19 | 20 | # include 21 | # include 22 | 23 | typedef struct s_gnl_manager 24 | { 25 | char **file_rest; 26 | char *line; 27 | int max_fd; 28 | } t_gnl_manager; 29 | 30 | size_t ft_strlen(const char *s); 31 | void *ft_memset(void *dst, int value, size_t n); 32 | char *ft_strchr(const char *src, int c); 33 | void *ft_memmove(void *dst, const void *src, size_t n); 34 | char *ft_strjoin(char const *s1, char const *s2); 35 | char *ft_strndup(const char *s1, size_t n); 36 | char *get_next_line(int fd); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/libft/get-next-line/get_next_line.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/05 17:21:50 by nkim #+# #+# */ 9 | /* Updated: 2021/07/27 18:29:23 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_H 14 | # define GET_NEXT_LINE_H 15 | 16 | # ifndef BUFFER_SIZE 17 | # define BUFFER_SIZE 1 18 | # endif 19 | 20 | # include 21 | # include 22 | 23 | typedef struct s_gnl_manager 24 | { 25 | char **file_rest; 26 | char *line; 27 | int max_fd; 28 | } t_gnl_manager; 29 | 30 | size_t ft_strlen(const char *s); 31 | void *ft_memset(void *dst, int value, size_t n); 32 | char *ft_strchr(const char *src, int c); 33 | void *ft_memmove(void *dst, const void *src, size_t n); 34 | char *ft_strjoin(char const *s1, char const *s2); 35 | char *ft_strndup(const char *s1, size_t n); 36 | char *get_next_line(int fd); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 16:43:00 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:19:38 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *lstclear(t_list **res, void (*del)(void *)) 16 | { 17 | ft_lstclear(res, del); 18 | return (0); 19 | } 20 | 21 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 22 | { 23 | t_list *res; 24 | t_list *tmp; 25 | 26 | if (lst) 27 | { 28 | res = (t_list *)malloc(sizeof(t_list)); 29 | if (!(res)) 30 | return (0); 31 | res->content = (*f)(lst->content); 32 | tmp = res; 33 | } 34 | else 35 | return (0); 36 | while (lst) 37 | { 38 | tmp->next = (t_list *)malloc(sizeof(t_list)); 39 | if (!tmp) 40 | return (lstclear(&res, del)); 41 | tmp = tmp->next; 42 | tmp->content = (*f)(lst->content); 43 | lst = lst->next; 44 | } 45 | tmp->next = NULL; 46 | return (res); 47 | } 48 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/11 16:43:00 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:19:38 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *lstclear(t_list **res, void (*del)(void *)) 16 | { 17 | ft_lstclear(res, del); 18 | return (0); 19 | } 20 | 21 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 22 | { 23 | t_list *res; 24 | t_list *tmp; 25 | 26 | if (lst) 27 | { 28 | res = (t_list *)malloc(sizeof(t_list)); 29 | if (!(res)) 30 | return (0); 31 | res->content = (*f)(lst->content); 32 | tmp = res; 33 | } 34 | else 35 | return (0); 36 | while (lst) 37 | { 38 | tmp->next = (t_list *)malloc(sizeof(t_list)); 39 | if (!tmp) 40 | return (lstclear(&res, del)); 41 | tmp = tmp->next; 42 | tmp->content = (*f)(lst->content); 43 | lst = lst->next; 44 | } 45 | tmp->next = NULL; 46 | return (res); 47 | } 48 | -------------------------------------------------------------------------------- /include_bonus/draw_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:49:59 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 06:30:20 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DRAW_BONUS_H 14 | # define DRAW_BONUS_H 15 | 16 | # include "so_long_bonus.h" 17 | 18 | void draw_tiles(t_game *game); 19 | void draw_step(t_game *game); 20 | void draw_sprites(t_game *game); 21 | void draw_exit(t_game *game); 22 | void draw_enemies(t_game *game); 23 | void draw_init(t_game *game); 24 | 25 | void draw_animate_player(t_game *game); 26 | void draw_animate_collect(t_game *game); 27 | void draw_animate_enemy(t_game *game); 28 | 29 | void draw_partial(t_game *game, 30 | void (*partial_func)(t_game *, int, int)); 31 | void draw_partial_tiles(t_game *game, int row, int col); 32 | 33 | void draw_screen(t_game *game); 34 | void draw_start_screen(t_game *game); 35 | void draw_fail_screen(t_game *game); 36 | void draw_success_screen(t_game *game); 37 | 38 | #endif -------------------------------------------------------------------------------- /lib/libft/ft_printf/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: nkim +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/05/03 22:59:15 by nkim #+# #+# # 9 | # Updated: 2021/09/25 11:40:00 by nkim ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libftprintf.a 14 | SRC_DIR = . 15 | LIBFT = libft.a 16 | LIBFT_DIR = ./libft 17 | LIBFT_LIB = $(LIBFT_DIR)/$(LIBFT) 18 | INCS = . 19 | 20 | AFLAGS = rus 21 | 22 | CC = cc 23 | CFLAGS = -Wall -Wextra -Werror 24 | 25 | SRCS = ft_printf.c print_number.c print_string.c utils.c 26 | OBJS = $(SRCS:.c=.o) 27 | 28 | all : $(NAME) 29 | 30 | clean : 31 | @rm -rf $(OBJS) 32 | @make clean -C $(LIBFT_DIR) 33 | 34 | fclean : clean 35 | @rm -rf $(NAME) 36 | @make fclean -C $(LIBFT_DIR) 37 | 38 | re : fclean all 39 | 40 | $(NAME) : $(OBJS) $(LIBFT) 41 | @cp $(LIBFT_LIB) $@ 42 | @ar $(AFLAGS) $@ $(OBJS) 43 | 44 | # Libft 45 | $(LIBFT) : $(LIBFT_LIB) 46 | 47 | $(LIBFT_LIB) : 48 | @make -C $(LIBFT_DIR) 49 | 50 | %.o : %.c 51 | @$(CC) $(CFLAGS) -c $? 52 | 53 | test : $(NAME) 54 | @$(CC) main.c -L $(SRC_DIR) -l ftprintf 55 | 56 | .PHONY : all clean fclean re 57 | -------------------------------------------------------------------------------- /src/utils/ft_make_iterable_sprites.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_make_iterable_sprites.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/26 15:49:45 by nkim #+# #+# */ 9 | /* Updated: 2022/07/08 01:02:21 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void ft_make_iterable_sprites(t_game *game, 16 | t_sprites **sprites, 17 | char *imgName, 18 | int cnt) 19 | { 20 | t_sprites *tmp; 21 | char *file_name; 22 | char *xpm_file; 23 | int num; 24 | int idx; 25 | 26 | *sprites = (t_sprites *)malloc(sizeof(t_sprites)); 27 | tmp = *sprites; 28 | idx = 0; 29 | while (idx < cnt) 30 | { 31 | num = '0' + idx; 32 | file_name = ft_strjoin(imgName, (char *)&num); 33 | xpm_file = ft_strjoin(file_name, ".xpm"); 34 | tmp->img = ft_make_xpm_img(game, xpm_file); 35 | free(file_name); 36 | free(xpm_file); 37 | if (idx != cnt - 1) 38 | { 39 | tmp->next = (t_sprites *)malloc(sizeof(t_sprites)); 40 | tmp = tmp->next; 41 | } 42 | idx++; 43 | } 44 | tmp->next = *sprites; 45 | } 46 | -------------------------------------------------------------------------------- /src_bonus/utils_bonus/ft_make_iterable_sprites_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_make_iterable_sprites_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/26 15:49:45 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:05:09 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "utils_bonus.h" 14 | 15 | void ft_make_iterable_sprites(t_game *game, 16 | t_sprites **sprites, 17 | char *imgName, 18 | int cnt) 19 | { 20 | t_sprites *tmp; 21 | char *file_name; 22 | char *xpm_file; 23 | int num; 24 | int idx; 25 | 26 | *sprites = (t_sprites *)malloc(sizeof(t_sprites)); 27 | tmp = *sprites; 28 | idx = 0; 29 | while (idx < cnt) 30 | { 31 | num = '0' + idx; 32 | file_name = ft_strjoin(imgName, (char *)&num); 33 | xpm_file = ft_strjoin(file_name, ".xpm"); 34 | tmp->img = ft_make_xpm_img(game, xpm_file); 35 | free(file_name); 36 | free(xpm_file); 37 | if (idx != cnt - 1) 38 | { 39 | tmp->next = (t_sprites *)malloc(sizeof(t_sprites)); 40 | tmp = tmp->next; 41 | } 42 | idx++; 43 | } 44 | tmp->next = *sprites; 45 | } 46 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/print_number.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* print_number.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/09/18 16:39:33 by nkim #+# #+# */ 9 | /* Updated: 2022/07/11 16:28:52 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_printf.h" 14 | 15 | int print_decimal(int arg) 16 | { 17 | int cnt; 18 | 19 | cnt = ft_putnbr(arg); 20 | return (cnt); 21 | } 22 | 23 | int print_un_decimal(unsigned int arg) 24 | { 25 | int cnt; 26 | int un; 27 | 28 | un = arg; 29 | cnt = ft_putunnbr(un); 30 | return (cnt); 31 | } 32 | 33 | int print_un_hex(unsigned int arg, char type) 34 | { 35 | int cnt; 36 | signed int un; 37 | char *base; 38 | 39 | un = arg; 40 | if (type == 'X') 41 | base = "0123456789ABCDEF"; 42 | else 43 | base = "0123456789abcdef"; 44 | cnt = ft_putunnbr_hex(un, base); 45 | return (cnt); 46 | } 47 | 48 | int print_pointer(unsigned long long arg) 49 | { 50 | int cnt; 51 | char *base; 52 | 53 | base = "0123456789abcdef"; 54 | write(1, "0x", 2); 55 | cnt = ft_putunnbr_hex(arg, base); 56 | return (cnt + 2); 57 | } 58 | -------------------------------------------------------------------------------- /include_bonus/utils_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* utils_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 03:49:59 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 06:19:24 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef UTILS_BONUS_H 14 | # define UTILS_BONUS_H 15 | 16 | # include "../lib/libft/include/libft42.h" 17 | # include "../lib/mlx/mlx.h" 18 | # include "error_bonus.h" 19 | # include "so_long_bonus.h" 20 | # include 21 | 22 | # define ASSET_PATH "./assets/" 23 | 24 | void ft_put_img(t_game *game, void *img, int x, int y); 25 | void *ft_ptr_realloc(void *buf, int before_size, int after_size); 26 | void *ft_make_xpm_img(t_game *game, char *fileName); 27 | void *ft_make_xpm_screen(t_game *game, char *xpmFile); 28 | void ft_make_iterable_sprites(t_game *game, 29 | t_sprites **sprites, 30 | char *imgName, 31 | int cnt); 32 | char *ft_get_line(int fd); 33 | 34 | void ft_lstc_add_back(t_component **lst, t_component *new); 35 | int ft_lstc_size(t_component *lst); 36 | int ft_lstc_add(t_component **lst, int x, int y); 37 | void ft_lstc_delete(t_component **lst, int x, int y); 38 | 39 | #endif -------------------------------------------------------------------------------- /lib/mlx/mlx_new_window.h: -------------------------------------------------------------------------------- 1 | // 2 | // mlx_int.h for minilibx 3 | // 4 | // ol@staff.42.fr 5 | // 6 | // include opengl needed before mlx_int.h 7 | // 8 | 9 | #import 10 | #import "mlx_int.h" 11 | 12 | @interface NSWindowEvent : NSWindow 13 | { 14 | func_t event_funct[MAX_EVENT]; 15 | void *(event_param[MAX_EVENT]); 16 | int keyrepeat; 17 | int keyflag; 18 | int size_x; 19 | int size_y; 20 | } 21 | - (NSWindowEvent *) initWithContentRect:(NSRect)rect styleMask:(NSUInteger)winstyle backing:(NSBackingStoreType)bck defer:(BOOL) dfr; 22 | - (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param; 23 | - (void) setKeyRepeat:(int)mode; 24 | - (void) exposeNotification:(NSNotification *)note; 25 | - (void) closeNotification:(NSNotification *)note; 26 | @end 27 | 28 | 29 | @interface MlxWin : NSOpenGLView 30 | { 31 | NSWindowEvent *win; 32 | NSOpenGLContext *ctx; 33 | glsl_info_t glsl; 34 | int openglwin; 35 | 36 | int size_x; 37 | int size_y; 38 | 39 | int pixel_nb; 40 | GLuint pixel_vbuffer; 41 | GLuint pixel_texture; 42 | unsigned int *pixtexbuff; 43 | } 44 | 45 | - (id) initWithRect: (NSRect)rect andTitle: (NSString *)title pfaAttrs: (NSOpenGLPixelFormatAttribute *)attrs; 46 | - (void) selectGLContext; 47 | - (void) flushGLContext; 48 | - (void) pixelPutColor: (int)color X:(int)x Y:(int)y; 49 | - (void) mlx_gl_draw; 50 | - (void) mlx_gl_draw_img:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y; 51 | - (void) mlx_gl_draw_font:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y andColor:(int)color glyphX:(int)gx glyphY:(int)gy; 52 | - (NSOpenGLContext *) ctx; 53 | - (NSWindowEvent *) win; 54 | - (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param; 55 | - (void) setKeyRepeat:(int)mode; 56 | - (void) ctxNeedsUpdate; 57 | @end 58 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 18:20:43 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:36:31 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t get_int_len(size_t n) 16 | { 17 | size_t len; 18 | 19 | len = 0; 20 | while (n) 21 | { 22 | n /= 10; 23 | len++; 24 | } 25 | return (len); 26 | } 27 | 28 | void put_itoa(char *res, int len, size_t n) 29 | { 30 | if (n < 10) 31 | res[len] = n + '0'; 32 | else 33 | { 34 | put_itoa(res, len - 1, n / 10); 35 | res[len] = (n % 10) + '0'; 36 | } 37 | } 38 | 39 | char *ft_itoa(int n) 40 | { 41 | char *res; 42 | size_t len; 43 | size_t num; 44 | int is_minus; 45 | 46 | is_minus = 0; 47 | if (n <= 0) 48 | { 49 | num = -1 * (size_t)n; 50 | is_minus = 1; 51 | } 52 | else 53 | num = n; 54 | len = get_int_len(num); 55 | res = (char *)malloc(sizeof(char) * (len + is_minus + 1)); 56 | if (!res) 57 | return (0); 58 | if (is_minus) 59 | res[0] = '-'; 60 | put_itoa(res + is_minus, len - 1, num); 61 | res[len + is_minus] = '\0'; 62 | return (res); 63 | } 64 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 18:20:43 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:36:31 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t get_int_len(size_t n) 16 | { 17 | size_t len; 18 | 19 | len = 0; 20 | while (n) 21 | { 22 | n /= 10; 23 | len++; 24 | } 25 | return (len); 26 | } 27 | 28 | void put_itoa(char *res, int len, size_t n) 29 | { 30 | if (n < 10) 31 | res[len] = n + '0'; 32 | else 33 | { 34 | put_itoa(res, len - 1, n / 10); 35 | res[len] = (n % 10) + '0'; 36 | } 37 | } 38 | 39 | char *ft_itoa(int n) 40 | { 41 | char *res; 42 | size_t len; 43 | size_t num; 44 | int is_minus; 45 | 46 | is_minus = 0; 47 | if (n <= 0) 48 | { 49 | num = -1 * (size_t)n; 50 | is_minus = 1; 51 | } 52 | else 53 | num = n; 54 | len = get_int_len(num); 55 | res = (char *)malloc(sizeof(char) * (len + is_minus + 1)); 56 | if (!res) 57 | return (0); 58 | if (is_minus) 59 | res[0] = '-'; 60 | put_itoa(res + is_minus, len - 1, num); 61 | res[len + is_minus] = '\0'; 62 | return (res); 63 | } 64 | -------------------------------------------------------------------------------- /src_bonus/game_bonus/restart_game_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* restart_game_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 06:00:04 by nkim #+# #+# */ 9 | /* Updated: 2022/07/15 19:44:11 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "game_bonus.h" 14 | #include "draw_bonus.h" 15 | #include 16 | #include 17 | 18 | void free_enemies(t_component *enemies) 19 | { 20 | t_component *tmp; 21 | 22 | while (enemies) 23 | { 24 | tmp = enemies; 25 | enemies = enemies->next; 26 | free(tmp); 27 | } 28 | } 29 | 30 | void free_collections(t_component *collections) 31 | { 32 | t_component *tmp; 33 | 34 | while (collections) 35 | { 36 | tmp = collections; 37 | collections = collections->next; 38 | free(tmp); 39 | } 40 | } 41 | 42 | void free_game(t_game *game) 43 | { 44 | free_collections(game->collect.collections); 45 | free_enemies(game->enemy.enemies); 46 | } 47 | 48 | void restart_game(t_game *game) 49 | { 50 | free_game(game); 51 | init_props(game); 52 | draw_tiles(game); 53 | draw_step(game); 54 | draw_sprites(game); 55 | draw_enemies(game); 56 | draw_exit(game); 57 | printf("\033[1;33m== Restart Game ==\033[0m\n"); 58 | game->status = PLAYING; 59 | game->step = 0; 60 | } 61 | -------------------------------------------------------------------------------- /lib/libft/libft/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: nkim +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/05/03 22:59:15 by nkim #+# #+# # 9 | # Updated: 2022/07/07 20:59:50 by nkim ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libft.a 14 | CC = cc 15 | AFLAGS = rcs 16 | CFLAGS = -Wall -Wextra -Werror 17 | SRCS = *.c 18 | SRC = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c\ 19 | ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c\ 20 | ft_strlcpy.c ft_strlcat.c ft_strchr.c ft_strrchr.c\ 21 | ft_strnstr.c ft_strncmp.c ft_atoi.c ft_isalpha.c\ 22 | ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c\ 23 | ft_toupper.c ft_tolower.c ft_calloc.c ft_strdup.c\ 24 | ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c\ 25 | ft_itoa.c ft_strmapi.c ft_putchar_fd.c ft_putstr_fd.c\ 26 | ft_putendl_fd.c ft_putnbr_fd.c\ 27 | ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c\ 28 | ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c\ 29 | ft_lstmap.c 30 | OBJ = $(SRC:.c=.o) 31 | 32 | all : $(NAME) 33 | 34 | clean : 35 | @rm -rf $(OBJ) 36 | 37 | fclean : clean 38 | @rm -rf $(NAME) 39 | 40 | re : fclean all 41 | 42 | $(NAME) : $(OBJ) 43 | @ar $(AFLAGS) $@ $? 44 | 45 | %.o : %.c 46 | @$(CC) $(CFLAGS) -c $? 47 | 48 | .PHONY : all clean fclean re -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: nkim +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/05/03 22:59:15 by nkim #+# #+# # 9 | # Updated: 2021/09/24 20:33:55 by nkim ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libft.a 14 | CC = gcc 15 | AFLAGS = rcs 16 | CFLAGS = -Wall -Wextra -Werror 17 | SRCS = *.c 18 | SRC = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c\ 19 | ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c\ 20 | ft_strlcpy.c ft_strlcat.c ft_strchr.c ft_strrchr.c\ 21 | ft_strnstr.c ft_strncmp.c ft_atoi.c ft_isalpha.c\ 22 | ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c\ 23 | ft_toupper.c ft_tolower.c ft_calloc.c ft_strdup.c\ 24 | ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c\ 25 | ft_itoa.c ft_strmapi.c ft_putchar_fd.c ft_putstr_fd.c\ 26 | ft_putendl_fd.c ft_putnbr_fd.c\ 27 | ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c\ 28 | ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c\ 29 | ft_lstmap.c 30 | OBJ = $(SRC:.c=.o) 31 | 32 | all : $(NAME) 33 | 34 | clean : 35 | rm -rf $(OBJ) 36 | 37 | fclean : clean 38 | rm -rf $(NAME) 39 | 40 | re : fclean all 41 | 42 | $(NAME) : $(OBJ) 43 | ar $(AFLAGS) $@ $? 44 | 45 | %.o : %.c 46 | $(CC) $(CFLAGS) -c $? 47 | 48 | .PHONY : all clean fclean re -------------------------------------------------------------------------------- /lib/libft/libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 15:36:34 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:37:06 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int is_isspace(char c) 16 | { 17 | if (c == ' ' || c == '\n' || c == '\t' 18 | ||c == '\v' || c == '\f' || c == '\r') 19 | return (1); 20 | else 21 | return (0); 22 | } 23 | 24 | int ctoi(char c) 25 | { 26 | int res; 27 | 28 | res = c - '0'; 29 | return (res); 30 | } 31 | 32 | int detect_flow(int is_minus) 33 | { 34 | if (is_minus == -1) 35 | return (0); 36 | else 37 | return (-1); 38 | } 39 | 40 | int ft_atoi(const char *str) 41 | { 42 | long long res; 43 | long long tmp; 44 | int is_minus; 45 | int i; 46 | 47 | i = 0; 48 | is_minus = 1; 49 | while (is_isspace(str[i])) 50 | i++; 51 | if (str[i] == '-' || str[i] == '+') 52 | { 53 | if (str[i++] == '-') 54 | is_minus = -1; 55 | } 56 | if (!ft_isdigit(str[i])) 57 | return (0); 58 | res = 0; 59 | while (ft_isdigit(str[i])) 60 | { 61 | tmp = res * 10 + ctoi(str[i++]); 62 | if (tmp < res || (tmp == 0x7FFFFFFFFFFFFFFF && is_minus == 1)) 63 | return (detect_flow(is_minus)); 64 | res = tmp; 65 | } 66 | return ((int)(is_minus * res)); 67 | } 68 | -------------------------------------------------------------------------------- /src_bonus/draw_bonus/draw_screen_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_screen_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 05:52:53 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 07:54:13 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "draw_bonus.h" 14 | #include "utils_bonus.h" 15 | 16 | void draw_start_screen(t_game *game) 17 | { 18 | int x; 19 | int y; 20 | 21 | x = ((game->map.cols / 2.0) - 3) * TILE_SIZE; 22 | y = ((game->map.rows / 2.0) - 2.5) * TILE_SIZE; 23 | ft_put_img(game, game->screen.start, x, y); 24 | } 25 | 26 | void draw_fail_screen(t_game *game) 27 | { 28 | int x; 29 | int y; 30 | 31 | x = ((game->map.cols / 2.0) - 3) * TILE_SIZE; 32 | y = ((game->map.rows / 2.0) - 2.5) * TILE_SIZE; 33 | ft_put_img(game, game->screen.fail, x, y); 34 | } 35 | 36 | void draw_success_screen(t_game *game) 37 | { 38 | int x; 39 | int y; 40 | 41 | x = ((game->map.cols / 2.0) - 3) * TILE_SIZE; 42 | y = ((game->map.rows / 2.0) - 2.5) * TILE_SIZE; 43 | ft_put_img(game, game->screen.success, x, y); 44 | } 45 | 46 | void draw_screen(t_game *game) 47 | { 48 | if (game->status == NOTSTARTED) 49 | draw_start_screen(game); 50 | else if (game->status == FAIL) 51 | draw_fail_screen(game); 52 | else if (game->status == SUCCESS) 53 | draw_success_screen(game); 54 | } 55 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/10 15:36:34 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:37:06 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int is_isspace(char c) 16 | { 17 | if (c == ' ' || c == '\n' || c == '\t' 18 | ||c == '\v' || c == '\f' || c == '\r') 19 | return (1); 20 | else 21 | return (0); 22 | } 23 | 24 | int ctoi(char c) 25 | { 26 | int res; 27 | 28 | res = c - '0'; 29 | return (res); 30 | } 31 | 32 | int detect_flow(int is_minus) 33 | { 34 | if (is_minus == -1) 35 | return (0); 36 | else 37 | return (-1); 38 | } 39 | 40 | int ft_atoi(const char *str) 41 | { 42 | long long res; 43 | long long tmp; 44 | int is_minus; 45 | int i; 46 | 47 | i = 0; 48 | is_minus = 1; 49 | while (is_isspace(str[i])) 50 | i++; 51 | if (str[i] == '-' || str[i] == '+') 52 | { 53 | if (str[i++] == '-') 54 | is_minus = -1; 55 | } 56 | if (!ft_isdigit(str[i])) 57 | return (0); 58 | res = 0; 59 | while (ft_isdigit(str[i])) 60 | { 61 | tmp = res * 10 + ctoi(str[i++]); 62 | if (tmp < res || (tmp == 0x7FFFFFFFFFFFFFFF && is_minus == 1)) 63 | return (detect_flow(is_minus)); 64 | res = tmp; 65 | } 66 | return ((int)(is_minus * res)); 67 | } 68 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/09/20 19:40:28 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:50:58 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_printf.h" 14 | 15 | int ft_putnbr(int n) 16 | { 17 | int cnt; 18 | char tmp; 19 | unsigned int nbr; 20 | 21 | nbr = n; 22 | cnt = 0; 23 | if (n < 0) 24 | { 25 | write(1, "-", 1); 26 | nbr = n * -1; 27 | } 28 | if (nbr < 10) 29 | tmp = '0' + nbr; 30 | else 31 | { 32 | cnt = ft_putnbr(nbr / 10); 33 | tmp = '0' + (nbr % 10); 34 | } 35 | write(1, &tmp, 1); 36 | cnt++; 37 | if (n < 0) 38 | cnt++; 39 | return (cnt); 40 | } 41 | 42 | int ft_putunnbr(unsigned int nbr) 43 | { 44 | int cnt; 45 | char tmp; 46 | 47 | cnt = 0; 48 | if (nbr < 10) 49 | tmp = '0' + nbr; 50 | else 51 | { 52 | cnt = ft_putunnbr(nbr / 10); 53 | tmp = '0' + (nbr % 10); 54 | } 55 | write(1, &tmp, 1); 56 | cnt++; 57 | return (cnt); 58 | } 59 | 60 | int ft_putunnbr_hex(unsigned long long nbr, char *base) 61 | { 62 | int cnt; 63 | char tmp; 64 | 65 | cnt = 0; 66 | if (nbr < 0x10) 67 | tmp = base[nbr]; 68 | else 69 | { 70 | cnt = ft_putunnbr_hex(nbr / 0x10, base); 71 | tmp = base[nbr % 0x10]; 72 | } 73 | write(1, &tmp, 1); 74 | cnt++; 75 | return (cnt); 76 | } 77 | -------------------------------------------------------------------------------- /src/hook/key_hook.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key_hook.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 18:07:36 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:42:50 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void move_key_hook(int keycode, t_game *game) 16 | { 17 | if (keycode == KEY_D) 18 | { 19 | game->move_status = RIGHT; 20 | game->offset = game->player.x; 21 | game->player.sprites = game->player.r_sprites; 22 | game->player.initial = game->player.r_inital; 23 | } 24 | else if (keycode == KEY_A) 25 | { 26 | game->move_status = LEFT; 27 | game->offset = game->player.x; 28 | game->player.sprites = game->player.l_sprites; 29 | game->player.initial = game->player.l_inital; 30 | } 31 | else if (keycode == KEY_W) 32 | { 33 | game->move_status = TOP; 34 | game->offset = game->player.y; 35 | } 36 | else if (keycode == KEY_S) 37 | { 38 | game->move_status = BOTTOM; 39 | game->offset = game->player.y; 40 | } 41 | printf("STEP : %d\n", ++(game->step)); 42 | } 43 | 44 | int key_hook(int keycode, t_game *game) 45 | { 46 | if (game->move_status == NONE 47 | && (keycode == KEY_A || keycode == KEY_D 48 | || keycode == KEY_S || keycode == KEY_W)) 49 | move_key_hook(keycode, game); 50 | if (keycode == KEY_ESC) 51 | close_game(game); 52 | return (1); 53 | } 54 | -------------------------------------------------------------------------------- /src/draw/draw_animate.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_animate.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 17:50:07 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:29:23 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void draw_animate_player(t_game *game) 16 | { 17 | int step; 18 | 19 | step = 4; 20 | if (game->move_status == RIGHT) 21 | handle_location(game, step, 0); 22 | else if (game->move_status == LEFT) 23 | handle_location(game, -step, 0); 24 | else if (game->move_status == TOP) 25 | handle_location(game, 0, -step); 26 | else if (game->move_status == BOTTOM) 27 | handle_location(game, 0, step); 28 | game->offset += step; 29 | if (game->offset > MAX_OFFSET) 30 | game->offset = 0; 31 | ft_put_img(game, game->player.sprites->img, 32 | game->player.x, game->player.y); 33 | game->player.sprites = game->player.sprites->next; 34 | } 35 | 36 | void draw_animate_collect(t_game *game) 37 | { 38 | t_component *collections; 39 | 40 | collections = game->collect.collections; 41 | while (collections) 42 | { 43 | ft_put_img(game, game->tiles.ground, 44 | collections->x, collections->y); 45 | ft_put_img(game, game->collect.sprites->img, 46 | collections->x, collections->y); 47 | collections = collections->next; 48 | } 49 | game->collect.sprites = game->collect.sprites->next; 50 | } 51 | -------------------------------------------------------------------------------- /src_bonus/utils_bonus/ft_make_xpm_img_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_make_xpm_img_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/23 19:04:18 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 06:19:12 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "utils_bonus.h" 14 | #include 15 | 16 | void *ft_make_xpm_img(t_game *game, char *xpmFile) 17 | { 18 | char *path; 19 | void *img; 20 | int width; 21 | int height; 22 | 23 | path = ft_strjoin(ASSET_PATH, xpmFile); 24 | img = mlx_xpm_file_to_image(game->mlx_ptr, path, &width, &height); 25 | free(path); 26 | if (!img) 27 | { 28 | printf("fileName: %s\n", xpmFile); 29 | throw_error("XPM Error : check ASSET_PATH or fileName"); 30 | } 31 | else if (!(width == TILE_SIZE && height == TILE_SIZE)) 32 | throw_error("TILE SIZE Error : incorrect tile size"); 33 | return (img); 34 | } 35 | 36 | void *ft_make_xpm_screen(t_game *game, char *xpmFile) 37 | { 38 | char *path; 39 | void *img; 40 | int width; 41 | int height; 42 | 43 | path = ft_strjoin(ASSET_PATH, xpmFile); 44 | img = mlx_xpm_file_to_image(game->mlx_ptr, path, &width, &height); 45 | free(path); 46 | if (!img) 47 | { 48 | printf("fileName: %s\n", xpmFile); 49 | throw_error("XPM Error : check ASSET_PATH or fileName"); 50 | } 51 | else if (!(width == SCREEN_WIDTH && height == SCREEN_HEIGHT)) 52 | throw_error("TILE SIZE Error : incorrect tile size"); 53 | return (img); 54 | } 55 | -------------------------------------------------------------------------------- /src/utils/ft_lst_component.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lst_component.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/26 16:19:18 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:54:04 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | t_component *ft_lstc_last(t_component *component) 16 | { 17 | if (!component) 18 | return (0); 19 | while (component->next) 20 | component = component->next; 21 | return (component); 22 | } 23 | 24 | void ft_lstc_add_back(t_component **lst, t_component *new) 25 | { 26 | if (!*lst) 27 | { 28 | *lst = new; 29 | return ; 30 | } 31 | ft_lstc_last(*lst)->next = new; 32 | } 33 | 34 | void ft_lstc_delete(t_component **lst, int x, int y) 35 | { 36 | t_component *tmp; 37 | t_component *target; 38 | 39 | tmp = *lst; 40 | if (tmp && tmp->x == x && tmp->y == y) 41 | { 42 | *lst = tmp->next; 43 | free(tmp); 44 | tmp = NULL; 45 | return ; 46 | } 47 | while (tmp && tmp->next) 48 | { 49 | if (tmp->next->x == x && tmp->next->y == y) 50 | { 51 | target = tmp->next; 52 | tmp->next = tmp->next->next; 53 | free(target); 54 | target = NULL; 55 | } 56 | tmp = tmp->next; 57 | } 58 | } 59 | 60 | int ft_lstc_add(t_component **lst, int x, int y) 61 | { 62 | t_component *new; 63 | 64 | new = (t_component *)malloc(sizeof(t_component)); 65 | if (!new) 66 | return (0); 67 | new->x = x; 68 | new->y = y; 69 | new->next = NULL; 70 | ft_lstc_add_back(lst, new); 71 | return (1); 72 | } 73 | -------------------------------------------------------------------------------- /src_bonus/utils_bonus/ft_lst_component_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lst_component_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/26 16:19:18 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:05:04 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "utils_bonus.h" 14 | 15 | t_component *ft_lstc_last(t_component *component) 16 | { 17 | if (!component) 18 | return (0); 19 | while (component->next) 20 | component = component->next; 21 | return (component); 22 | } 23 | 24 | void ft_lstc_add_back(t_component **lst, t_component *new) 25 | { 26 | if (!*lst) 27 | { 28 | *lst = new; 29 | return ; 30 | } 31 | ft_lstc_last(*lst)->next = new; 32 | } 33 | 34 | void ft_lstc_delete(t_component **lst, int x, int y) 35 | { 36 | t_component *tmp; 37 | t_component *target; 38 | 39 | tmp = *lst; 40 | if (tmp && tmp->x == x && tmp->y == y) 41 | { 42 | *lst = tmp->next; 43 | free(tmp); 44 | tmp = NULL; 45 | return ; 46 | } 47 | while (tmp && tmp->next) 48 | { 49 | if (tmp->next->x == x && tmp->next->y == y) 50 | { 51 | target = tmp->next; 52 | tmp->next = tmp->next->next; 53 | free(target); 54 | target = NULL; 55 | } 56 | tmp = tmp->next; 57 | } 58 | } 59 | 60 | int ft_lstc_add(t_component **lst, int x, int y) 61 | { 62 | t_component *new; 63 | 64 | new = (t_component *)malloc(sizeof(t_component)); 65 | if (!new) 66 | return (0); 67 | new->x = x; 68 | new->y = y; 69 | new->next = NULL; 70 | ft_lstc_add_back(lst, new); 71 | return (1); 72 | } 73 | -------------------------------------------------------------------------------- /lib/mlx/mlx_int_str_to_wordtab.c: -------------------------------------------------------------------------------- 1 | // 2 | // str 2 wordtab & co 3 | // by ol 4 | 5 | 6 | #include 7 | #include 8 | 9 | int mlx_int_str_str(char *str,char *find,int len) 10 | { 11 | int len_f; 12 | int pos; 13 | char *s; 14 | char *f; 15 | 16 | len_f = strlen(find); 17 | if (len_f>len) 18 | return (-1); 19 | pos = 0; 20 | while (*(str+len_f-1)) 21 | { 22 | s = str; 23 | f = find; 24 | while (*(f++) == *(s++)) 25 | if (!*f) 26 | return (pos); 27 | str ++; 28 | pos ++; 29 | } 30 | return (-1); 31 | } 32 | 33 | 34 | 35 | int mlx_int_str_str_cote(char *str,char *find,int len) 36 | { 37 | int len_f; 38 | int pos; 39 | char *s; 40 | char *f; 41 | int cote; 42 | 43 | len_f = strlen(find); 44 | if (len_f>len) 45 | return (-1); 46 | cote = 0; 47 | pos = 0; 48 | while (*(str+len_f-1)) 49 | { 50 | if (*str=='"') 51 | cote = 1-cote; 52 | if (!cote) 53 | { 54 | s = str; 55 | f = find; 56 | while (*(f++) == *(s++)) 57 | if (!*f) 58 | return (pos); 59 | } 60 | str ++; 61 | pos ++; 62 | } 63 | return (-1); 64 | } 65 | 66 | 67 | char **mlx_int_str_to_wordtab(char *str) 68 | { 69 | char **tab; 70 | int pos; 71 | int nb_word; 72 | int len; 73 | 74 | len = strlen(str); 75 | nb_word = 0; 76 | pos = 0; 77 | while (pos +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/13 15:21:06 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 10:51:55 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_printf.h" 14 | 15 | int print_format(va_list ap, const char *format) 16 | { 17 | if (*format == 'c') 18 | return (print_c(va_arg(ap, int))); 19 | else if (*format == 's') 20 | return (print_s(va_arg(ap, char *))); 21 | else if (*format == 'd' || *format == 'i') 22 | return (print_decimal(va_arg(ap, int))); 23 | else if (*format == 'u') 24 | return (print_un_decimal(va_arg(ap, int))); 25 | else if (*format == 'p') 26 | return (print_pointer(va_arg(ap, unsigned long long))); 27 | else if (*format == 'X' || *format == 'x') 28 | return (print_un_hex(va_arg(ap, unsigned int), *format)); 29 | else if (*format == '%') 30 | return (write(1, "%", 1)); 31 | else 32 | return (0); 33 | } 34 | 35 | int manage_print(const char *string, va_list ap) 36 | { 37 | int idx; 38 | int cnt; 39 | 40 | idx = 0; 41 | cnt = 0; 42 | while (string[idx]) 43 | { 44 | if (string[idx] == '%') 45 | { 46 | cnt += print_format(ap, &(string[++idx])); 47 | } 48 | else 49 | { 50 | write(1, &(string[idx]), 1); 51 | cnt++; 52 | } 53 | idx++; 54 | } 55 | return (cnt); 56 | } 57 | 58 | int ft_printf(const char *string, ...) 59 | { 60 | va_list ap; 61 | int cnt; 62 | 63 | va_start(ap, string); 64 | cnt = manage_print(string, ap); 65 | va_end(ap); 66 | return (cnt); 67 | } 68 | -------------------------------------------------------------------------------- /src_bonus/draw_bonus/draw_partial_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_partial_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/11 19:40:29 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:31:52 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "draw_bonus.h" 14 | #include "utils_bonus.h" 15 | 16 | void draw_partial_tiles(t_game *game, int row, int col) 17 | { 18 | char **map; 19 | t_component *collections; 20 | 21 | map = game->map.map; 22 | collections = game->collect.collections; 23 | if (map[row][col] == '1') 24 | ft_put_img(game, game->tiles.wall, col * TILE_SIZE, row * TILE_SIZE); 25 | else if (map[row][col] == '0' || map[row][col] == 'P') 26 | ft_put_img(game, game->tiles.ground, col * TILE_SIZE, row * TILE_SIZE); 27 | else if (map[row][col] == 'C') 28 | { 29 | while (collections) 30 | { 31 | if (collections->x == col * TILE_SIZE && collections->y == row 32 | * TILE_SIZE) 33 | return ; 34 | collections = collections->next; 35 | } 36 | ft_put_img(game, game->tiles.ground, col * TILE_SIZE, row * TILE_SIZE); 37 | } 38 | } 39 | 40 | void draw_partial(t_game *game, void (*partial_func)(t_game *, int, int)) 41 | { 42 | int row; 43 | int col; 44 | int move_status; 45 | 46 | row = (game->player.y) / TILE_SIZE; 47 | col = (game->player.x) / TILE_SIZE; 48 | move_status = game->move_status; 49 | partial_func(game, row, col); 50 | if (move_status == RIGHT || move_status == LEFT) 51 | partial_func(game, row, col + 1); 52 | else if (move_status == TOP || move_status == BOTTOM) 53 | partial_func(game, row + 1, col); 54 | } 55 | -------------------------------------------------------------------------------- /lib/libft/libft/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/07 17:20:26 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:33:27 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int get_first_index(char const *s1, char const *set) 16 | { 17 | int i; 18 | int j; 19 | int flag; 20 | 21 | i = 0; 22 | while (s1[i]) 23 | { 24 | flag = 0; 25 | j = 0 - 1; 26 | while (set[++j]) 27 | { 28 | if (set[j] == s1[i]) 29 | flag = 1; 30 | } 31 | if (!flag) 32 | return (i); 33 | i++; 34 | } 35 | return (-1); 36 | } 37 | 38 | int get_last_index(char const *s1, char const *set) 39 | { 40 | int i; 41 | int j; 42 | int flag; 43 | 44 | i = (int)ft_strlen(s1) - 1; 45 | while (s1[i] && i > 0) 46 | { 47 | flag = 0; 48 | j = 0 - 1; 49 | while (set[++j]) 50 | { 51 | if (set[j] == s1[i]) 52 | flag = 1; 53 | } 54 | if (!flag) 55 | return (i); 56 | i--; 57 | } 58 | return (-1); 59 | } 60 | 61 | char *ft_strtrim(char const *s1, char const *set) 62 | { 63 | int start; 64 | int last; 65 | int i; 66 | char *res; 67 | 68 | if (!s1) 69 | return (0); 70 | start = get_first_index(s1, set); 71 | last = get_last_index(s1, set); 72 | if (start == -1 || last == -1) 73 | { 74 | res = (char *)malloc(sizeof(char)); 75 | if (!(res)) 76 | return (0); 77 | res[0] = '\0'; 78 | return (res); 79 | } 80 | res = ft_calloc(last - start + 2, sizeof(char)); 81 | if (!(res)) 82 | return (0); 83 | i = 0 - 1; 84 | while (start + (++i) <= last) 85 | res[i] = s1[start + i]; 86 | res[i] = '\0'; 87 | return (res); 88 | } 89 | -------------------------------------------------------------------------------- /lib/libft/ft_printf/libft/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/07 17:20:26 by nkim #+# #+# */ 9 | /* Updated: 2021/09/25 11:33:27 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int get_first_index(char const *s1, char const *set) 16 | { 17 | int i; 18 | int j; 19 | int flag; 20 | 21 | i = 0; 22 | while (s1[i]) 23 | { 24 | flag = 0; 25 | j = 0 - 1; 26 | while (set[++j]) 27 | { 28 | if (set[j] == s1[i]) 29 | flag = 1; 30 | } 31 | if (!flag) 32 | return (i); 33 | i++; 34 | } 35 | return (-1); 36 | } 37 | 38 | int get_last_index(char const *s1, char const *set) 39 | { 40 | int i; 41 | int j; 42 | int flag; 43 | 44 | i = (int)ft_strlen(s1) - 1; 45 | while (s1[i] && i > 0) 46 | { 47 | flag = 0; 48 | j = 0 - 1; 49 | while (set[++j]) 50 | { 51 | if (set[j] == s1[i]) 52 | flag = 1; 53 | } 54 | if (!flag) 55 | return (i); 56 | i--; 57 | } 58 | return (-1); 59 | } 60 | 61 | char *ft_strtrim(char const *s1, char const *set) 62 | { 63 | int start; 64 | int last; 65 | int i; 66 | char *res; 67 | 68 | if (!s1) 69 | return (0); 70 | start = get_first_index(s1, set); 71 | last = get_last_index(s1, set); 72 | if (start == -1 || last == -1) 73 | { 74 | res = (char *)malloc(sizeof(char)); 75 | if (!(res)) 76 | return (0); 77 | res[0] = '\0'; 78 | return (res); 79 | } 80 | res = ft_calloc(last - start + 2, sizeof(char)); 81 | if (!(res)) 82 | return (0); 83 | i = 0 - 1; 84 | while (start + (++i) <= last) 85 | res[i] = s1[start + i]; 86 | res[i] = '\0'; 87 | return (res); 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # (੭。╹▿╹。)੭ so_long 2 | ![](https://img.shields.io/badge/Language-C-blue) 3 | ![](https://img.shields.io/badge/School-42-black) 4 | 5 | This project is a small 2D game with minilibx. You'll learn about textures, sprites and tiles. 6 | 7 | ![image](https://user-images.githubusercontent.com/51353146/152220218-a4bda6e5-9f31-4fff-9816-95958ebfff07.png) 8 | 9 | ## Preview 10 | ![solog](https://user-images.githubusercontent.com/51353146/178384797-19ed3357-c622-4c87-bc8f-fffaa978b7be.gif) 11 | 12 | 13 | ## How play the game 14 | To play this game you can use any map of your choice as long follow the following rues: 15 | 16 | * The extension need be `.ber` 17 | * Its must be rectangular, surrounded by wall `1` 18 | * Must have only one exit, only one player and at least one collectible 19 | * Characters allowed: 20 | 21 | | Character | Object | 22 | |:-----------:|:------------------------:| 23 | | *1* | wall | 24 | | *0* | Empty | 25 | | *C* | collectible | 26 | | *E* | exit | 27 | | *P* | Player starting position | 28 | | *F* | Enemy starting position | 29 | 30 | In folder [map_file](map_file) have some examples of maps. 31 | 32 | ### Control of play 33 | You can use `AWSD` to move `UP`, `DOWN`, `LEFT`, `RIGHT`. 34 | For restart the game press `ESC` or click on the red cross of window. 35 | If you touch the enemy you loose the game. 36 | To win the game its necessary pick up all collectible and pass for the exit. 37 | 38 | ### How execute the game 39 | To start the game you need run the command `make` root directory. 40 | This will compile the executable file `so_long`, to execute its necessary run `./so_long map_file/map.ber` `./so_long_bonus map_file/map.ber` or any map of your choice. 41 | 42 | ## Makefile rules 43 | 44 | | Rule | Description | 45 | |:------------:|:-------------------------------------------------------:| 46 | | `make` | Compile the program. | 47 | | `make bonus` | Compile the bonus program | 48 | | `make clean` | Remove every objects of compilation | 49 | | `make fclean`| Do `clean` rule and remove the executable program | 50 | | `make re` | Do `fclean` rule and compile the program | 51 | -------------------------------------------------------------------------------- /lib/libft/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: nkim +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/05/03 22:59:15 by nkim #+# #+# # 9 | # Updated: 2021/09/25 11:40:00 by nkim ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libft.a 14 | INCLUDES_DIR = includes 15 | 16 | CC = cc 17 | CFLAGS = -Wall -Wextra -Werror 18 | 19 | AFLAGS = rus 20 | 21 | LIBFT_DIR = libft 22 | FTPRINTF_DIR = ft_printf 23 | GNL_DIR = get-next-line 24 | 25 | LIBFT = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c \ 26 | ft_memchr.c ft_memcmp.c ft_strlen.c ft_strlcpy.c ft_strlcat.c \ 27 | ft_strchr.c ft_strrchr.c ft_strnstr.c ft_strncmp.c ft_atoi.c \ 28 | ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c \ 29 | ft_toupper.c ft_tolower.c ft_calloc.c ft_strdup.c ft_substr.c \ 30 | ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \ 31 | ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \ 32 | ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back.c \ 33 | ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c 34 | 35 | FTPRINTF = ft_printf.c print_number.c print_string.c utils.c 36 | 37 | GNL = get_next_line.c get_next_line_utils.c 38 | 39 | all : $(NAME) 40 | 41 | clean : 42 | @rm -rf $(addprefix $(LIBFT_DIR)/, $(LIBFT:.c=.o)) 43 | @rm -rf $(addprefix $(FTPRINTF_DIR)/, $(FTPRINTF:.c=.o)) 44 | @rm -rf $(addprefix $(GNL_DIR)/, $(GNL:.c=.o)) 45 | 46 | fclean : clean 47 | @rm -rf $(NAME) 48 | 49 | re : fclean all 50 | 51 | $(NAME): libft ft_printf gnl 52 | 53 | %.o: %.c 54 | @$(CC) $(CFLAGS) -c -o $@ $^ 55 | @$(AR) $(ARFLAGS) $(NAME) $@ 56 | 57 | libft: $(addprefix $(LIBFT_DIR)/, $(LIBFT:.c=.o)) 58 | ft_printf: $(addprefix $(FTPRINTF_DIR)/, $(FTPRINTF:.c=.o)) 59 | gnl: $(addprefix $(GNL_DIR)/, $(GNL:.c=.o)) 60 | 61 | 62 | .PHONY : all clean fclean re 63 | -------------------------------------------------------------------------------- /src_bonus/draw_bonus/draw_animate_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_animate_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 17:50:07 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 04:18:15 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "draw_bonus.h" 14 | #include "hook_bonus.h" 15 | #include "utils_bonus.h" 16 | 17 | void draw_animate_player(t_game *game) 18 | { 19 | int step; 20 | 21 | step = 4; 22 | if (game->move_status == RIGHT) 23 | handle_location(game, step, 0); 24 | else if (game->move_status == LEFT) 25 | handle_location(game, -step, 0); 26 | else if (game->move_status == TOP) 27 | handle_location(game, 0, -step); 28 | else if (game->move_status == BOTTOM) 29 | handle_location(game, 0, step); 30 | game->offset += step; 31 | if (game->offset > MAX_OFFSET) 32 | game->offset = 0; 33 | ft_put_img(game, game->player.sprites->img, game->player.x, game->player.y); 34 | game->player.sprites = game->player.sprites->next; 35 | } 36 | 37 | void draw_animate_collect(t_game *game) 38 | { 39 | t_component *collections; 40 | 41 | collections = game->collect.collections; 42 | while (collections) 43 | { 44 | ft_put_img(game, game->tiles.ground, collections->x, collections->y); 45 | ft_put_img( 46 | game, game->collect.sprites->img, collections->x, collections->y); 47 | collections = collections->next; 48 | } 49 | game->collect.sprites = game->collect.sprites->next; 50 | } 51 | 52 | void draw_animate_enemy(t_game *game) 53 | { 54 | t_component *enemies; 55 | 56 | enemies = game->enemy.enemies; 57 | while (enemies) 58 | { 59 | ft_put_img(game, game->tiles.ground, enemies->x, enemies->y); 60 | ft_put_img(game, game->enemy.sprites->img, enemies->x, enemies->y); 61 | enemies = enemies->next; 62 | } 63 | game->enemy.sprites = game->enemy.sprites->next; 64 | } 65 | -------------------------------------------------------------------------------- /src/game/game.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* game.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 22:18:35 by nkim #+# #+# */ 9 | /* Updated: 2022/01/29 23:34:37 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void init_window(t_game *game) 16 | { 17 | int x; 18 | int y; 19 | 20 | x = game->map.cols; 21 | y = game->map.rows; 22 | game->mlx_ptr = mlx_init(); 23 | game->win_ptr = mlx_new_window(game->mlx_ptr, \ 24 | TILE_SIZE * x, TILE_SIZE * y, "KIRBY"); 25 | game->move_status = NONE; 26 | game->offset = 0; 27 | game->collect.collections = NULL; 28 | game->step = 0; 29 | } 30 | 31 | void init_imgs(t_game *game) 32 | { 33 | t_tiles *tiles; 34 | t_player *player; 35 | 36 | tiles = &game->tiles; 37 | player = &game->player; 38 | tiles->wall = ft_make_xpm_img(game, "wall.xpm"); 39 | tiles->ground = ft_make_xpm_img(game, "ground.xpm"); 40 | tiles->exit = ft_make_xpm_img(game, "exit.xpm"); 41 | tiles->open_exit = ft_make_xpm_img(game, "open_exit.xpm"); 42 | ft_make_iterable_sprites(game, &player->r_sprites, "rkirby", 10); 43 | ft_make_iterable_sprites(game, &player->l_sprites, "lkirby", 10); 44 | ft_make_iterable_sprites(game, &game->collect.sprites, "star", 6); 45 | game->player.r_inital = game->player.r_sprites; 46 | game->player.l_inital = game->player.l_sprites; 47 | game->player.sprites = game->player.r_sprites; 48 | game->player.initial = game->player.r_sprites; 49 | } 50 | 51 | void init_game(t_game *game) 52 | { 53 | init_window(game); 54 | init_imgs(game); 55 | draw_tiles(game); 56 | draw_sprites(game); 57 | draw_exit(game); 58 | } 59 | 60 | void start_game(t_game *game) 61 | { 62 | init_game(game); 63 | printf("\033[1;33m== Start Game ==\033[0m\n"); 64 | } 65 | 66 | int close_game(t_game *game) 67 | { 68 | printf("END\n"); 69 | mlx_destroy_window(game->mlx_ptr, game->win_ptr); 70 | exit(EXIT_SUCCESS); 71 | } 72 | -------------------------------------------------------------------------------- /lib/mlx/mlx_int.h: -------------------------------------------------------------------------------- 1 | // 2 | // mlx_int.h for minilibx 3 | // 4 | // ol@staff.42.fr 5 | // 6 | // include opengl needed before mlx_int.h 7 | // 8 | 9 | 10 | #define MAX_EVENT 32 11 | #define MAX_PIXEL_NB 200000 12 | #define UNIQ_BPP 4 13 | 14 | #define FONT_WIDTH 10 15 | #define FONT_HEIGHT 20 16 | 17 | 18 | typedef int (*func_t)(); 19 | 20 | /* structs */ 21 | 22 | typedef struct glsl_info_s 23 | { 24 | GLuint pixel_vshader; 25 | GLuint pixel_fshader; 26 | GLuint pixel_program; 27 | GLint loc_pixel_position; 28 | GLint loc_pixel_texture; 29 | GLint loc_pixel_winhalfsize; 30 | 31 | GLuint image_vshader; 32 | GLuint image_fshader; 33 | GLuint image_program; 34 | GLint loc_image_position; 35 | GLint loc_image_winhalfsize; 36 | GLint loc_image_texture; 37 | GLint loc_image_pos; 38 | GLint loc_image_size; 39 | 40 | GLuint font_vshader; 41 | GLuint font_fshader; 42 | GLuint font_program; 43 | GLint loc_font_position; 44 | GLint loc_font_winhalfsize; 45 | GLint loc_font_texture; 46 | GLint loc_font_color; 47 | GLint loc_font_posinwin; 48 | GLint loc_font_posinatlas; 49 | GLint loc_font_atlassize; 50 | } glsl_info_t; 51 | 52 | 53 | typedef struct mlx_img_list_s 54 | { 55 | int width; 56 | int height; 57 | char *buffer; 58 | GLfloat vertexes[8]; 59 | struct mlx_img_list_s *next; 60 | } mlx_img_list_t; 61 | 62 | 63 | typedef struct mlx_img_ctx_s 64 | { 65 | GLuint texture; 66 | GLuint vbuffer; 67 | mlx_img_list_t *img; 68 | struct mlx_img_ctx_s *next; 69 | } mlx_img_ctx_t; 70 | 71 | typedef struct mlx_win_list_s 72 | { 73 | void *winid; 74 | mlx_img_ctx_t *img_list; 75 | int nb_flush; 76 | int pixmgt; 77 | struct mlx_win_list_s *next; 78 | } mlx_win_list_t; 79 | 80 | 81 | typedef struct mlx_ptr_s 82 | { 83 | void *appid; 84 | mlx_win_list_t *win_list; 85 | mlx_img_list_t *img_list; 86 | void (*loop_hook)(void *); 87 | void *loop_hook_data; 88 | void *loop_timer; 89 | mlx_img_list_t *font; 90 | int main_loop_active; 91 | } mlx_ptr_t; 92 | 93 | // proto 94 | 95 | int mlx_shaders(glsl_info_t *glsl); 96 | char **mlx_int_str_to_wordtab(char *str); 97 | int mlx_int_str_str(char *str,char *find,int len); 98 | int mlx_int_str_str_cote(char *str,char *find,int len); 99 | int mlx_destroy_image(mlx_ptr_t *mlx_ptr, mlx_img_list_t *img_ptr); 100 | void *mlx_new_image(); 101 | void *mlx_xpm_to_image(mlx_ptr_t *xvar,char **xpm_data,int *width,int *height); 102 | int mlx_do_sync(mlx_ptr_t *mlx_ptr); 103 | -------------------------------------------------------------------------------- /src_bonus/hook_bonus/handle_player_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* handle_player.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: nkim +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/12 06:38:50 by nkim #+# #+# */ 9 | /* Updated: 2022/07/12 07:06:26 by nkim ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "draw_bonus.h" 14 | #include "game_bonus.h" 15 | #include "hook_bonus.h" 16 | #include "utils_bonus.h" 17 | #include 18 | 19 | static void move_player(t_game *game) 20 | { 21 | draw_partial(game, &draw_partial_tiles); 22 | draw_exit(game); 23 | draw_animate_player(game); 24 | if (game->offset % TILE_SIZE == 0) 25 | printf("STEP : %d\n", ++(game->step)); 26 | if (game->is_stop) 27 | game->is_running = FALSE; 28 | draw_step(game); 29 | } 30 | 31 | static void stop_player(t_game *game) 32 | { 33 | draw_partial(game, &draw_partial_tiles); 34 | draw_exit(game); 35 | draw_animate_player(game); 36 | if (game->offset % TILE_SIZE == 0) 37 | draw_init(game); 38 | } 39 | 40 | static void fire_player(t_game *game) 41 | { 42 | static int cnt; 43 | 44 | cnt++; 45 | if (game->status == FAIL && cnt < 8) 46 | { 47 | ft_put_img(game, game->player.fire_sprites->img, game->player.x, 48 | game->player.y); 49 | game->player.fire_sprites = game->player.fire_sprites->next; 50 | } 51 | else 52 | { 53 | draw_screen(game); 54 | } 55 | } 56 | 57 | void handle_player(t_game *game) 58 | { 59 | static unsigned int frame; 60 | 61 | if (!(++frame % 864)) 62 | draw_animate_collect(game); 63 | if (!(frame % 864)) 64 | draw_animate_enemy(game); 65 | if (!(frame % 288) && game->status) 66 | fire_player(game); 67 | else if (!(frame % 288) && game->is_running) 68 | move_player(game); 69 | else if (!(frame % 288) && game->is_stop) 70 | stop_player(game); 71 | else if (!(frame % 432) && game->move_status != NONE) 72 | { 73 | move_player(game); 74 | if (game->offset % TILE_SIZE == 0) 75 | draw_init(game); 76 | } 77 | } 78 | --------------------------------------------------------------------------------