├── lib ├── src │ ├── libft │ │ ├── README.md │ │ ├── libft.h.gch │ │ ├── ft_putchar_fd.c │ │ ├── ft_isascii.c │ │ ├── ft_isdigit.c │ │ ├── ft_isprint.c │ │ ├── ft_tolower.c │ │ ├── ft_toupper.c │ │ ├── ft_isalnum.c │ │ ├── ft_strlen.c │ │ ├── ft_isalpha.c │ │ ├── ft_swap_int.c │ │ ├── ft_lstadd_front.c │ │ ├── ft_lstdelone.c │ │ ├── ft_bzero.c │ │ ├── ft_lstiter.c │ │ ├── ft_putstr_fd.c │ │ ├── ft_calloc.c │ │ ├── ft_lstsize.c │ │ ├── ft_lstlast.c │ │ ├── ft_putendl_fd.c │ │ ├── ft_lstnew.c │ │ ├── ft_memset.c │ │ ├── ft_lstclear.c │ │ ├── ft_lstadd_back.c │ │ ├── ft_strncmp.c │ │ ├── ft_strchr.c │ │ ├── ft_strrchr.c │ │ ├── ft_memchr.c │ │ ├── ft_num_tobase.c │ │ ├── ft_strdup.c │ │ ├── ft_memcpy.c │ │ ├── ft_memcmp.c │ │ ├── ft_strlcpy.c │ │ ├── ft_memccpy.c │ │ ├── ft_putnbr_fd.c │ │ ├── ft_substr.c │ │ ├── ft_strnstr.c │ │ ├── ft_strmapi.c │ │ ├── ft_strlcat.c │ │ ├── ft_lstmap.c │ │ ├── ft_memmove.c │ │ ├── ft_strjoin.c │ │ ├── ft_atoi.c │ │ ├── ft_itoa.c │ │ ├── ft_strtrim.c │ │ ├── Makefile │ │ └── ft_split.c │ ├── ft_printf │ │ ├── ft_printf_string.c │ │ ├── ft_printf_char.c │ │ ├── ft_printf.c │ │ ├── ft_printf_num.c │ │ └── ft_printf_num_print.c │ └── get_next_line │ │ └── get_next_line.c ├── README.md ├── include │ └── get_next_line.h └── Makefile ├── map ├── map_rec.ber ├── non_exit.ber ├── non_player.ber ├── map_exit.ber ├── non_rec.ber └── map_sl.ber ├── 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 ├── asset ├── ball.png ├── stone.png ├── ending.png ├── ladder.png ├── opening.png ├── tile00.png ├── tile01.png ├── gameover.png ├── loading0.png ├── loading1.png ├── player_E00.png ├── player_E01.png ├── player_E02.png ├── player_N00.png ├── player_N01.png ├── player_N02.png ├── player_S00.png ├── player_S01.png ├── player_S02.png ├── player_W00.png ├── player_W01.png ├── player_W02.png ├── rocket_E00.png ├── rocket_N00.png ├── rocket_S00.png └── rocket_W00.png ├── minilibx_opengl.tar ├── include ├── so_long.h.gch ├── error.h ├── color.h ├── key.h ├── config.h └── map.h ├── so_long_play_screen_shot.png ├── minilibx_mms_20210621 ├── mlx_init.o ├── mlx_png.o ├── mlx_xpm.o ├── interface.o ├── libmlx.dylib ├── mlx_image.o ├── mlx_window.o ├── mlx_image.swiftdoc ├── mlx_init.swiftdoc ├── mlx_string_put.o ├── mlx_init.swiftmodule ├── mlx_window.swiftdoc ├── mlx_image.swiftmodule ├── mlx_window.swiftmodule ├── mlx_image.swiftsourceinfo ├── mlx_init.swiftsourceinfo ├── mlx_window.swiftsourceinfo ├── Makefile ├── mlx_image.swift ├── man │ └── man3 │ │ ├── mlx_new_window.3 │ │ └── mlx_pixel_put.3 └── mlx_string_put.c ├── .vscode └── settings.json ├── include_bonus ├── error_bonus.h ├── color_bonus.h ├── key_bonus.h ├── config_bonus.h └── map_bonus.h ├── src ├── move_spin.c ├── reset_game.c ├── move_init.c ├── move_collision.c ├── error.c ├── draw_sprites.c ├── step_count.c ├── collec.c ├── map_check_ext.c ├── ft_mlx.c ├── map_draw.c ├── key.c ├── main.c ├── move_dir.c ├── util_lst.c ├── map_parse.c ├── enemy_script.c ├── enemy_draw.c ├── draw_scene.c ├── player_draw.c ├── init_game.c ├── event.c └── map_compo_coord.c ├── src_bonus ├── move_spin_bonus.c ├── reset_game_bonus.c ├── move_init_bonus.c ├── move_collision_bonus.c ├── error_bonus.c ├── draw_sprites_bonus.c ├── step_count_bonus.c ├── collec_bonus.c ├── map_check_ext_bonus.c ├── ft_mlx_bonus.c ├── map_draw_bonus.c ├── key_bonus.c ├── main_bonus.c ├── move_dir_bonus.c ├── util_lst_bonus.c ├── map_parse_bonus.c ├── enemy_script_bonus.c ├── enemy_draw_bonus.c ├── draw_scene_bonus.c ├── player_draw_bonus.c ├── init_game_bonus.c ├── event_bonus.c └── map_compo_coord_bonus.c ├── .gitignore └── README.md /lib/src/libft/README.md: -------------------------------------------------------------------------------- 1 | # Libft 2 | 42Seoul Libft 3 | -------------------------------------------------------------------------------- /lib/README.md: -------------------------------------------------------------------------------- 1 | # lib_jisokang 2 | 42 프로젝트에서 사용하는 개인 라이브러리 3 | -------------------------------------------------------------------------------- /map/map_rec.ber: -------------------------------------------------------------------------------- 1 | 111111 2 | 1P0C01 3 | 1000E1 4 | 111111 5 | -------------------------------------------------------------------------------- /map/non_exit.ber: -------------------------------------------------------------------------------- 1 | 111111 2 | 1P0C01 3 | 100001 4 | 111111 5 | -------------------------------------------------------------------------------- /map/non_player.ber: -------------------------------------------------------------------------------- 1 | 111111 2 | 100C01 3 | 1000E1 4 | 111111 5 | -------------------------------------------------------------------------------- /map/map_exit.ber: -------------------------------------------------------------------------------- 1 | 11111 2 | 1P0E1 3 | 1CCC1 4 | 1R001 5 | 11111 6 | -------------------------------------------------------------------------------- /mlx/font.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/mlx/font.xcf -------------------------------------------------------------------------------- /asset/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/ball.png -------------------------------------------------------------------------------- /asset/stone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/stone.png -------------------------------------------------------------------------------- /asset/ending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/ending.png -------------------------------------------------------------------------------- /asset/ladder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/ladder.png -------------------------------------------------------------------------------- /asset/opening.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/opening.png -------------------------------------------------------------------------------- /asset/tile00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/tile00.png -------------------------------------------------------------------------------- /asset/tile01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/tile01.png -------------------------------------------------------------------------------- /asset/gameover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/gameover.png -------------------------------------------------------------------------------- /asset/loading0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/loading0.png -------------------------------------------------------------------------------- /asset/loading1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/loading1.png -------------------------------------------------------------------------------- /asset/player_E00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_E00.png -------------------------------------------------------------------------------- /asset/player_E01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_E01.png -------------------------------------------------------------------------------- /asset/player_E02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_E02.png -------------------------------------------------------------------------------- /asset/player_N00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_N00.png -------------------------------------------------------------------------------- /asset/player_N01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_N01.png -------------------------------------------------------------------------------- /asset/player_N02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_N02.png -------------------------------------------------------------------------------- /asset/player_S00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_S00.png -------------------------------------------------------------------------------- /asset/player_S01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_S01.png -------------------------------------------------------------------------------- /asset/player_S02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_S02.png -------------------------------------------------------------------------------- /asset/player_W00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_W00.png -------------------------------------------------------------------------------- /asset/player_W01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_W01.png -------------------------------------------------------------------------------- /asset/player_W02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/player_W02.png -------------------------------------------------------------------------------- /asset/rocket_E00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/rocket_E00.png -------------------------------------------------------------------------------- /asset/rocket_N00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/rocket_N00.png -------------------------------------------------------------------------------- /asset/rocket_S00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/rocket_S00.png -------------------------------------------------------------------------------- /asset/rocket_W00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/asset/rocket_W00.png -------------------------------------------------------------------------------- /minilibx_opengl.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_opengl.tar -------------------------------------------------------------------------------- /include/so_long.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/include/so_long.h.gch -------------------------------------------------------------------------------- /lib/src/libft/libft.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/lib/src/libft/libft.h.gch -------------------------------------------------------------------------------- /mlx/mlx_png.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | void *mlx_png_file_to_image(void *xvar, char *file, int *width, int *height); 5 | -------------------------------------------------------------------------------- /so_long_play_screen_shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/so_long_play_screen_shot.png -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_init.o -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_png.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_png.o -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_xpm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_xpm.o -------------------------------------------------------------------------------- /minilibx_mms_20210621/interface.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/interface.o -------------------------------------------------------------------------------- /minilibx_mms_20210621/libmlx.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/libmlx.dylib -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_image.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_image.o -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_window.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_window.o -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_image.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_image.swiftdoc -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_init.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_init.swiftdoc -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_string_put.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_string_put.o -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_init.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_init.swiftmodule -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_window.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_window.swiftdoc -------------------------------------------------------------------------------- /map/non_rec.ber: -------------------------------------------------------------------------------- 1 | 111 111 2 | 10111101 3 | 1111P000001 4 | 1010011101111111 5 | 1000011000000001 6 | 10001 1000111111 7 | 11111 11111 8 | -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_image.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_image.swiftmodule -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_window.swiftmodule: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_window.swiftmodule -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_image.swiftsourceinfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_image.swiftsourceinfo -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_init.swiftsourceinfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_init.swiftsourceinfo -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_window.swiftsourceinfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devleomk1/so_long/HEAD/minilibx_mms_20210621/mlx_window.swiftsourceinfo -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "ios": "c", 4 | "istream": "c", 5 | "locale": "c", 6 | "stdlib.h": "c", 7 | "so_long.h": "c", 8 | "string.h": "c" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /map/map_sl.ber: -------------------------------------------------------------------------------- 1 | 1111111111111 2 | 11111P11111C1 3 | 1000001000101 4 | 10111010R0C01 5 | 1C10000001101 6 | 1000111100001 7 | 1010111100111 8 | 1010011C00001 9 | 10C1011111001 10 | 11110000C10E1 11 | 1111111111111 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /minilibx_mms_20210621/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | MODULE_SRC= mlx_image.swift mlx_window.swift mlx_init.swift 5 | MODULE_OBJ=$(MODULE_SRC:.swift=.swiftmodule) 6 | 7 | SRC= interface.swift $(MODULE_SRC) 8 | OBJ=$(SRC:.swift=.o) 9 | 10 | C_SRC= mlx_xpm.c mlx_png.c mlx_string_put.c 11 | C_OBJ=$(C_SRC:.c=.o) 12 | CFLAGS=-O3 13 | 14 | NAME=libmlx.dylib 15 | 16 | INC=-I. 17 | #OPTI=-Ounchecked 18 | 19 | all: $(NAME) 20 | 21 | $(NAME): $(MODULE_OBJ) $(OBJ) $(C_OBJ) 22 | swiftc $(OPTI) $(INC) -o $(NAME) -emit-library $(OBJ) $(C_OBJ) -lz 23 | 24 | 25 | 26 | %.o: %.swift 27 | swiftc $(OPTI) $(INC) -parse-as-library -c $< -o $@ 28 | 29 | %.swiftmodule: %.swift 30 | swiftc $(OPTI) $(INC) -parse-as-library -c $< -o $@ -emit-module -module-name $(patsubst %.swift,%,$<) -module-link-name $(patsubst %.swift,%,$<) 31 | 32 | clean: 33 | rm -f $(NAME) $(OBJ) $(MODULE_OBJ) $(C_OBJ) *.swiftdoc *~ 34 | 35 | -------------------------------------------------------------------------------- /lib/src/libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/09 14:20:24 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /include/error.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* error.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/28 02:29:48 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 13:16:26 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ERROR_H 14 | # define ERROR_H 15 | 16 | # define EXIT_ERR 1 17 | 18 | void exit_err(char *msg); 19 | void debug(char *msg, int debug); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/22 18:14:24 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_isascii(int c) 16 | { 17 | if (c >= 0 && c <= 127) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/22 17:57:46 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_isdigit(int c) 16 | { 17 | if (c >= '0' && c <= '9') 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/22 18:16:48 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_isprint(int c) 16 | { 17 | if (c >= 32 && c <= 126) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/22 23:13:35 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_tolower(int c) 16 | { 17 | if (c >= 'A' && c <= 'Z') 18 | return (c + 32); 19 | else 20 | return (c); 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/22 23:06:35 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (c >= 'a' && c <= 'z') 18 | return (c - 32); 19 | else 20 | return (c); 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/22 18:03:48 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_isalnum(int c) 16 | { 17 | if (ft_isalpha(c) || ft_isdigit(c)) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /include_bonus/error_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* error_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/28 02:29:48 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 16:36:27 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ERROR_BONUS_H 14 | # define ERROR_BONUS_H 15 | 16 | # define EXIT_ERR 1 17 | 18 | void exit_err(char *msg); 19 | void debug(char *msg, int debug); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/29 05:01:46 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (s[i] != '\0') 21 | i++; 22 | return (i); 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/22 17:06:04 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_isalpha(int c) 16 | { 17 | if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_swap_int.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_swap_int.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/06/21 19:39:49 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_swap_int(int *a, int *b) 16 | { 17 | int tmp; 18 | 19 | if (*a == *b) 20 | return ; 21 | tmp = *a; 22 | *a = *b; 23 | *b = tmp; 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/13 08:18:36 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_lstadd_front(t_list **lst, t_list *new) 16 | { 17 | if (lst == NULL || new == NULL) 18 | return ; 19 | new->next = *lst; 20 | *lst = new; 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/14 05:44:44 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void *)) 16 | { 17 | if (lst == NULL || del == NULL) 18 | return ; 19 | del(lst->content); 20 | free(lst); 21 | } 22 | -------------------------------------------------------------------------------- /src/move_spin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_spin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 12:12:32 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void spin_clockwise(t_spr *sprite) 16 | { 17 | if (sprite->dir == DIR_NONE) 18 | return ; 19 | sprite->dir++; 20 | if (sprite->dir > DIR_EAST) 21 | sprite->dir = DIR_SOUTH; 22 | } 23 | -------------------------------------------------------------------------------- /src_bonus/move_spin_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_spin_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 12:12:32 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void spin_clockwise(t_spr *sprite) 16 | { 17 | if (sprite->dir == DIR_NONE) 18 | return ; 19 | sprite->dir++; 20 | if (sprite->dir > DIR_EAST) 21 | sprite->dir = DIR_SOUTH; 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/libft/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/29 01:42:44 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | unsigned char *dst; 18 | size_t i; 19 | 20 | dst = s; 21 | i = 0; 22 | while (n > 0) 23 | { 24 | dst[i] = 0; 25 | i++; 26 | n--; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/14 13:41:12 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | if (lst == NULL || f == NULL) 18 | return ; 19 | while (lst != NULL) 20 | { 21 | f(lst->content); 22 | lst = lst->next; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/libft/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/09 14:52:32 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_putstr_fd(char *s, int fd) 16 | { 17 | size_t i; 18 | 19 | if (s == NULL) 20 | return ; 21 | i = 0; 22 | while (s[i] != '\0') 23 | { 24 | write(fd, &s[i], 1); 25 | i++; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/libft/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/06 03:06:12 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void *ft_calloc(size_t count, size_t size) 16 | { 17 | void *new; 18 | 19 | new = malloc(count * size); 20 | if (new == NULL) 21 | return (NULL); 22 | ft_bzero(new, (count * size)); 23 | return (new); 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/13 08:38:41 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int i; 18 | t_list *curr; 19 | 20 | i = 0; 21 | curr = lst; 22 | while (curr != NULL) 23 | { 24 | curr = curr->next; 25 | i++; 26 | } 27 | return (i); 28 | } 29 | -------------------------------------------------------------------------------- /include/color.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* color.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/06/07 20:09:25 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/07 18:13:40 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef COLOR_H 14 | # define COLOR_H 15 | 16 | # define RED "\x1b[31m" 17 | # define GREEN "\x1b[32m" 18 | # define BLUE "\x1b[34m" 19 | # define YELLOW "\x1b[33m" 20 | # define MAGENTA "\x1b[35m" 21 | # define CYAN "\x1b[36m" 22 | 23 | # define RESET "\x1b[0m" 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/13 17:18:34 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | t_list *curr; 18 | 19 | curr = lst; 20 | if (lst == NULL) 21 | return (NULL); 22 | while (curr->next != NULL) 23 | { 24 | curr = curr->next; 25 | } 26 | return (curr); 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/09 15:06:15 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_putendl_fd(char *s, int fd) 16 | { 17 | size_t i; 18 | 19 | if (s == NULL) 20 | return ; 21 | i = 0; 22 | while (s[i] != '\0') 23 | { 24 | write(fd, &s[i], 1); 25 | i++; 26 | } 27 | write(fd, "\n", 1); 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/12 17:41:10 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *new; 18 | 19 | new = (t_list *)malloc(sizeof(t_list)); 20 | if (new == NULL) 21 | return (NULL); 22 | new->content = content; 23 | new->next = NULL; 24 | return (new); 25 | } 26 | -------------------------------------------------------------------------------- /include_bonus/color_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* color_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/06/07 20:09:25 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 16:36:47 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef COLOR_BONUS_H 14 | # define COLOR_BONUS_H 15 | 16 | # define RED "\x1b[31m" 17 | # define GREEN "\x1b[32m" 18 | # define BLUE "\x1b[34m" 19 | # define YELLOW "\x1b[33m" 20 | # define MAGENTA "\x1b[35m" 21 | # define CYAN "\x1b[36m" 22 | 23 | # define RESET "\x1b[0m" 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/src/libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/03 11:33:07 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void *ft_memset(void *b, int c, size_t len) 16 | { 17 | unsigned char *dst; 18 | unsigned char value; 19 | size_t i; 20 | 21 | dst = b; 22 | value = c; 23 | i = 0; 24 | while (i < len) 25 | { 26 | dst[i] = value; 27 | i++; 28 | } 29 | return (b); 30 | } 31 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/14 11:51:01 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void *)) 16 | { 17 | t_list *curr; 18 | t_list *next_lst; 19 | 20 | curr = *lst; 21 | while (curr != NULL) 22 | { 23 | next_lst = curr->next; 24 | ft_lstdelone(curr, del); 25 | curr = next_lst; 26 | } 27 | *lst = NULL; 28 | } 29 | -------------------------------------------------------------------------------- /src/reset_game.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* reset_game.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 15:14:05 by jisokang #+# #+# */ 9 | /* Updated: 2021/11/23 17:41:31 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | int reset_game(t_game *game) 16 | { 17 | ft_putstr_fd("RESET\n", 1); 18 | game->flag.game_scene = GAME_PLAYING; 19 | free(game->collec.clst); 20 | init_collec(game); 21 | get_compo_coord(game); 22 | init_player(game); 23 | init_enemy(game); 24 | init_flag(game); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /src/move_init.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_init.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/18 03:54:23 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void init_dir(t_game *game) 16 | { 17 | game->dir2coord[DIR_NONE] = (t_coord){0, 0}; 18 | game->dir2coord[DIR_NORTH] = (t_coord){0, -1}; 19 | game->dir2coord[DIR_SOUTH] = (t_coord){0, 1}; 20 | game->dir2coord[DIR_WEST] = (t_coord){-1, 0}; 21 | game->dir2coord[DIR_EAST] = (t_coord){1, 0}; 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/libft/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/13 17:29:42 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | t_list *last; 18 | 19 | if (lst == NULL || new == NULL) 20 | return ; 21 | if (*lst == NULL) 22 | { 23 | *lst = new; 24 | return ; 25 | } 26 | last = ft_lstlast(*lst); 27 | new->next = last->next; 28 | last->next = new; 29 | } 30 | -------------------------------------------------------------------------------- /src_bonus/reset_game_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* reset_game_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 15:14:05 by jisokang #+# #+# */ 9 | /* Updated: 2021/11/23 17:43:32 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | int reset_game(t_game *game) 16 | { 17 | ft_putstr_fd("RESET\n", 1); 18 | game->flag.game_scene = GAME_PLAYING; 19 | free(game->collec.clst); 20 | init_collec(game); 21 | get_compo_coord(game); 22 | init_player(game); 23 | init_enemy(game); 24 | init_flag(game); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/02 03:40:37 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | while (n > 0 && (*s1 != '\0' && *s2 != '\0')) 18 | { 19 | if (*s1 != *s2) 20 | break ; 21 | s1++; 22 | s2++; 23 | n--; 24 | } 25 | if (n == 0) 26 | return (0); 27 | return (*(unsigned char*)s1 - *(unsigned char*)s2); 28 | } 29 | -------------------------------------------------------------------------------- /src_bonus/move_init_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_init_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/18 03:54:23 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void init_dir(t_game *game) 16 | { 17 | game->dir2coord[DIR_NONE] = (t_coord){0, 0}; 18 | game->dir2coord[DIR_NORTH] = (t_coord){0, -1}; 19 | game->dir2coord[DIR_SOUTH] = (t_coord){0, 1}; 20 | game->dir2coord[DIR_WEST] = (t_coord){-1, 0}; 21 | game->dir2coord[DIR_EAST] = (t_coord){1, 0}; 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/02 21:28:23 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | char find; 18 | int i; 19 | 20 | find = (unsigned char)c; 21 | i = 0; 22 | while (s[i] != '\0') 23 | { 24 | if (s[i] == find) 25 | return ((char *)s + i); 26 | i++; 27 | } 28 | if (s[i] == find) 29 | return ((char *)s + i); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/03 04:10:22 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | char find; 18 | int i; 19 | 20 | find = (unsigned char)c; 21 | i = ft_strlen(s); 22 | while (i > 0) 23 | { 24 | if (s[i] == find) 25 | return ((char *)s + i); 26 | i--; 27 | } 28 | if (s[0] == find) 29 | return ((char *)s); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/libft/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/05 12:14:48 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | unsigned char *str; 18 | unsigned char find; 19 | size_t i; 20 | 21 | str = (unsigned char *)s; 22 | find = (unsigned char)c; 23 | i = 0; 24 | while (i < n) 25 | { 26 | if (str[i] == find) 27 | return (str + i); 28 | i++; 29 | } 30 | return (NULL); 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/libft/ft_num_tobase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_num_tobase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/06/23 19:17:02 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:40:35 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | /** 16 | * num = 1234 17 | * num_box = [4][3][2][1] 18 | * len = 4 19 | */ 20 | int ft_num_tobase(int *num_box, long long num, unsigned int base) 21 | { 22 | int len; 23 | 24 | len = 0; 25 | { 26 | while (num != 0) 27 | { 28 | num_box[len++] = num % base; 29 | num = num / base; 30 | } 31 | } 32 | return (len); 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/06 03:09:27 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | char *s2; 18 | size_t i; 19 | size_t len; 20 | 21 | len = ft_strlen(s1); 22 | s2 = malloc(sizeof(char) * (len + 1)); 23 | if (s2 == NULL) 24 | return (NULL); 25 | i = 0; 26 | while (s1[i] != '\0') 27 | { 28 | s2[i] = s1[i]; 29 | i++; 30 | } 31 | s2[i] = '\0'; 32 | return (s2); 33 | } 34 | -------------------------------------------------------------------------------- /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/src/libft/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/05 06:26:19 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t n) 16 | { 17 | unsigned char *d; 18 | unsigned char *s; 19 | size_t i; 20 | 21 | if (dst == NULL && src == NULL) 22 | return (NULL); 23 | d = (unsigned char *)dst; 24 | s = (unsigned char *)src; 25 | i = 0; 26 | while (i < n) 27 | { 28 | d[i] = s[i]; 29 | i++; 30 | } 31 | return (dst); 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/05 14:14:14 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | unsigned char *str1; 18 | unsigned char *str2; 19 | size_t i; 20 | 21 | str1 = (unsigned char *)s1; 22 | str2 = (unsigned char *)s2; 23 | i = 0; 24 | while (n > 0) 25 | { 26 | if (str1[i] != str2[i]) 27 | return (str1[i] - str2[i]); 28 | i++; 29 | n--; 30 | } 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /src/move_collision.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_collision.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:28:20 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | int is_collision(t_game *game, t_spr *sprite, int dir) 16 | { 17 | int x; 18 | int y; 19 | char c; 20 | 21 | x = game->dir2coord[dir].x; 22 | y = game->dir2coord[dir].y; 23 | c = game->maps.coord[sprite->y + y][sprite->x + x]; 24 | if (c == '1') 25 | return (TRUE); 26 | else if (c == 'E' && !game->flag.collect_all) 27 | return (TRUE); 28 | return (FALSE); 29 | } 30 | -------------------------------------------------------------------------------- /src/error.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* error.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/12 00:54:34 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 13:35:24 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void exit_err(char *msg) 16 | { 17 | ft_putstr_fd(RED "Error\n" RESET, 2); 18 | ft_putstr_fd(YELLOW, 2); 19 | ft_putstr_fd(msg, 2); 20 | ft_putstr_fd(RESET, 2); 21 | exit (EXIT_ERR); 22 | } 23 | 24 | void debug(char *msg, int debug) 25 | { 26 | if (debug == TRUE) 27 | { 28 | ft_putstr_fd("\t", 1); 29 | ft_putstr_fd(msg, 1); 30 | ft_putstr_fd(GREEN "\t\tOK\n" RESET, 1); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src_bonus/move_collision_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_collision_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:28:20 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | int is_collision(t_game *game, t_spr *sprite, int dir) 16 | { 17 | int x; 18 | int y; 19 | char c; 20 | 21 | x = game->dir2coord[dir].x; 22 | y = game->dir2coord[dir].y; 23 | c = game->maps.coord[sprite->y + y][sprite->x + x]; 24 | if (c == '1') 25 | return (TRUE); 26 | else if (c == 'E' && !game->flag.collect_all) 27 | return (TRUE); 28 | return (FALSE); 29 | } 30 | -------------------------------------------------------------------------------- /src_bonus/error_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* error_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/12 00:54:34 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void exit_err(char *msg) 16 | { 17 | ft_putstr_fd(RED "Error\n" RESET, 2); 18 | ft_putstr_fd(YELLOW, 2); 19 | ft_putstr_fd(msg, 2); 20 | ft_putstr_fd(RESET, 2); 21 | exit (EXIT_ERR); 22 | } 23 | 24 | void debug(char *msg, int debug) 25 | { 26 | if (debug == TRUE) 27 | { 28 | ft_putstr_fd("\t", 1); 29 | ft_putstr_fd(msg, 1); 30 | ft_putstr_fd(GREEN "\t\tOK\n" RESET, 1); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/29 06:23:10 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t i; 18 | size_t src_len; 19 | 20 | if (dst == NULL || src == NULL) 21 | return (0); 22 | src_len = ft_strlen(src); 23 | if (dstsize == 0) 24 | return (src_len); 25 | i = 0; 26 | while (i < (dstsize - 1) && src[i] != '\0') 27 | { 28 | dst[i] = src[i]; 29 | i++; 30 | } 31 | dst[i] = '\0'; 32 | return (src_len); 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/libft/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/05 11:48:08 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void *ft_memccpy(void *dst, const void *src, int c, size_t n) 16 | { 17 | unsigned char *d; 18 | unsigned char *s; 19 | unsigned char find; 20 | size_t i; 21 | 22 | d = (unsigned char *)dst; 23 | s = (unsigned char *)src; 24 | i = 0; 25 | find = (unsigned char)c; 26 | while (i < n) 27 | { 28 | d[i] = s[i]; 29 | if (s[i] == find) 30 | return (dst + i + 1); 31 | i++; 32 | } 33 | return (NULL); 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/09 15:31:45 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void display_nbr(int n, int fd) 16 | { 17 | if (n >= 10) 18 | display_nbr(n / 10, fd); 19 | write(fd, &"0123456789" [n % 10], 1); 20 | } 21 | 22 | void ft_putnbr_fd(int n, int fd) 23 | { 24 | if (fd < 0) 25 | return ; 26 | if (n == -2147483648) 27 | { 28 | write(fd, "-2147483648", 11); 29 | return ; 30 | } 31 | if (n < 0) 32 | { 33 | write(fd, "-", 1); 34 | n = n * -1; 35 | } 36 | display_nbr(n, fd); 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/libft/ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/07 03:48:34 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | char *ft_substr(char const *s, unsigned int start, size_t len) 16 | { 17 | char *substr; 18 | size_t s_len; 19 | 20 | if (s == NULL) 21 | return (NULL); 22 | s_len = ft_strlen(s); 23 | substr = (char *)malloc(sizeof(char) * (len + 1)); 24 | if (start >= s_len) 25 | { 26 | substr[0] = '\0'; 27 | return (substr); 28 | } 29 | if (substr == NULL) 30 | return (NULL); 31 | ft_strlcpy(substr, s + start, len + 1); 32 | return (substr); 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/05 04:37:25 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../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 | 20 | if (*needle == '\0') 21 | return ((char *)haystack); 22 | i = 0; 23 | while (haystack[i] != '\0' && i < len) 24 | { 25 | j = 0; 26 | while (haystack[i + j] == needle[j] && i + j < len) 27 | { 28 | j++; 29 | if (needle[j] == '\0') 30 | return ((char *)&haystack[i]); 31 | } 32 | i++; 33 | } 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/10 06:39:21 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | char *newstr; 18 | size_t len; 19 | size_t i; 20 | 21 | if (s == NULL || f == NULL) 22 | return (NULL); 23 | len = ft_strlen(s); 24 | newstr = (char *)malloc(sizeof(char) * (len + 1)); 25 | if (newstr == NULL) 26 | return (NULL); 27 | i = 0; 28 | while (s[i] != '\0') 29 | { 30 | newstr[i] = f(i, s[i]); 31 | i++; 32 | } 33 | newstr[i] = '\0'; 34 | return (newstr); 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/12/29 05:31:29 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t src_len; 18 | size_t dst_len; 19 | size_t i; 20 | 21 | src_len = ft_strlen(src); 22 | dst_len = ft_strlen(dst); 23 | if (dstsize < dst_len + 1) 24 | return (dstsize + src_len); 25 | i = 0; 26 | while (src[i] != '\0' && dst_len + i + 1 < dstsize) 27 | { 28 | dst[dst_len + i] = src[i]; 29 | i++; 30 | } 31 | dst[dst_len + i] = '\0'; 32 | return (dst_len + src_len); 33 | } 34 | -------------------------------------------------------------------------------- /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/src/libft/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/14 13:50:17 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 16 | { 17 | t_list *result; 18 | t_list *temp; 19 | 20 | if (lst == NULL || f == NULL) 21 | return (NULL); 22 | result = NULL; 23 | while (lst != NULL) 24 | { 25 | temp = ft_lstnew((*f)(lst->content)); 26 | if (temp == NULL) 27 | { 28 | ft_lstclear(&result, del); 29 | return (NULL); 30 | } 31 | ft_lstadd_back(&result, temp); 32 | temp = temp->next; 33 | lst = lst->next; 34 | } 35 | return (result); 36 | } 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | so_long 2 | so_long_bonus 3 | 4 | # Created by https://www.toptal.com/developers/gitignore/api/macos,c 5 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,c 6 | 7 | ### C ### 8 | # Prerequisites 9 | *.d 10 | 11 | # Object files 12 | *.o 13 | *.ko 14 | *.obj 15 | *.elf 16 | 17 | # Linker output 18 | *.ilk 19 | *.map 20 | *.exp 21 | 22 | # Precompiled Headers 23 | *.gch 24 | *.pch 25 | 26 | # Libraries 27 | *.lib 28 | *.a 29 | *.la 30 | *.lo 31 | 32 | # Shared objects (inc. Windows DLLs) 33 | *.dll 34 | *.so 35 | *.so.* 36 | *.dylib 37 | 38 | # Executables 39 | *.exe 40 | *.out 41 | *.app 42 | *.i*86 43 | *.x86_64 44 | *.hex 45 | 46 | # Debug files 47 | *.dSYM/ 48 | *.su 49 | *.idb 50 | *.pdb 51 | 52 | # Kernel Module Compile Results 53 | *.mod* 54 | *.cmd 55 | .tmp_versions/ 56 | modules.order 57 | Module.symvers 58 | Mkfile.old 59 | dkms.conf 60 | 61 | ### macOS ### 62 | # General 63 | .DS_Store 64 | .AppleDouble 65 | .LSOverride 66 | 67 | # Icon must end with two \r 68 | Icon 69 | 70 | 71 | # Thumbnails 72 | ._* 73 | 74 | # Files that might appear in the root of a volume 75 | .DocumentRevisions-V100 76 | .fseventsd 77 | .Spotlight-V100 78 | .TemporaryItems 79 | .Trashes 80 | .VolumeIcon.icns 81 | .com.apple.timemachine.donotpresent 82 | 83 | # Directories potentially created on remote AFP share 84 | .AppleDB 85 | .AppleDesktop 86 | Network Trash Folder 87 | Temporary Items 88 | .apdisk 89 | 90 | # End of https://www.toptal.com/developers/gitignore/api/macos,c 91 | -------------------------------------------------------------------------------- /src/draw_sprites.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_sprites.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 16:32:14 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | /** 16 | * If you print the sprites at the 17 | * top of the screen first, they 18 | * do not overlap unnaturally. 19 | */ 20 | void draw_sprites(t_game *game) 21 | { 22 | int i; 23 | int j; 24 | 25 | i = 0; 26 | while (i < game->maps.rows) 27 | { 28 | j = 0; 29 | while (j < game->maps.cols) 30 | { 31 | if (game->player.spr.x == j && game->player.spr.y == i) 32 | draw_player(game); 33 | else if (game->enemy.x == j && game->enemy.y == i) 34 | draw_enemy(game); 35 | j++; 36 | } 37 | i++; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /include/key.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/18 02:27:06 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 20:07:05 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef KEY_H 14 | # define KEY_H 15 | 16 | # define X_EVENT_KEY_PRESS 2 17 | 18 | /* Clicking on the RED cross on the window frame */ 19 | # define X_EVENT_KEY_EXIT 17 20 | 21 | # define KEY_ESC 53 22 | # define KEY_R 15 23 | # define KEY_RETURN 36 24 | 25 | # define KEY_W 13 26 | # define KEY_A 0 27 | # define KEY_S 1 28 | # define KEY_D 2 29 | # define KEY_UP 126 30 | # define KEY_LEFT 123 31 | # define KEY_DOWN 125 32 | # define KEY_RIGHT 124 33 | 34 | typedef struct s_game t_game; 35 | 36 | int deal_key(int key_code, t_game *game); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/step_count.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* step_count.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/31 07:16:05 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 13:10:00 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | static void print_step_count(t_game *game) 16 | { 17 | ft_putstr_fd("Step : ", 1); 18 | ft_putnbr_fd(game->player.spr.step, 1); 19 | ft_putstr_fd("\n", 1); 20 | game->flag.step_cnt = FALSE; 21 | } 22 | 23 | void draw_step_count(t_game *game) 24 | { 25 | char *str; 26 | 27 | str = ft_itoa(game->player.spr.step); 28 | if (game->flag.step_cnt && game->flag.game_scene == GAME_PLAYING) 29 | print_step_count(game); 30 | ft_put_img64(game, game->tile.tb.ptr, 0, 0); 31 | mlx_string_put(game->mlx, game->win, 24, 36, 0x000000, str); 32 | free(str); 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/libft/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/04 02:27:48 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t len) 16 | { 17 | unsigned char *new_dst; 18 | unsigned char *new_src; 19 | size_t i; 20 | 21 | if (dst == src || len == 0) 22 | return (dst); 23 | i = 0; 24 | new_dst = (unsigned char *)dst; 25 | new_src = (unsigned char *)src; 26 | if (dst < src) 27 | { 28 | while (i++ < len) 29 | new_dst[i - 1] = new_src[i - 1]; 30 | } 31 | else 32 | { 33 | while (i < len) 34 | { 35 | new_dst[len - i - 1] = new_src[len - i - 1]; 36 | i++; 37 | } 38 | } 39 | return (dst); 40 | } 41 | -------------------------------------------------------------------------------- /src_bonus/draw_sprites_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_sprites_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 16:32:14 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | /** 16 | * If you print the sprites at the 17 | * top of the screen first, they 18 | * do not overlap unnaturally. 19 | */ 20 | void draw_sprites(t_game *game) 21 | { 22 | int i; 23 | int j; 24 | 25 | i = 0; 26 | while (i < game->maps.rows) 27 | { 28 | j = 0; 29 | while (j < game->maps.cols) 30 | { 31 | if (game->player.spr.x == j && game->player.spr.y == i) 32 | draw_player(game); 33 | else if (game->enemy.x == j && game->enemy.y == i) 34 | draw_enemy(game); 35 | j++; 36 | } 37 | i++; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /include_bonus/key_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/18 02:27:06 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 16:36:23 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef KEY_BONUS_H 14 | # define KEY_BONUS_H 15 | 16 | # define X_EVENT_KEY_PRESS 2 17 | 18 | /* Clicking on the RED cross on the window frame */ 19 | # define X_EVENT_KEY_EXIT 17 20 | 21 | # define KEY_ESC 53 22 | # define KEY_R 15 23 | # define KEY_RETURN 36 24 | 25 | # define KEY_W 13 26 | # define KEY_A 0 27 | # define KEY_S 1 28 | # define KEY_D 2 29 | # define KEY_UP 126 30 | # define KEY_LEFT 123 31 | # define KEY_DOWN 125 32 | # define KEY_RIGHT 124 33 | 34 | typedef struct s_game t_game; 35 | 36 | int deal_key(int key_code, t_game *game); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_image.swift: -------------------------------------------------------------------------------- 1 | 2 | 3 | import Metal 4 | 5 | 6 | public class MlxImg 7 | { 8 | public var texture: MTLTexture 9 | /// var texture_buff: MTLBuffer 10 | 11 | public var texture_sizeline: Int 12 | public var texture_data: UnsafeMutablePointer 13 | public var texture_width: Int 14 | public var texture_height: Int 15 | 16 | public var onGPU = 0 17 | 18 | convenience public init(d device:MTLDevice, w width:Int, h height:Int) 19 | { 20 | self.init(d:device, w:width, h:height, t:0) 21 | } 22 | 23 | public init(d device:MTLDevice, w width:Int, h height:Int, t target:Int) 24 | { 25 | texture_width = width 26 | texture_height = height 27 | texture_sizeline = width * 4 28 | texture_sizeline = 256 * (texture_sizeline / 256 + (texture_sizeline%256 >= 1 ? 1 : 0) ) 29 | 30 | let textureDesc = MTLTextureDescriptor() 31 | textureDesc.width = texture_width 32 | textureDesc.height = texture_height 33 | textureDesc.usage = .shaderRead 34 | if (target == 1) 35 | { 36 | textureDesc.usage = .renderTarget 37 | textureDesc.storageMode = .private 38 | } 39 | textureDesc.pixelFormat = MTLPixelFormat.bgra8Unorm 40 | let texture_buff = device.makeBuffer(length: texture_sizeline * height)! 41 | texture = texture_buff.makeTexture(descriptor:textureDesc, offset:0, bytesPerRow:texture_sizeline)! 42 | 43 | let tmpptr = texture_buff.contents() 44 | texture_data = tmpptr.assumingMemoryBound(to:UInt32.self) 45 | } 46 | 47 | 48 | } -------------------------------------------------------------------------------- /src_bonus/step_count_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* step_count_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/31 07:16:05 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | static void print_step_count(t_game *game) 16 | { 17 | ft_putstr_fd("Step : ", 1); 18 | ft_putnbr_fd(game->player.spr.step, 1); 19 | ft_putstr_fd("\n", 1); 20 | game->flag.step_cnt = FALSE; 21 | } 22 | 23 | void draw_step_count(t_game *game) 24 | { 25 | char *str; 26 | 27 | str = ft_itoa(game->player.spr.step); 28 | if (game->flag.step_cnt && game->flag.game_scene == GAME_PLAYING) 29 | print_step_count(game); 30 | ft_put_img64(game, game->tile.tb.ptr, 0, 0); 31 | mlx_string_put(game->mlx, game->win, 24, 36, 0x000000, str); 32 | free(str); 33 | } 34 | -------------------------------------------------------------------------------- /src/collec.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* collec.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 05:47:01 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void init_collec(t_game *game) 16 | { 17 | game->collec.clst = NULL; 18 | } 19 | 20 | void draw_collect(t_game *game) 21 | { 22 | int x; 23 | int y; 24 | t_clst *lst; 25 | 26 | x = game->player.spr.x; 27 | y = game->player.spr.y; 28 | lst = game->collec.clst; 29 | while (lst) 30 | { 31 | if (!lst->istouch) 32 | { 33 | if (lst->coord.x == x && lst->coord.y == y) 34 | { 35 | lst->istouch = TRUE; 36 | game->player.item++; 37 | } 38 | ft_put_img64(game, game->collec.ball.ptr, 39 | lst->coord.x, lst->coord.y); 40 | } 41 | lst = lst->next; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/map_check_ext.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_check_ext.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:18:38 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:50:06 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | int check_ext(char *str, char *ext) 16 | { 17 | int i; 18 | int j; 19 | 20 | if (ext[0] != '.') 21 | exit_err("Invalid function parameter. ext[0] must be 'dot' charter\n"); 22 | i = ft_strlen(str) - ft_strlen(ext); 23 | if (i <= 0 || str[i] != '.') 24 | exit_err("Wrong extension or file path.\n"); 25 | j = 0; 26 | while (str[i + j] != '\0' && ext[j] != '\0') 27 | { 28 | if (str[i + j] == ext[j]) 29 | j++; 30 | else 31 | break ; 32 | } 33 | if (!(str[i + j] == '\0' && ext[j] == '\0')) 34 | exit_err("Wrong extension or file path.\n"); 35 | return (TRUE); 36 | } 37 | -------------------------------------------------------------------------------- /src_bonus/collec_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* collec_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 05:47:01 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:06 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void init_collec(t_game *game) 16 | { 17 | game->collec.clst = NULL; 18 | } 19 | 20 | void draw_collect(t_game *game) 21 | { 22 | int x; 23 | int y; 24 | t_clst *lst; 25 | 26 | x = game->player.spr.x; 27 | y = game->player.spr.y; 28 | lst = game->collec.clst; 29 | while (lst) 30 | { 31 | if (!lst->istouch) 32 | { 33 | if (lst->coord.x == x && lst->coord.y == y) 34 | { 35 | lst->istouch = TRUE; 36 | game->player.item++; 37 | } 38 | ft_put_img64(game, game->collec.ball.ptr, 39 | lst->coord.x, lst->coord.y); 40 | } 41 | lst = lst->next; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src_bonus/map_check_ext_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_check_ext_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:18:38 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | int check_ext(char *str, char *ext) 16 | { 17 | int i; 18 | int j; 19 | 20 | if (ext[0] != '.') 21 | exit_err("Invalid function parameter. ext[0] must be 'dot' charter\n"); 22 | i = ft_strlen(str) - ft_strlen(ext); 23 | if (i <= 0 || str[i] != '.') 24 | exit_err("Wrong extension or file path.\n"); 25 | j = 0; 26 | while (str[i + j] != '\0' && ext[j] != '\0') 27 | { 28 | if (str[i + j] == ext[j]) 29 | j++; 30 | else 31 | break ; 32 | } 33 | if (!(str[i + j] == '\0' && ext[j] == '\0')) 34 | exit_err("Wrong extension or file path.\n"); 35 | return (TRUE); 36 | } 37 | -------------------------------------------------------------------------------- /lib/include/get_next_line.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/09 20:24:43 by jisokang #+# #+# */ 9 | /* Updated: 2021/07/17 18:37:46 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_H 14 | # define GET_NEXT_LINE_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include "libft.h" 20 | 21 | # ifndef OPEN_MAX 22 | # define OPEN_MAX 32 23 | # endif 24 | 25 | # ifndef BUFFER_SIZE 26 | # define BUFFER_SIZE 1 27 | # endif 28 | 29 | int get_next_line(int fd, char **line); 30 | char *ft_strjoin_gnl(char *s1, char const *s2); 31 | char *ft_strdup_gnl(const char *s1); 32 | //size_t ft_strlen_gnl(const char *s); 33 | size_t t_strlcpy_gnl(char *dst, const char *src, size_t dstsize); 34 | size_t ft_strlcat_gnl(char *dest, const char *src, size_t dstsize); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/07 15:00:37 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/08 15:24:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | char *ft_strjoin(char const *s1, char const *s2) 16 | { 17 | char *newstr; 18 | size_t s1_len; 19 | size_t s2_len; 20 | 21 | if (s1 == NULL && s2 == NULL) 22 | return (NULL); 23 | else if (s1 == NULL && s2 != NULL) 24 | return (ft_strdup(s2)); 25 | else if (s1 != NULL && s2 == NULL) 26 | return (ft_strdup(s1)); 27 | s1_len = ft_strlen(s1); 28 | s2_len = ft_strlen(s2); 29 | newstr = (char *)malloc(sizeof(char) * (s1_len + s2_len + 1)); 30 | if (newstr == NULL) 31 | return (0); 32 | ft_strlcpy(newstr, s1, s1_len + 1); 33 | ft_strlcat(newstr, s2, s1_len + s2_len + 1); 34 | return (newstr); 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/ft_printf/ft_printf_string.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf_string.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/30 20:22:04 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/21 16:40:26 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/ft_printf.h" 14 | 15 | int ft_print_string(t_info *info, va_list ap) 16 | { 17 | int len; 18 | int printed; 19 | const char *s; 20 | 21 | printed = 0; 22 | s = va_arg(ap, char *); 23 | if (s == NULL) 24 | s = "(null)"; 25 | len = ft_strlen(s); 26 | if (info->precision < len && info->precision > 0) 27 | len = info->precision; 28 | else if (info->precision == 0 || info->dot_only == ENABLE) 29 | len = 0; 30 | if (info->minus == DISABLE) 31 | while (len < (info->width)--) 32 | printed += write(1, " ", 1); 33 | printed += write(1, s, len); 34 | while (len < (info->width)--) 35 | printed += write(1, " ", 1); 36 | return (printed); 37 | } 38 | -------------------------------------------------------------------------------- /src/ft_mlx.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_mlx.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/16 05:47:08 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 20:30:35 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void *ft_xpm_to_img(t_game *game, char *str) 16 | { 17 | char *path; 18 | void *img; 19 | 20 | path = ft_strjoin(ASSET_PATH, str); 21 | img = mlx_xpm_file_to_image(game->mlx, path, 22 | &(game->img64.w), &(game->img64.h)); 23 | free(path); 24 | if (img == NULL) 25 | exit_err("XPM to image fail! " 26 | "please check ASSET_PATH or image file.\n"); 27 | return (img); 28 | } 29 | 30 | void ft_put_img64(t_game *game, void *img_ptr, int x, int y) 31 | { 32 | mlx_put_image_to_window(game->mlx, game->win, 33 | img_ptr, x * TILE_SIZE, y * TILE_SIZE); 34 | } 35 | 36 | void ft_put_img(t_game *game, void *img_ptr, int x, int y) 37 | { 38 | mlx_put_image_to_window(game->mlx, game->win, img_ptr, x, y); 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # so_long 2 | [![jisokang's 42 so_long Score](https://badge42.vercel.app/api/v2/cl3wfqiem000609jsr6tci7fi/project/2193781)](https://github.com/JaeSeoKim/badge42) 3 | ![so long play screen shot](so_long_play_screen_shot.png) 4 | This is a small game project from 42school implemented using MiniLibX. This project is inspired by Game Freak's [Pokemon Firered](https://en.wikipedia.org/wiki/Pokémon_FireRed_and_LeafGreen). 5 | 6 | ## Goals 7 | This project is a very small 2D game. It is built to make you work with textures, sprites. And some very basic gameplay elements. 8 | 9 | ## Getting Started 10 | >🚨 Please check the issue/#1 before start. 11 | 12 | ### Install 13 | ```bash 14 | $ make bonus 15 | ``` 16 | 17 | ### Usage 18 | ```bash 19 | $ ./so_long_bonus [MAP_FILE.ber] 20 | ``` 21 | Only map files with extension `.ber` are available. Map file examples are available in the `map/` directory. 22 | 23 | ```bash 24 | $ ./so_long_bonus map/map_sl.ber 25 | ``` 26 | Run the code to use all the features of the game. 27 | 28 | ### HOW TO PLAY 29 | The player’s goal is to collect all collectibles present on the map then escape with minimal movement. 30 | 31 | |KEYBOARD|ACTION| 32 | |---|---| 33 | |`W`, `↑`|Move up| 34 | |`S`, `↓`|Move down| 35 | |`A`, `←`|Move left| 36 | |`D`, `→`|Move right| 37 | |`return ⏎`| Start game| 38 | |`R`|Retry game| 39 | |`ESC ⎋`|Close the game window| 40 | 41 | ## Reference 42 | * [42Paris/minilibx-linux](https://github.com/42Paris/minilibx-linux) 43 | * [42Docs/minilibx](https://harm-smits.github.io/42docs/libs/minilibx) 44 | * [taelee42/mlx_example](https://github.com/taelee42/mlx_example) 45 | * [pret/Disassembly of Pokémon FireRed and LeafGreen](https://github.com/pret/pokefirered) 46 | -------------------------------------------------------------------------------- /src_bonus/ft_mlx_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_mlx_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/16 05:47:08 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void *ft_xpm_to_img(t_game *game, char *str) 16 | { 17 | char *path; 18 | void *img; 19 | 20 | path = ft_strjoin(ASSET_PATH, str); 21 | img = mlx_xpm_file_to_image(game->mlx, path, 22 | &(game->img64.w), &(game->img64.h)); 23 | free(path); 24 | if (img == NULL) 25 | exit_err("XPM to image fail! " 26 | "please check ASSET_PATH or image file.\n"); 27 | return (img); 28 | } 29 | 30 | void ft_put_img64(t_game *game, void *img_ptr, int x, int y) 31 | { 32 | mlx_put_image_to_window(game->mlx, game->win, 33 | img_ptr, x * TILE_SIZE, y * TILE_SIZE); 34 | } 35 | 36 | void ft_put_img(t_game *game, void *img_ptr, int x, int y) 37 | { 38 | mlx_put_image_to_window(game->mlx, game->win, img_ptr, x, y); 39 | } 40 | -------------------------------------------------------------------------------- /src/map_draw.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_draw.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/31 07:01:55 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | static void _draw_map(t_game *game, int i, int j) 16 | { 17 | if (game->maps.coord[i][j] == '1') 18 | ft_put_img64(game, game->tile.t1.ptr, j, i); 19 | else if (game->maps.coord[i][j] == 'E') 20 | { 21 | if (game->flag.collect_all) 22 | ft_put_img64(game, game->tile.tl.ptr, j, i); 23 | else 24 | { 25 | ft_put_img64(game, game->tile.t0.ptr, j, i); 26 | ft_put_img64(game, game->tile.ts.ptr, j, i); 27 | } 28 | } 29 | else 30 | ft_put_img64(game, game->tile.t0.ptr, j, i); 31 | } 32 | 33 | void draw_map(t_game *game) 34 | { 35 | int i; 36 | int j; 37 | 38 | i = 0; 39 | while (i < game->maps.rows) 40 | { 41 | j = 0; 42 | while (j < game->maps.cols) 43 | { 44 | _draw_map(game, i, j); 45 | j++; 46 | } 47 | i++; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src_bonus/map_draw_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_draw_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/31 07:01:55 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | static void _draw_map(t_game *game, int i, int j) 16 | { 17 | if (game->maps.coord[i][j] == '1') 18 | ft_put_img64(game, game->tile.t1.ptr, j, i); 19 | else if (game->maps.coord[i][j] == 'E') 20 | { 21 | if (game->flag.collect_all) 22 | ft_put_img64(game, game->tile.tl.ptr, j, i); 23 | else 24 | { 25 | ft_put_img64(game, game->tile.t0.ptr, j, i); 26 | ft_put_img64(game, game->tile.ts.ptr, j, i); 27 | } 28 | } 29 | else 30 | ft_put_img64(game, game->tile.t0.ptr, j, i); 31 | } 32 | 33 | void draw_map(t_game *game) 34 | { 35 | int i; 36 | int j; 37 | 38 | i = 0; 39 | while (i < game->maps.rows) 40 | { 41 | j = 0; 42 | while (j < game->maps.cols) 43 | { 44 | _draw_map(game, i, j); 45 | j++; 46 | } 47 | i++; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/src/libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/11/05 17:17:31 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | int ft_isspace(char c) 16 | { 17 | if (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' ') 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | 23 | int ft_atoi(const char *str) 24 | { 25 | long sign; 26 | long result; 27 | size_t i; 28 | 29 | sign = 1; 30 | result = 0; 31 | i = 0; 32 | while (str[i] != '\0' && ft_isspace(str[i]) == 1) 33 | i++; 34 | if (str[i] == '-') 35 | sign = -1; 36 | if (str[i] == '+' || str[i] == '-') 37 | i++; 38 | while (str[i] != '\0' && str[i] >= '0' && str[i] <= '9') 39 | { 40 | result = result * 10 + (str[i] - '0'); 41 | if (result > 2147483647 && sign == 1) 42 | return (-1); 43 | if (result > 2147483648 && sign == -1) 44 | return (0); 45 | i++; 46 | } 47 | return (sign * result); 48 | } 49 | -------------------------------------------------------------------------------- /src/key.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:34:08 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | int deal_key(int key_code, t_game *game) 16 | { 17 | if (key_code == KEY_ESC) 18 | exit(0); 19 | else if (key_code == KEY_RETURN && game->flag.game_scene == GAME_START) 20 | game->flag.game_scene = GAME_PLAYING; 21 | else if (key_code == KEY_R && game->flag.game_scene != GAME_START) 22 | reset_game(game); 23 | else if (!game->flag.held_keys && game->flag.game_scene == GAME_PLAYING) 24 | { 25 | if (key_code == KEY_W || key_code == KEY_UP) 26 | move_north(game, &(game->player.spr)); 27 | else if (key_code == KEY_A || key_code == KEY_LEFT) 28 | move_west(game, &(game->player.spr)); 29 | else if (key_code == KEY_S || key_code == KEY_DOWN) 30 | move_south(game, &(game->player.spr)); 31 | else if (key_code == KEY_D || key_code == KEY_RIGHT) 32 | move_east(game, &(game->player.spr)); 33 | } 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/09 05:14:54 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | long int ft_abs(long int nbr) 16 | { 17 | if (nbr < 0) 18 | return (-nbr); 19 | else 20 | return (nbr); 21 | } 22 | 23 | int ft_len(long int nbr) 24 | { 25 | int len; 26 | 27 | if (nbr <= 0) 28 | len = 1; 29 | else 30 | len = 0; 31 | while (nbr != 0) 32 | { 33 | nbr = nbr / 10; 34 | len++; 35 | } 36 | return (len); 37 | } 38 | 39 | char *ft_itoa(int n) 40 | { 41 | int len; 42 | int sign; 43 | char *str; 44 | 45 | if (n < 0) 46 | sign = -1; 47 | else 48 | sign = 1; 49 | len = ft_len(n); 50 | str = (char *)malloc(sizeof(char) * (len + 1)); 51 | if (str == NULL) 52 | return (0); 53 | str[len] = '\0'; 54 | len--; 55 | while (len >= 0) 56 | { 57 | str[len] = '0' + ft_abs(n % 10); 58 | n = ft_abs(n / 10); 59 | len--; 60 | } 61 | if (sign == -1) 62 | str[0] = '-'; 63 | return (str); 64 | } 65 | -------------------------------------------------------------------------------- /src_bonus/key_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* key_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:34:08 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | int deal_key(int key_code, t_game *game) 16 | { 17 | if (key_code == KEY_ESC) 18 | exit(0); 19 | else if (key_code == KEY_RETURN && game->flag.game_scene == GAME_START) 20 | game->flag.game_scene = GAME_PLAYING; 21 | else if (key_code == KEY_R && game->flag.game_scene != GAME_START) 22 | reset_game(game); 23 | else if (!game->flag.held_keys && game->flag.game_scene == GAME_PLAYING) 24 | { 25 | if (key_code == KEY_W || key_code == KEY_UP) 26 | move_north(game, &(game->player.spr)); 27 | else if (key_code == KEY_A || key_code == KEY_LEFT) 28 | move_west(game, &(game->player.spr)); 29 | else if (key_code == KEY_S || key_code == KEY_DOWN) 30 | move_south(game, &(game->player.spr)); 31 | else if (key_code == KEY_D || key_code == KEY_RIGHT) 32 | move_east(game, &(game->player.spr)); 33 | } 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /minilibx_mms_20210621/man/man3/mlx_new_window.3: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Managing windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I void * 8 | .fi 9 | .B mlx_new_window 10 | ( 11 | .I void *mlx_ptr, int size_x, int size_y, char *title 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_clear_window 18 | ( 19 | .I void *mlx_ptr, void *win_ptr 20 | ); 21 | 22 | .nf 23 | .I int 24 | .fi 25 | .B mlx_destroy_window 26 | ( 27 | .I void *mlx_ptr, void *win_ptr 28 | ); 29 | 30 | 31 | .SH DESCRIPTION 32 | The 33 | .B mlx_new_window 34 | () function creates a new window on the screen, using the 35 | .I size_x 36 | and 37 | .I size_y 38 | parameters to determine its size, and 39 | .I title 40 | as the text that should be displayed in the window's title bar. 41 | The 42 | .I mlx_ptr 43 | parameter is the connection identifier returned by 44 | .B mlx_init 45 | () (see the 46 | .B mlx 47 | man page). 48 | .B mlx_new_window 49 | () returns a 50 | .I void * 51 | window identifier that can be used by other MiniLibX calls. 52 | Note that the MiniLibX 53 | can handle an arbitrary number of separate windows. 54 | 55 | .B mlx_clear_window 56 | () and 57 | .B mlx_destroy_window 58 | () respectively clear (in black) and destroy the given window. They both have 59 | the same parameters: 60 | .I mlx_ptr 61 | is the screen connection identifier, and 62 | .I win_ptr 63 | is a window identifier. 64 | 65 | .SH RETURN VALUES 66 | If 67 | .B mlx_new_window() 68 | fails to create a new window (for wathever reason), it will return NULL, 69 | otherwise a non-null pointer is returned as a window identifier. 70 | .B mlx_clear_window 71 | and 72 | .B mlx_destroy_window 73 | right now return nothing. 74 | 75 | .SH SEE ALSO 76 | mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 77 | 78 | .SH AUTHOR 79 | Copyright ol@ - 2002-2019 - Olivier Crouzet 80 | -------------------------------------------------------------------------------- /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/src/ft_printf/ft_printf_char.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf_char.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/30 17:42:42 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/21 16:40:26 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/ft_printf.h" 14 | 15 | int ft_print_char(t_info *info, va_list ap) 16 | { 17 | int printed; 18 | char c; 19 | 20 | printed = 0; 21 | if (info->minus == DISABLE) 22 | { 23 | while (--(info->width) > 0) 24 | printed += write(1, " ", 1); 25 | } 26 | c = (unsigned char)va_arg(ap, int); 27 | printed += write(1, &c, 1); 28 | while (--(info->width) > 0) 29 | printed += write(1, " ", 1); 30 | return (printed); 31 | } 32 | 33 | int ft_print_percent(t_info *info) 34 | { 35 | int printed; 36 | 37 | printed = 0; 38 | if (info->minus == DISABLE && info->zero == DISABLE) 39 | { 40 | while (--(info->width) > 0) 41 | printed += write(1, " ", 1); 42 | } 43 | if (info->minus == DISABLE && info->zero == ENABLE) 44 | { 45 | while (--(info->width) > 0) 46 | printed += write(1, "0", 1); 47 | } 48 | printed += write(1, "%", 1); 49 | while (--(info->width) > 0) 50 | printed += write(1, " ", 1); 51 | return (printed); 52 | } 53 | -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* config.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/10 14:18:05 by jisokang #+# #+# */ 9 | /* Updated: 2021/09/30 01:15:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CONFIG_H 14 | # define CONFIG_H 15 | 16 | /*------------------------------ 17 | * DEBUG OPTION 18 | *------------------------------*/ 19 | /* 1 : Debug mode ON 20 | * 0 : Debug mode OFF */ 21 | # define DEBUG 1 22 | 23 | /*------------------------------ 24 | * GAME MODE OPTION 25 | *------------------------------*/ 26 | /* 1 : BONUS MODE 27 | * 0 : MANDATORY MODE */ 28 | # define GAME_MODE 0 29 | 30 | /*------------------------------ 31 | * ASSET PATH 32 | *------------------------------*/ 33 | # define ASSET_PATH "./asset/" 34 | 35 | /*------------------------------ 36 | * COMPO OPTION 37 | *------------------------------*/ 38 | # define COMPO_P_MAX 1 39 | # define COMPO_C_MAX 1 40 | # define COMPO_E_MAX 1 41 | # define COMPO_R_MAX 0 42 | 43 | /*------------------------------ 44 | * PLAYER OPTION 45 | *------------------------------*/ 46 | /* Player Speed 47 | * Default : 4 48 | * Min : 1 49 | * Max : 64 50 | * Enter only multiples of 2. */ 51 | # define PLAYER_SPEED 4 52 | # define ENEMY_SPEED 8 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/map.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/07 18:14:15 by jisokang #+# #+# */ 9 | /* Updated: 2021/09/30 01:24:26 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MAP_H 14 | # define MAP_H 15 | 16 | /** 17 | * [Component] 18 | * The component is an element that contains map file. 19 | * 'p' : player 20 | * 'e' : exit 21 | * 'c' : collectible item 22 | * 'r' : Team Rocket (enemy) 23 | * */ 24 | typedef struct s_compo 25 | { 26 | int p; 27 | int e; 28 | int c; 29 | int r; 30 | } t_compo; 31 | 32 | typedef struct s_map 33 | { 34 | int rows; 35 | int cols; 36 | char **coord; 37 | char *file; 38 | t_compo cnt; 39 | } t_map; 40 | 41 | # define MAP_EXT ".ber" 42 | 43 | # define TILE_SIZE 64 44 | 45 | typedef struct s_game t_game; 46 | 47 | int check_ext(char *str, char *ext); 48 | int check_map_compo(char c); 49 | int is_map_rectangle(t_game *game, int len2); 50 | int is_map_walled(t_map maps); 51 | void count_max_rows_cols(t_game *game, int fd); 52 | void map_malloc(t_game *game, int fd); 53 | int open_file(char *filename); 54 | void map_load(t_game *game, char *filename); 55 | void get_compo_coord(t_game *game); 56 | void file_read(t_game *game, char *filename); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/10 23:09:34 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:18:10 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | int close_game(t_game *game) 16 | { 17 | mlx_destroy_window(game->mlx, game->win); 18 | exit(0); 19 | } 20 | 21 | void frame_cunt(t_game *game) 22 | { 23 | game->fps++; 24 | if (game->fps >= 600) 25 | game->fps = 0; 26 | } 27 | 28 | int main_loop(t_game *game) 29 | { 30 | if (game->flag.game_scene != GAME_PLAYING) 31 | draw_scene_event(game); 32 | else 33 | { 34 | draw_map(game); 35 | draw_collect(game); 36 | event_checker(game); 37 | enemy_script(game); 38 | draw_sprites(game); 39 | draw_step_count(game); 40 | } 41 | frame_cunt(game); 42 | return (0); 43 | } 44 | 45 | int main(int argc, char **argv) 46 | { 47 | t_game game; 48 | 49 | if (argc != 2) 50 | exit_err("Usage: ./so_long [MAP_FILE.ber]\n"); 51 | init_collec(&game); 52 | file_read(&game, argv[1]); 53 | init_game(&game); 54 | mlx_hook(game.win, X_EVENT_KEY_PRESS, 0, &deal_key, &game); 55 | mlx_hook(game.win, X_EVENT_KEY_EXIT, 0, &close_game, &game); 56 | mlx_loop_hook(game.mlx, &main_loop, &game); 57 | mlx_loop(game.mlx); 58 | } 59 | -------------------------------------------------------------------------------- /src/move_dir.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_dir.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/16 05:54:32 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void move_dir(t_game *game, t_spr *sprite, int dir) 16 | { 17 | sprite->x0 = sprite->x; 18 | sprite->y0 = sprite->y; 19 | sprite->dir = dir; 20 | if (sprite->frame > sprite->frame_max) 21 | sprite->frame = 0; 22 | sprite->frame++; 23 | if (!is_collision(game, sprite, dir)) 24 | { 25 | sprite->move = TRUE; 26 | sprite->x += game->dir2coord[dir].x; 27 | sprite->y += game->dir2coord[dir].y; 28 | sprite->step++; 29 | if (sprite == &(game->player.spr)) 30 | game->flag.step_cnt = TRUE; 31 | } 32 | else 33 | sprite->move = FALSE; 34 | game->flag.player_walk = TRUE; 35 | } 36 | 37 | void move_north(t_game *game, t_spr *sprite) 38 | { 39 | move_dir(game, sprite, DIR_NORTH); 40 | } 41 | 42 | void move_south(t_game *game, t_spr *sprite) 43 | { 44 | move_dir(game, sprite, DIR_SOUTH); 45 | } 46 | 47 | void move_west(t_game *game, t_spr *sprite) 48 | { 49 | move_dir(game, sprite, DIR_WEST); 50 | } 51 | 52 | void move_east(t_game *game, t_spr *sprite) 53 | { 54 | move_dir(game, sprite, DIR_EAST); 55 | } 56 | -------------------------------------------------------------------------------- /src/util_lst.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* util_lst.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/26 07:08:11 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | t_clst *clst_new(int x, int y) 16 | { 17 | t_clst *new; 18 | 19 | new = (t_clst *)malloc(sizeof(t_clst)); 20 | if (new == NULL) 21 | return (NULL); 22 | new->coord.x = x; 23 | new->coord.y = y; 24 | new->istouch = FALSE; 25 | new->next = NULL; 26 | return (new); 27 | } 28 | 29 | t_clst *clst_last(t_clst *lst) 30 | { 31 | t_clst *curr; 32 | 33 | curr = lst; 34 | if (lst == NULL) 35 | return (NULL); 36 | while (curr->next != NULL) 37 | curr = curr->next; 38 | return (curr); 39 | } 40 | 41 | void clst_add_back(t_clst **lst, t_clst *new) 42 | { 43 | t_clst *last; 44 | 45 | if (new == NULL) 46 | return ; 47 | if (*lst == NULL) 48 | { 49 | *lst = new; 50 | return ; 51 | } 52 | last = clst_last(*lst); 53 | new->next = last->next; 54 | last->next = new; 55 | } 56 | 57 | void clst_clear(t_clst *head) 58 | { 59 | t_clst *curr; 60 | t_clst *next; 61 | 62 | curr = head; 63 | while (curr != NULL) 64 | { 65 | next = curr->next; 66 | free(curr); 67 | curr = next; 68 | } 69 | head = NULL; 70 | } 71 | -------------------------------------------------------------------------------- /include_bonus/config_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* config_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/10 14:18:05 by jisokang #+# #+# */ 9 | /* Updated: 2021/09/30 01:16:32 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CONFIG_BONUS_H 14 | # define CONFIG_BONUS_H 15 | 16 | /*------------------------------ 17 | * DEBUG OPTION 18 | *------------------------------*/ 19 | /* 1 : Debug mode ON 20 | * 0 : Debug mode OFF */ 21 | # define DEBUG 0 22 | 23 | /*------------------------------ 24 | * GAME MODE OPTION 25 | *------------------------------*/ 26 | /* 1 : BONUS MODE 27 | * 0 : MANDATORY MODE */ 28 | # define GAME_MODE 1 29 | 30 | /*------------------------------ 31 | * ASSET PATH 32 | *------------------------------*/ 33 | # define ASSET_PATH "./asset/" 34 | 35 | /*------------------------------ 36 | * COMPO OPTION 37 | *------------------------------*/ 38 | # define COMPO_P_MAX 1 39 | # define COMPO_C_MAX 1 40 | # define COMPO_E_MAX 1 41 | # define COMPO_R_MAX 1 42 | 43 | /*------------------------------ 44 | * PLAYER OPTION 45 | *------------------------------*/ 46 | /* Player Speed 47 | * Default : 4 48 | * Min : 1 49 | * Max : 64 50 | * Enter only multiples of 2. */ 51 | # define PLAYER_SPEED 4 52 | # define ENEMY_SPEED 8 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include_bonus/map_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/07 18:14:15 by jisokang #+# #+# */ 9 | /* Updated: 2021/09/30 01:26:04 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MAP_BONUS_H 14 | # define MAP_BONUS_H 15 | 16 | /** 17 | * [Component] 18 | * The component is an element that contains map file. 19 | * 'p' : player 20 | * 'e' : exit 21 | * 'c' : collectible item 22 | * 'r' : Team Rocket (enemy) 23 | * */ 24 | typedef struct s_compo 25 | { 26 | int p; 27 | int e; 28 | int c; 29 | int r; 30 | } t_compo; 31 | 32 | typedef struct s_map 33 | { 34 | int rows; 35 | int cols; 36 | char **coord; 37 | char *file; 38 | t_compo cnt; 39 | } t_map; 40 | 41 | # define MAP_EXT ".ber" 42 | 43 | # define TILE_SIZE 64 44 | 45 | typedef struct s_game t_game; 46 | 47 | int check_ext(char *str, char *ext); 48 | int check_map_compo(char c); 49 | int is_map_rectangle(t_game *game, int len2); 50 | int is_map_walled(t_map maps); 51 | void count_max_rows_cols(t_game *game, int fd); 52 | void map_malloc(t_game *game, int fd); 53 | int open_file(char *filename); 54 | void map_load(t_game *game, char *filename); 55 | void get_compo_coord(t_game *game); 56 | void file_read(t_game *game, char *filename); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src_bonus/main_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/10 23:09:34 by jisokang #+# #+# */ 9 | /* Updated: 2021/11/01 23:36:27 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | int close_game(t_game *game) 16 | { 17 | mlx_destroy_window(game->mlx, game->win); 18 | exit(0); 19 | } 20 | 21 | void frame_cunt(t_game *game) 22 | { 23 | game->fps++; 24 | if (game->fps >= 600) 25 | game->fps = 0; 26 | } 27 | 28 | int main_loop(t_game *game) 29 | { 30 | if (game->flag.game_scene != GAME_PLAYING) 31 | draw_scene_event(game); 32 | else 33 | { 34 | draw_map(game); 35 | draw_collect(game); 36 | event_checker(game); 37 | enemy_script(game); 38 | draw_sprites(game); 39 | draw_step_count(game); 40 | } 41 | frame_cunt(game); 42 | return (0); 43 | } 44 | 45 | int main(int argc, char **argv) 46 | { 47 | t_game game; 48 | 49 | if (argc != 2) 50 | exit_err("Usage: ./so_long [MAP_FILE.ber]\n"); 51 | init_collec(&game); 52 | file_read(&game, argv[1]); 53 | init_game(&game); 54 | mlx_hook(game.win, X_EVENT_KEY_PRESS, 0, &deal_key, &game); 55 | mlx_hook(game.win, X_EVENT_KEY_EXIT, 0, &close_game, &game); 56 | mlx_loop_hook(game.mlx, &main_loop, &game); 57 | mlx_loop(game.mlx); 58 | } 59 | -------------------------------------------------------------------------------- /src_bonus/move_dir_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* move_dir_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/16 05:54:32 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void move_dir(t_game *game, t_spr *sprite, int dir) 16 | { 17 | sprite->x0 = sprite->x; 18 | sprite->y0 = sprite->y; 19 | sprite->dir = dir; 20 | if (sprite->frame > sprite->frame_max) 21 | sprite->frame = 0; 22 | sprite->frame++; 23 | if (!is_collision(game, sprite, dir)) 24 | { 25 | sprite->move = TRUE; 26 | sprite->x += game->dir2coord[dir].x; 27 | sprite->y += game->dir2coord[dir].y; 28 | sprite->step++; 29 | if (sprite == &(game->player.spr)) 30 | game->flag.step_cnt = TRUE; 31 | } 32 | else 33 | sprite->move = FALSE; 34 | game->flag.player_walk = TRUE; 35 | } 36 | 37 | void move_north(t_game *game, t_spr *sprite) 38 | { 39 | move_dir(game, sprite, DIR_NORTH); 40 | } 41 | 42 | void move_south(t_game *game, t_spr *sprite) 43 | { 44 | move_dir(game, sprite, DIR_SOUTH); 45 | } 46 | 47 | void move_west(t_game *game, t_spr *sprite) 48 | { 49 | move_dir(game, sprite, DIR_WEST); 50 | } 51 | 52 | void move_east(t_game *game, t_spr *sprite) 53 | { 54 | move_dir(game, sprite, DIR_EAST); 55 | } 56 | -------------------------------------------------------------------------------- /src_bonus/util_lst_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* util_lst_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/26 07:08:11 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | t_clst *clst_new(int x, int y) 16 | { 17 | t_clst *new; 18 | 19 | new = (t_clst *)malloc(sizeof(t_clst)); 20 | if (new == NULL) 21 | return (NULL); 22 | new->coord.x = x; 23 | new->coord.y = y; 24 | new->istouch = FALSE; 25 | new->next = NULL; 26 | return (new); 27 | } 28 | 29 | t_clst *clst_last(t_clst *lst) 30 | { 31 | t_clst *curr; 32 | 33 | curr = lst; 34 | if (lst == NULL) 35 | return (NULL); 36 | while (curr->next != NULL) 37 | curr = curr->next; 38 | return (curr); 39 | } 40 | 41 | void clst_add_back(t_clst **lst, t_clst *new) 42 | { 43 | t_clst *last; 44 | 45 | if (new == NULL) 46 | return ; 47 | if (*lst == NULL) 48 | { 49 | *lst = new; 50 | return ; 51 | } 52 | last = clst_last(*lst); 53 | new->next = last->next; 54 | last->next = new; 55 | } 56 | 57 | void clst_clear(t_clst *head) 58 | { 59 | t_clst *curr; 60 | t_clst *next; 61 | 62 | curr = head; 63 | while (curr != NULL) 64 | { 65 | next = curr->next; 66 | free(curr); 67 | curr = next; 68 | } 69 | head = NULL; 70 | } 71 | -------------------------------------------------------------------------------- /lib/src/ft_printf/ft_printf.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/08 16:37:49 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 20:25:40 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/ft_printf.h" 14 | 15 | void init_struct(t_info *info) 16 | { 17 | info->minus = DISABLE; 18 | info->zero = DISABLE; 19 | info->dot_only = DISABLE; 20 | info->locass = DISABLE; 21 | info->address = DISABLE; 22 | info->width = -1; 23 | info->precision = -1; 24 | info->num_base = 10; 25 | info->num_sign = 0; 26 | } 27 | 28 | int ft_parse_symbols(const char *format, va_list ap) 29 | { 30 | t_info info; 31 | int printed; 32 | 33 | printed = 0; 34 | while (*format != 0) 35 | { 36 | init_struct(&info); 37 | if (*format == '%') 38 | { 39 | format++; 40 | ft_parse_flag(&format, &info); 41 | ft_parse_width(&format, &info, ap); 42 | ft_parse_precision(&format, &info, ap); 43 | printed += ft_parse_type(&info, ap, *format); 44 | } 45 | else 46 | printed += write(1, format, 1); 47 | format++; 48 | } 49 | return (printed); 50 | } 51 | 52 | int ft_printf(const char *format, ...) 53 | { 54 | va_list ap; 55 | int printed; 56 | 57 | va_start(ap, format); 58 | printed = ft_parse_symbols(format, ap); 59 | va_end(ap); 60 | return (printed); 61 | } 62 | -------------------------------------------------------------------------------- /src/map_parse.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_parse.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:17:43 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 14:35:33 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | /** 16 | * check map file components 17 | * 0 : an empty space. 18 | * 1 : a wall. 19 | * C : a Collectible. 20 | * E : map Exit. 21 | * P : the Player’s starting position. 22 | * R : team Rocket. enemy patrol. 23 | */ 24 | int check_map_compo(char c) 25 | { 26 | if (c == '0' || c == '1' || c == 'C' 27 | || c == 'E' || c == 'P' || c == 'R') 28 | return (TRUE); 29 | return (FALSE); 30 | } 31 | 32 | int is_map_rectangle(t_game *game, int len2) 33 | { 34 | int len1; 35 | 36 | len1 = game->maps.cols; 37 | if (len1 != len2) 38 | return (FALSE); 39 | return (TRUE); 40 | } 41 | 42 | int is_map_walled(t_map maps) 43 | { 44 | int max_col; 45 | int max_row; 46 | int i; 47 | 48 | i = 0; 49 | max_col = maps.cols - 1; 50 | max_row = maps.rows - 1; 51 | while (i < maps.rows) 52 | { 53 | if (maps.coord[i][0] != '1' || maps.coord[i][max_col] != '1') 54 | return (FALSE); 55 | i++; 56 | } 57 | i = 0; 58 | while (i < maps.cols) 59 | { 60 | if (maps.coord[0][i] != '1' || maps.coord[max_row][i] != '1') 61 | return (FALSE); 62 | i++; 63 | } 64 | return (TRUE); 65 | } 66 | -------------------------------------------------------------------------------- /src/enemy_script.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* enemy_script.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 14:40:23 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void init_enemy(t_game *game) 16 | { 17 | game->enemy.dir = DIR_SOUTH; 18 | game->enemy.i = 0; 19 | game->enemy.move = TRUE; 20 | } 21 | 22 | void enemy_find_player(t_game *game) 23 | { 24 | int x; 25 | int y; 26 | int i; 27 | int dir; 28 | 29 | i = 0; 30 | dir = game->enemy.dir; 31 | while (!game->flag.enemy_walk) 32 | { 33 | x = game->enemy.x + game->dir2coord[dir].x * i; 34 | y = game->enemy.y + game->dir2coord[dir].y * i; 35 | if (game->maps.coord[y][x] == '1') 36 | return ; 37 | if (game->player.spr.x == x && game->player.spr.y == y) 38 | { 39 | game->flag.held_keys = TRUE; 40 | game->flag.enemy_walk = TRUE; 41 | game->enemy.x0 = game->enemy.x; 42 | game->enemy.y0 = game->enemy.y; 43 | game->enemy.x = x - game->dir2coord[dir].x; 44 | game->enemy.y = y - game->dir2coord[dir].y; 45 | return ; 46 | } 47 | i++; 48 | } 49 | } 50 | 51 | void enemy_script(t_game *game) 52 | { 53 | if (game->maps.cnt.r > 0) 54 | { 55 | if (game->fps % 100 == 0 && !game->flag.enemy_walk) 56 | spin_clockwise(&(game->enemy)); 57 | enemy_find_player(game); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/src/libft/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/08 14:09:23 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | size_t ft_getstart(char const *s1, char const *set) 16 | { 17 | size_t len; 18 | size_t i; 19 | 20 | len = ft_strlen(s1); 21 | i = 0; 22 | while (i < len) 23 | { 24 | if (ft_strchr(set, s1[i]) == 0) 25 | break ; 26 | i++; 27 | } 28 | return (i); 29 | } 30 | 31 | size_t ft_getend(char const *s1, char const *set) 32 | { 33 | size_t len; 34 | size_t i; 35 | 36 | len = ft_strlen(s1); 37 | i = 0; 38 | while (i < len) 39 | { 40 | if (ft_strchr(set, s1[len - i - 1]) == 0) 41 | break ; 42 | i++; 43 | } 44 | return (len - i); 45 | } 46 | 47 | char *ft_strtrim(char const *s1, char const *set) 48 | { 49 | char *trim_str; 50 | size_t start; 51 | size_t end; 52 | 53 | if (s1 == NULL) 54 | return (NULL); 55 | if (set == NULL) 56 | return (ft_strdup(s1)); 57 | start = ft_getstart(s1, set); 58 | end = ft_getend(s1, set); 59 | if (start >= end) 60 | return (ft_strdup("")); 61 | trim_str = (char *)malloc(sizeof(char) * (end - start + 1)); 62 | if (trim_str == NULL) 63 | return (NULL); 64 | ft_strlcpy(trim_str, s1 + start, end - start + 1); 65 | return (trim_str); 66 | } 67 | -------------------------------------------------------------------------------- /src_bonus/map_parse_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_parse_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 04:17:43 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | /** 16 | * check map file components 17 | * 0 : an empty space. 18 | * 1 : a wall. 19 | * C : a Collectible. 20 | * E : map Exit. 21 | * P : the Player’s starting position. 22 | * R : team Rocket. enemy patrol. 23 | */ 24 | int check_map_compo(char c) 25 | { 26 | if (c == '0' || c == '1' || c == 'C' 27 | || c == 'E' || c == 'P' || c == 'R') 28 | return (TRUE); 29 | return (FALSE); 30 | } 31 | 32 | int is_map_rectangle(t_game *game, int len2) 33 | { 34 | int len1; 35 | 36 | len1 = game->maps.cols; 37 | if (len1 != len2) 38 | return (FALSE); 39 | return (TRUE); 40 | } 41 | 42 | int is_map_walled(t_map maps) 43 | { 44 | int max_col; 45 | int max_row; 46 | int i; 47 | 48 | i = 0; 49 | max_col = maps.cols - 1; 50 | max_row = maps.rows - 1; 51 | while (i < maps.rows) 52 | { 53 | if (maps.coord[i][0] != '1' || maps.coord[i][max_col] != '1') 54 | return (FALSE); 55 | i++; 56 | } 57 | i = 0; 58 | while (i < maps.cols) 59 | { 60 | if (maps.coord[0][i] != '1' || maps.coord[max_row][i] != '1') 61 | return (FALSE); 62 | i++; 63 | } 64 | return (TRUE); 65 | } 66 | -------------------------------------------------------------------------------- /src_bonus/enemy_script_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* enemy_script_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 14:40:23 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void init_enemy(t_game *game) 16 | { 17 | game->enemy.dir = DIR_SOUTH; 18 | game->enemy.i = 0; 19 | game->enemy.move = TRUE; 20 | } 21 | 22 | void enemy_find_player(t_game *game) 23 | { 24 | int x; 25 | int y; 26 | int i; 27 | int dir; 28 | 29 | i = 0; 30 | dir = game->enemy.dir; 31 | while (!game->flag.enemy_walk) 32 | { 33 | x = game->enemy.x + game->dir2coord[dir].x * i; 34 | y = game->enemy.y + game->dir2coord[dir].y * i; 35 | if (game->maps.coord[y][x] == '1') 36 | return ; 37 | if (game->player.spr.x == x && game->player.spr.y == y) 38 | { 39 | game->flag.held_keys = TRUE; 40 | game->flag.enemy_walk = TRUE; 41 | game->enemy.x0 = game->enemy.x; 42 | game->enemy.y0 = game->enemy.y; 43 | game->enemy.x = x - game->dir2coord[dir].x; 44 | game->enemy.y = y - game->dir2coord[dir].y; 45 | return ; 46 | } 47 | i++; 48 | } 49 | } 50 | 51 | void enemy_script(t_game *game) 52 | { 53 | if (game->maps.cnt.r > 0) 54 | { 55 | if (game->fps % 100 == 0 && !game->flag.enemy_walk) 56 | spin_clockwise(&(game->enemy)); 57 | enemy_find_player(game); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/enemy_draw.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* enemy_draw.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/05 11:01:18 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | static t_img *get_enemy_sprimg(t_game *game, int dir) 16 | { 17 | t_img *spr; 18 | 19 | spr = &(game->enemy.imgx[dir][0]); 20 | return (spr); 21 | } 22 | 23 | void draw_enemy_walk(t_game *game, t_spr *enemy, t_img *sprite, int dir) 24 | { 25 | int x; 26 | int y; 27 | 28 | game->flag.held_keys = TRUE; 29 | x = (enemy->x0 * TILE_SIZE) 30 | + (game->dir2coord[dir].x * enemy->i); 31 | y = ((enemy->y0 - 1) * TILE_SIZE) 32 | + (game->dir2coord[dir].y * enemy->i); 33 | ft_put_img(game, sprite->ptr, x, y); 34 | enemy->i += ENEMY_SPEED; 35 | if (enemy->x * TILE_SIZE == x && (enemy->y - 1) * TILE_SIZE == y) 36 | { 37 | enemy->i = 0; 38 | game->flag.held_keys = FALSE; 39 | game->flag.enemy_walk = FALSE; 40 | game->flag.game_scene = GAME_OVER; 41 | } 42 | } 43 | 44 | void draw_enemy(t_game *game) 45 | { 46 | int dir; 47 | t_spr *enemy; 48 | t_img *sprite; 49 | 50 | dir = game->enemy.dir; 51 | enemy = &(game->enemy); 52 | sprite = get_enemy_sprimg(game, dir); 53 | if (game->flag.enemy_walk && !game->flag.player_walk) 54 | draw_enemy_walk(game, enemy, sprite, dir); 55 | else 56 | ft_put_img64(game, sprite->ptr, enemy->x0, enemy->y0 - 1); 57 | } 58 | -------------------------------------------------------------------------------- /lib/src/ft_printf/ft_printf_num.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf_num.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/31 14:24:19 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/21 16:40:26 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/ft_printf.h" 14 | 15 | int print_di(t_info *info, va_list ap) 16 | { 17 | int printed; 18 | long long num; 19 | 20 | info->num_base = 10; 21 | num = va_arg(ap, int); 22 | if (num < 0) 23 | { 24 | info->num_sign = -1; 25 | num = -num; 26 | (info->width)--; 27 | } 28 | printed = print_num(info, num); 29 | return (printed); 30 | } 31 | 32 | int print_u(t_info *info, va_list ap) 33 | { 34 | int printed; 35 | long long num; 36 | 37 | info->num_base = 10; 38 | num = va_arg(ap, unsigned int); 39 | printed = print_num(info, num); 40 | return (printed); 41 | } 42 | 43 | int print_xx(t_info *info, va_list ap, char type) 44 | { 45 | int printed; 46 | long long num; 47 | 48 | if (type == 'x') 49 | info->locass = SMALL; 50 | info->num_base = 16; 51 | num = va_arg(ap, unsigned int); 52 | printed = print_num(info, num); 53 | return (printed); 54 | } 55 | 56 | int print_p(t_info *info, va_list ap) 57 | { 58 | int printed; 59 | long long num; 60 | 61 | info->address = ENABLE; 62 | info->locass = SMALL; 63 | info->width -= 2; 64 | info->num_base = 16; 65 | num = (unsigned long)va_arg(ap, void *); 66 | printed = print_num(info, num); 67 | return (printed); 68 | } 69 | -------------------------------------------------------------------------------- /src_bonus/enemy_draw_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* enemy_draw_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/05 11:01:18 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | static t_img *get_enemy_sprimg(t_game *game, int dir) 16 | { 17 | t_img *spr; 18 | 19 | spr = &(game->enemy.imgx[dir][0]); 20 | return (spr); 21 | } 22 | 23 | void draw_enemy_walk(t_game *game, t_spr *enemy, t_img *sprite, int dir) 24 | { 25 | int x; 26 | int y; 27 | 28 | game->flag.held_keys = TRUE; 29 | x = (enemy->x0 * TILE_SIZE) 30 | + (game->dir2coord[dir].x * enemy->i); 31 | y = ((enemy->y0 - 1) * TILE_SIZE) 32 | + (game->dir2coord[dir].y * enemy->i); 33 | ft_put_img(game, sprite->ptr, x, y); 34 | enemy->i += ENEMY_SPEED; 35 | if (enemy->x * TILE_SIZE == x && (enemy->y - 1) * TILE_SIZE == y) 36 | { 37 | enemy->i = 0; 38 | game->flag.held_keys = FALSE; 39 | game->flag.enemy_walk = FALSE; 40 | game->flag.game_scene = GAME_OVER; 41 | } 42 | } 43 | 44 | void draw_enemy(t_game *game) 45 | { 46 | int dir; 47 | t_spr *enemy; 48 | t_img *sprite; 49 | 50 | dir = game->enemy.dir; 51 | enemy = &(game->enemy); 52 | sprite = get_enemy_sprimg(game, dir); 53 | if (game->flag.enemy_walk && !game->flag.player_walk) 54 | draw_enemy_walk(game, enemy, sprite, dir); 55 | else 56 | ft_put_img64(game, sprite->ptr, enemy->x0, enemy->y0 - 1); 57 | } 58 | -------------------------------------------------------------------------------- /src/draw_scene.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_scene.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 15:05:07 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:16:56 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | t_img *get_end_anim_spr(t_game *game) 16 | { 17 | int *i; 18 | 19 | i = &(game->pika.i); 20 | if (*i >= 60) 21 | *i = 0; 22 | if (20 <= *i && *i < 40) 23 | return (&(game->pika.imgx[0][1])); 24 | else 25 | return (&(game->pika.imgx[0][0])); 26 | } 27 | 28 | void _draw_ending_pika(t_game *game) 29 | { 30 | int i; 31 | int j; 32 | t_img *spr; 33 | 34 | spr = get_end_anim_spr(game); 35 | i = 0; 36 | while (i < game->maps.cols) 37 | { 38 | j = 0; 39 | while (j < game->maps.rows) 40 | { 41 | ft_put_img64(game, spr->ptr, i, j); 42 | j++; 43 | } 44 | i++; 45 | } 46 | game->pika.i++; 47 | } 48 | 49 | void draw_scene_event(t_game *game) 50 | { 51 | int x; 52 | int y; 53 | 54 | x = game->maps.cols / 2 - 2; 55 | y = game->maps.rows / 2 - 2; 56 | mlx_clear_window(game->mlx, game->win); 57 | if (game->flag.game_scene == GAME_START) 58 | ft_put_img64(game, game->opening.ptr, x, y); 59 | else if (game->flag.game_scene == GAME_OVER) 60 | ft_put_img64(game, game->gameover.ptr, x, y); 61 | else if (game->flag.game_scene == GAME_ENDING) 62 | { 63 | _draw_ending_pika(game); 64 | ft_put_img64(game, game->ending.ptr, x, y); 65 | } 66 | else 67 | exit_err("GAME SCENE ERROR\n"); 68 | } 69 | -------------------------------------------------------------------------------- /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/06 15:05:07 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | t_img *get_end_anim_spr(t_game *game) 16 | { 17 | int *i; 18 | 19 | i = &(game->pika.i); 20 | if (*i >= 60) 21 | *i = 0; 22 | if (20 <= *i && *i < 40) 23 | return (&(game->pika.imgx[0][1])); 24 | else 25 | return (&(game->pika.imgx[0][0])); 26 | } 27 | 28 | void _draw_ending_pika(t_game *game) 29 | { 30 | int i; 31 | int j; 32 | t_img *spr; 33 | 34 | spr = get_end_anim_spr(game); 35 | i = 0; 36 | while (i < game->maps.cols) 37 | { 38 | j = 0; 39 | while (j < game->maps.rows) 40 | { 41 | ft_put_img64(game, spr->ptr, i, j); 42 | j++; 43 | } 44 | i++; 45 | } 46 | game->pika.i++; 47 | } 48 | 49 | void draw_scene_event(t_game *game) 50 | { 51 | int x; 52 | int y; 53 | 54 | x = game->maps.cols / 2 - 2; 55 | y = game->maps.rows / 2 - 2; 56 | mlx_clear_window(game->mlx, game->win); 57 | if (game->flag.game_scene == GAME_START) 58 | ft_put_img64(game, game->opening.ptr, x, y); 59 | else if (game->flag.game_scene == GAME_OVER) 60 | ft_put_img64(game, game->gameover.ptr, x, y); 61 | else if (game->flag.game_scene == GAME_ENDING) 62 | { 63 | _draw_ending_pika(game); 64 | ft_put_img64(game, game->ending.ptr, x, y); 65 | } 66 | else 67 | exit_err("GAME SCENE ERROR\n"); 68 | } 69 | -------------------------------------------------------------------------------- /src/player_draw.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* player_draw.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/31 07:09:00 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/09 15:17:59 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | static t_img *get_player_sprimg(t_game *game, int dir) 16 | { 17 | t_img *spr; 18 | 19 | if (game->player.spr.frame == 1) 20 | spr = &(game->player.spr.imgx[dir][1]); 21 | else if (game->player.spr.frame == 3) 22 | spr = &(game->player.spr.imgx[dir][2]); 23 | else 24 | spr = &(game->player.spr.imgx[dir][0]); 25 | return (spr); 26 | } 27 | 28 | static 29 | void draw_player_walk(t_game *game, t_spr *player, t_img *sprite, int dir) 30 | { 31 | int x; 32 | int y; 33 | 34 | game->flag.held_keys = TRUE; 35 | x = (player->x0 * TILE_SIZE) 36 | + (game->dir2coord[dir].x * player->i * player->move); 37 | y = ((player->y0 - 1) * TILE_SIZE) 38 | + (game->dir2coord[dir].y * player->i * player->move); 39 | ft_put_img(game, sprite->ptr, x, y); 40 | player->i += PLAYER_SPEED; 41 | if (player->i >= 64) 42 | { 43 | player->i = 0; 44 | game->player.spr.frame++; 45 | game->flag.held_keys = FALSE; 46 | game->flag.player_walk = FALSE; 47 | } 48 | } 49 | 50 | void draw_player(t_game *game) 51 | { 52 | int dir; 53 | t_spr *player; 54 | t_img *sprite; 55 | 56 | dir = game->player.spr.dir; 57 | player = &(game->player.spr); 58 | sprite = get_player_sprimg(game, dir); 59 | if (game->flag.player_walk) 60 | draw_player_walk(game, player, sprite, dir); 61 | else 62 | ft_put_img64(game, sprite->ptr, player->x, player->y - 1); 63 | } 64 | -------------------------------------------------------------------------------- /src_bonus/player_draw_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* player_draw_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/31 07:09:00 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:01:02 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | static t_img *get_player_sprimg(t_game *game, int dir) 16 | { 17 | t_img *spr; 18 | 19 | if (game->player.spr.frame == 1) 20 | spr = &(game->player.spr.imgx[dir][1]); 21 | else if (game->player.spr.frame == 3) 22 | spr = &(game->player.spr.imgx[dir][2]); 23 | else 24 | spr = &(game->player.spr.imgx[dir][0]); 25 | return (spr); 26 | } 27 | 28 | static 29 | void draw_player_walk(t_game *game, t_spr *player, t_img *sprite, int dir) 30 | { 31 | int x; 32 | int y; 33 | 34 | game->flag.held_keys = TRUE; 35 | x = (player->x0 * TILE_SIZE) 36 | + (game->dir2coord[dir].x * player->i * player->move); 37 | y = ((player->y0 - 1) * TILE_SIZE) 38 | + (game->dir2coord[dir].y * player->i * player->move); 39 | ft_put_img(game, sprite->ptr, x, y); 40 | player->i += PLAYER_SPEED; 41 | if (player->i >= 64) 42 | { 43 | player->i = 0; 44 | game->player.spr.frame++; 45 | game->flag.held_keys = FALSE; 46 | game->flag.player_walk = FALSE; 47 | } 48 | } 49 | 50 | void draw_player(t_game *game) 51 | { 52 | int dir; 53 | t_spr *player; 54 | t_img *sprite; 55 | 56 | dir = game->player.spr.dir; 57 | player = &(game->player.spr); 58 | sprite = get_player_sprimg(game, dir); 59 | if (game->flag.player_walk) 60 | draw_player_walk(game, player, sprite, dir); 61 | else 62 | ft_put_img64(game, sprite->ptr, player->x, player->y - 1); 63 | } 64 | -------------------------------------------------------------------------------- /minilibx_mms_20210621/mlx_string_put.c: -------------------------------------------------------------------------------- 1 | 2 | #include "mlx.h" 3 | 4 | #include "font.c" 5 | 6 | #define ATLAS_NB_CHAR 95 7 | 8 | #define FONT_WIDTH ((font_atlas.width/(ATLAS_NB_CHAR))-2) 9 | 10 | 11 | int mlx_put_image_to_window_scale(void *mlx_ptr, void *win_ptr, void *img_ptr, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, unsigned int color); 12 | 13 | void mlx_int_fill(unsigned char *data, int sl) 14 | { 15 | int i, j; 16 | j = 0; 17 | while (j < font_atlas.height) 18 | { 19 | i = 0; 20 | while (i < font_atlas.width) 21 | { 22 | data[j*sl+i*4] = font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4+2]; 23 | data[j*sl+i*4+1] = font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4+1]; 24 | data[j*sl+i*4+2] = font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4]; 25 | data[j*sl+i*4+3] = 0xFF - font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4+3]; 26 | i ++; 27 | } 28 | j ++; 29 | } 30 | 31 | } 32 | 33 | int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string) 34 | { 35 | static void *font = (void *)0; 36 | static unsigned char *data = (void *)0; 37 | static int size_line = 0; 38 | int bpp; 39 | int endian; 40 | int pos; 41 | int val; 42 | int dest_w; 43 | int dest_h; 44 | 45 | if (font == (void *)0) 46 | { 47 | font = mlx_new_image(mlx_ptr, font_atlas.width, font_atlas.height); 48 | data = (unsigned char *)mlx_get_data_addr(font, &bpp, &size_line, &endian); 49 | mlx_int_fill(data, size_line); 50 | } 51 | 52 | color = (color&0xFFFFFF)|0xFF000000; 53 | 54 | //dest_w = (FONT_WIDTH*5)/7; /// ratio with X11 standard mlx_string_put 55 | //dest_h = (font_atlas.height*5)/7; 56 | //dest_w = (FONT_WIDTH*2); 57 | //dest_h = (font_atlas.height*2); 58 | dest_w = FONT_WIDTH; 59 | dest_h = font_atlas.height; 60 | y = y - (dest_h*3)/4; 61 | 62 | pos = 0; 63 | while (*string) 64 | { 65 | if (*string >= 32 && *string <= 127) 66 | val = *string - 32; 67 | else 68 | val = 31; 69 | mlx_put_image_to_window_scale(mlx_ptr, win_ptr, font, val*(FONT_WIDTH+2), 0, FONT_WIDTH, font_atlas.height, x+pos*dest_w, y, dest_w, dest_h, color); 70 | pos ++; 71 | string ++; 72 | } 73 | return (0); 74 | } 75 | -------------------------------------------------------------------------------- /minilibx_mms_20210621/man/man3/mlx_pixel_put.3: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Drawing inside windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I int 8 | .fi 9 | .B mlx_pixel_put 10 | ( 11 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_string_put 18 | ( 19 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string 20 | ); 21 | 22 | 23 | .SH DESCRIPTION 24 | The 25 | .B mlx_pixel_put 26 | () function draws a defined pixel in the window 27 | .I win_ptr 28 | using the ( 29 | .I x 30 | , 31 | .I y 32 | ) coordinates, and the specified 33 | .I color 34 | \&. The origin (0,0) is the upper left corner of the window, the x and y axis 35 | respectively pointing right and down. The connection 36 | identifier, 37 | .I mlx_ptr 38 | , is needed (see the 39 | .B mlx 40 | man page). 41 | 42 | Parameters for 43 | .B mlx_string_put 44 | () have the same meaning. Instead of a simple pixel, the specified 45 | .I string 46 | will be displayed at ( 47 | .I x 48 | , 49 | .I y 50 | ). 51 | 52 | Both functions will discard any display outside the window. This makes 53 | .B mlx_pixel_put 54 | slow. Consider using images instead. 55 | 56 | .SH COLOR MANAGEMENT 57 | The 58 | .I color 59 | parameter has an integer type. The displayed color needs to be encoded 60 | in this integer, following a defined scheme. All displayable colors 61 | can be split in 3 basic colors: red, green and blue. Three associated 62 | values, in the 0-255 range, represent how much of each color is mixed up 63 | to create the original color. Theses three values must be set inside the 64 | integer to display the right color. The three least significant bytes of 65 | this integer are filled as shown in the picture below: 66 | 67 | .nf 68 | | 0 | R | G | B | color integer 69 | +---+---+---+---+ 70 | .fi 71 | 72 | 73 | While filling the integer, make sure you avoid endian problems. Remember 74 | that the "blue" byte should always be the least significant one. 75 | 76 | Depending on hardware capabilities, the most significant bit can handle 77 | transparency. Beware, at the opposite of the OpenGL classics, it does 78 | not represent opacity. 79 | 80 | .SH SEE ALSO 81 | mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) 82 | 83 | 84 | .SH AUTHOR 85 | Copyright ol@ - 2002-2019 - Olivier Crouzet 86 | -------------------------------------------------------------------------------- /src/init_game.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* init_game.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 15:09:39 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:27:50 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | void init_window(t_game *game) 16 | { 17 | int width; 18 | int height; 19 | 20 | debug("init_window in!", DEBUG); 21 | game->mlx = mlx_init(); 22 | debug("mlx_init", DEBUG); 23 | if (!game->mlx) 24 | exit_err("mlx_init() fail\n"); 25 | width = game->maps.cols * TILE_SIZE; 26 | height = game->maps.rows * TILE_SIZE; 27 | game->win = mlx_new_window(game->mlx, width, height, "so_long"); 28 | if (!game->win) 29 | exit_err("init_window fail\n"); 30 | } 31 | 32 | void init_player(t_game *game) 33 | { 34 | game->player.step = 0; 35 | game->player.item = 0; 36 | game->player.spr.step = 0; 37 | game->player.spr.frame = 0; 38 | game->player.spr.frame_max = P_MAX_FRAME; 39 | game->player.spr.i = 0; 40 | game->player.spr.dir = DIR_SOUTH; 41 | game->player.spr.move = TRUE; 42 | game->pika.i = 0; 43 | } 44 | 45 | void init_flag(t_game *game) 46 | { 47 | game->flag.collect_all = FALSE; 48 | game->flag.held_keys = FALSE; 49 | game->flag.player_walk = FALSE; 50 | game->flag.enemy_walk = FALSE; 51 | game->flag.step_cnt = FALSE; 52 | game->fps = 0; 53 | } 54 | 55 | int check_game_mode(int mode) 56 | { 57 | if (mode == MANDATORY) 58 | return (GAME_PLAYING); 59 | else 60 | return (GAME_START); 61 | } 62 | 63 | void init_game(t_game *game) 64 | { 65 | init_window(game); 66 | init_dir(game); 67 | init_img(game); 68 | init_enemy(game); 69 | init_player(game); 70 | init_flag(game); 71 | game->flag.game_scene = check_game_mode(GAME_MODE); 72 | debug("init_game", DEBUG); 73 | } 74 | -------------------------------------------------------------------------------- /src/event.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* event.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 15:12:02 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:26:40 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | static void check_event_exit(t_game *game) 16 | { 17 | int x; 18 | int y; 19 | 20 | x = game->player.spr.x; 21 | y = game->player.spr.y; 22 | if (game->maps.coord[y][x] == 'E' 23 | && game->flag.collect_all && !game->flag.player_walk) 24 | { 25 | ft_putstr_fd("=====================\n\n", 1); 26 | ft_putstr_fd(CYAN"THANK YOU FOR PLAYING\n\n"RESET, 1); 27 | ft_putstr_fd("Based on GAME FREAK's\n", 1); 28 | ft_putstr_fd(" Pokemon Fire Red\n\n", 1); 29 | if (GAME_MODE) 30 | ft_putstr_fd(" Press [ESC] to exit\n Press [R] to retry\n\n", 1); 31 | ft_putstr_fd("=====================\n", 1); 32 | game->flag.game_scene = GAME_ENDING; 33 | } 34 | } 35 | 36 | static void check_event_gameover(t_game *game) 37 | { 38 | int x; 39 | int y; 40 | 41 | x = game->player.spr.x; 42 | y = game->player.spr.y; 43 | if (x == game->enemy.x && y == game->enemy.y 44 | && !game->flag.enemy_walk) 45 | { 46 | ft_putstr_fd("=====================\n\n", 1); 47 | ft_putstr_fd(RED" YOU DIED\n\n"RESET, 1); 48 | ft_putstr_fd(" Press [ESC] to exit\n", 1); 49 | ft_putstr_fd(" Press [R] to retry\n\n", 1); 50 | ft_putstr_fd("=====================\n", 1); 51 | game->flag.game_scene = GAME_OVER; 52 | } 53 | } 54 | 55 | void event_checker(t_game *game) 56 | { 57 | if (game->maps.cnt.c == game->player.item) 58 | game->flag.collect_all = TRUE; 59 | check_event_gameover(game); 60 | check_event_exit(game); 61 | if (game->flag.game_scene != GAME_PLAYING && !GAME_MODE) 62 | close_game(game); 63 | } 64 | -------------------------------------------------------------------------------- /src_bonus/init_game_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* init_game_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 15:09:39 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:34:04 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | void init_window(t_game *game) 16 | { 17 | int width; 18 | int height; 19 | 20 | debug("init_window in!", DEBUG); 21 | game->mlx = mlx_init(); 22 | debug("mlx_init", DEBUG); 23 | if (!game->mlx) 24 | exit_err("mlx_init() fail\n"); 25 | width = game->maps.cols * TILE_SIZE; 26 | height = game->maps.rows * TILE_SIZE; 27 | game->win = mlx_new_window(game->mlx, width, height, "so_long"); 28 | if (!game->win) 29 | exit_err("init_window fail\n"); 30 | } 31 | 32 | void init_player(t_game *game) 33 | { 34 | game->player.step = 0; 35 | game->player.item = 0; 36 | game->player.spr.step = 0; 37 | game->player.spr.frame = 0; 38 | game->player.spr.frame_max = P_MAX_FRAME; 39 | game->player.spr.i = 0; 40 | game->player.spr.dir = DIR_SOUTH; 41 | game->player.spr.move = TRUE; 42 | game->pika.i = 0; 43 | } 44 | 45 | void init_flag(t_game *game) 46 | { 47 | game->flag.collect_all = FALSE; 48 | game->flag.held_keys = FALSE; 49 | game->flag.player_walk = FALSE; 50 | game->flag.enemy_walk = FALSE; 51 | game->flag.step_cnt = FALSE; 52 | game->fps = 0; 53 | } 54 | 55 | int check_game_mode(int mode) 56 | { 57 | if (mode == MANDATORY) 58 | return (GAME_PLAYING); 59 | else 60 | return (GAME_START); 61 | } 62 | 63 | void init_game(t_game *game) 64 | { 65 | init_window(game); 66 | init_dir(game); 67 | init_img(game); 68 | init_enemy(game); 69 | init_player(game); 70 | init_flag(game); 71 | game->flag.game_scene = check_game_mode(GAME_MODE); 72 | debug("init_game", DEBUG); 73 | } 74 | -------------------------------------------------------------------------------- /src_bonus/event_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* event_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/08/06 15:12:02 by jisokang #+# #+# */ 9 | /* Updated: 2021/08/10 17:34:47 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | static void check_event_exit(t_game *game) 16 | { 17 | int x; 18 | int y; 19 | 20 | x = game->player.spr.x; 21 | y = game->player.spr.y; 22 | if (game->maps.coord[y][x] == 'E' 23 | && game->flag.collect_all && !game->flag.player_walk) 24 | { 25 | ft_putstr_fd("=====================\n\n", 1); 26 | ft_putstr_fd(CYAN"THANK YOU FOR PLAYING\n\n"RESET, 1); 27 | ft_putstr_fd("Based on GAME FREAK's\n", 1); 28 | ft_putstr_fd(" Pokemon Fire Red\n\n", 1); 29 | if (GAME_MODE) 30 | ft_putstr_fd(" Press [ESC] to exit\n Press [R] to retry\n\n", 1); 31 | ft_putstr_fd("=====================\n", 1); 32 | game->flag.game_scene = GAME_ENDING; 33 | } 34 | } 35 | 36 | static void check_event_gameover(t_game *game) 37 | { 38 | int x; 39 | int y; 40 | 41 | x = game->player.spr.x; 42 | y = game->player.spr.y; 43 | if (x == game->enemy.x && y == game->enemy.y 44 | && !game->flag.enemy_walk) 45 | { 46 | ft_putstr_fd("=====================\n\n", 1); 47 | ft_putstr_fd(RED" YOU DIED\n\n"RESET, 1); 48 | ft_putstr_fd(" Press [ESC] to exit\n", 1); 49 | ft_putstr_fd(" Press [R] to retry\n\n", 1); 50 | ft_putstr_fd("=====================\n", 1); 51 | game->flag.game_scene = GAME_OVER; 52 | } 53 | } 54 | 55 | void event_checker(t_game *game) 56 | { 57 | if (game->maps.cnt.c == game->player.item) 58 | game->flag.collect_all = TRUE; 59 | check_event_gameover(game); 60 | check_event_exit(game); 61 | if (game->flag.game_scene != GAME_PLAYING && !GAME_MODE) 62 | close_game(game); 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/libft/Makefile: -------------------------------------------------------------------------------- 1 | # # **************************************************************************** # 2 | # # # 3 | # # ::: :::::::: # 4 | # # Makefile :+: :+: :+: # 5 | # # +:+ +:+ +:+ # 6 | # # By: jisokang +#+ +:+ +#+ # 7 | # # +#+#+#+#+#+ +#+ # 8 | # # Created: 2020/12/23 22:53:42 by jisokang #+# #+# # 9 | # # Updated: 2021/02/20 19:57:08 by jisokang ### ########.fr # 10 | # # # 11 | # # **************************************************************************** # 12 | 13 | # NAME = libft.a 14 | 15 | # CC = gcc 16 | # CFLAGS = -Wall -Wextra -Werror 17 | 18 | # AR = ar rcs 19 | # RM = rm -f 20 | 21 | # SRCS = ft_atoi.c \ 22 | # ft_isalnum.c \ 23 | # ft_isalpha.c \ 24 | # ft_isascii.c \ 25 | # ft_isdigit.c \ 26 | # ft_isprint.c \ 27 | # ft_tolower.c \ 28 | # ft_toupper.c \ 29 | # ft_strlen.c \ 30 | # ft_strlcat.c \ 31 | # ft_strlcpy.c \ 32 | # ft_bzero.c \ 33 | # ft_strncmp.c \ 34 | # ft_strchr.c \ 35 | # ft_strrchr.c \ 36 | # ft_strnstr.c \ 37 | # ft_memset.c \ 38 | # ft_memmove.c \ 39 | # ft_memcpy.c \ 40 | # ft_memccpy.c \ 41 | # ft_memchr.c \ 42 | # ft_memcmp.c \ 43 | # ft_calloc.c \ 44 | # ft_strdup.c \ 45 | # ft_substr.c \ 46 | # ft_strjoin.c \ 47 | # ft_strtrim.c \ 48 | # ft_itoa.c \ 49 | # ft_putchar_fd.c \ 50 | # ft_putstr_fd.c \ 51 | # ft_putendl_fd.c \ 52 | # ft_putnbr_fd.c \ 53 | # ft_strmapi.c \ 54 | # ft_split.c 55 | 56 | # SRCS_BONUS = ft_lstnew.c \ 57 | # ft_lstadd_front.c \ 58 | # ft_lstsize.c \ 59 | # ft_lstlast.c \ 60 | # ft_lstadd_back.c \ 61 | # ft_lstdelone.c \ 62 | # ft_lstclear.c \ 63 | # ft_lstiter.c \ 64 | # ft_lstmap.c 65 | 66 | # OBJS = $(SRCS:.c=.o) 67 | # OBJS_BONUS = $(SRCS_BONUS:.c=.o) 68 | 69 | # $(NAME): $(OBJS) 70 | # $(AR) $@ $^ 71 | 72 | # bonus: $(OBJS_BONUS) 73 | # $(AR) $(NAME) $^ 74 | 75 | # all: $(NAME) 76 | 77 | # clean: 78 | # $(RM) $(OBJS) $(OBJS_BONUS) 79 | 80 | # fclean: clean 81 | # $(RM) $(NAME) 82 | 83 | # re: clean all 84 | -------------------------------------------------------------------------------- /lib/src/libft/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/10 07:44:44 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/23 19:29:41 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/libft.h" 14 | 15 | size_t get_str_count(const char *str, char c) 16 | { 17 | size_t i; 18 | size_t count; 19 | 20 | i = 0; 21 | count = 0; 22 | while (str[i] != '\0') 23 | { 24 | if (str[i] != c && str[i] != '\0') 25 | { 26 | count++; 27 | while (str[i] != c && str[i] != '\0') 28 | i++; 29 | } 30 | else if (str[i] != '\0') 31 | i++; 32 | } 33 | return (count); 34 | } 35 | 36 | static void *free_malloc(char **str) 37 | { 38 | size_t i; 39 | 40 | i = 0; 41 | while (str[i] != NULL) 42 | { 43 | free(str[i]); 44 | i++; 45 | } 46 | free(str); 47 | return (NULL); 48 | } 49 | 50 | static void do_split(char const *s, char c, char **str) 51 | { 52 | size_t i; 53 | size_t j; 54 | size_t start; 55 | 56 | i = 0; 57 | j = 0; 58 | while (s[i] != '\0') 59 | { 60 | if (s[i] != c && s[i] != '\0') 61 | { 62 | start = i; 63 | while (s[i] != c && s[i] != '\0') 64 | i++; 65 | str[j] = (char *)malloc(sizeof(char) * (i - start + 1)); 66 | if (str[j] == NULL) 67 | { 68 | free_malloc(str); 69 | return ; 70 | } 71 | ft_strlcpy(str[j], &s[start], i - start + 1); 72 | j++; 73 | } 74 | else if (s[i] != '\0') 75 | i++; 76 | } 77 | } 78 | 79 | char **ft_split(char const *s, char c) 80 | { 81 | char **str; 82 | size_t str_count; 83 | 84 | if (s == NULL) 85 | return (NULL); 86 | str_count = get_str_count(s, c); 87 | str = (char **)malloc(sizeof(char *) * (str_count + 1)); 88 | if (str == NULL) 89 | return (NULL); 90 | str[str_count] = NULL; 91 | if (str_count == 0) 92 | return (str); 93 | do_split(s, c, str); 94 | return (str); 95 | } 96 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/src/get_next_line/get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/09 19:15:25 by jisokang #+# #+# */ 9 | /* Updated: 2021/07/17 18:36:15 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/get_next_line.h" 14 | 15 | int is_newline(char const *s) 16 | { 17 | size_t i; 18 | 19 | if (s == NULL) 20 | return (0); 21 | i = 0; 22 | while (s[i] != '\0') 23 | { 24 | if (s[i] == '\n') 25 | return (i); 26 | i++; 27 | } 28 | return (-1); 29 | } 30 | 31 | int split_line(char **backup, char **line, int cut_idx) 32 | { 33 | char *temp; 34 | int len; 35 | 36 | (*backup)[cut_idx] = '\0'; 37 | *line = ft_strdup_gnl(*backup); 38 | len = ft_strlen(*backup + cut_idx + 1); 39 | if (len == 0) 40 | { 41 | free(*backup); 42 | *backup = 0; 43 | return (1); 44 | } 45 | temp = ft_strdup_gnl(*backup + cut_idx + 1); 46 | free(*backup); 47 | *backup = temp; 48 | return (1); 49 | } 50 | 51 | int return_all(char **backup, char **line, int read_size) 52 | { 53 | int cut_idx; 54 | 55 | if (read_size < 0) 56 | return (-1); 57 | if (*backup && (cut_idx = is_newline(*backup)) >= 0) 58 | return (split_line(backup, line, cut_idx)); 59 | else if (*backup != NULL) 60 | { 61 | *line = *backup; 62 | *backup = 0; 63 | return (0); 64 | } 65 | *line = ft_strdup_gnl(""); 66 | return (0); 67 | } 68 | 69 | int get_next_line(int fd, char **line) 70 | { 71 | static char *backup; 72 | char buf[BUFFER_SIZE + 1]; 73 | int read_size; 74 | int cut_idx; 75 | 76 | if (fd < 0 || line == NULL || BUFFER_SIZE <= 0) 77 | return (-1); 78 | while ((read_size = read(fd, buf, BUFFER_SIZE)) > 0) 79 | { 80 | buf[read_size] = '\0'; 81 | backup = ft_strjoin_gnl(backup, buf); 82 | if ((cut_idx = is_newline(backup)) >= 0) 83 | return (split_line(&backup, line, cut_idx)); 84 | } 85 | return (return_all(&backup, line, read_size)); 86 | } 87 | -------------------------------------------------------------------------------- /src/map_compo_coord.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_compo_coord.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 02:14:54 by jisokang #+# #+# */ 9 | /* Updated: 2021/09/30 01:17:32 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include/so_long.h" 14 | 15 | static void init_compo_cnt(t_game *game) 16 | { 17 | game->maps.cnt.p = 0; 18 | game->maps.cnt.e = 0; 19 | game->maps.cnt.c = 0; 20 | game->maps.cnt.r = 0; 21 | } 22 | 23 | static void _compo_coord(t_game *game, int i, int j) 24 | { 25 | if (game->maps.coord[i][j] == 'P') 26 | { 27 | game->player.spr.x = j; 28 | game->player.spr.x0 = j; 29 | game->player.spr.y = i; 30 | game->player.spr.y0 = i; 31 | game->maps.cnt.p++; 32 | } 33 | else if (game->maps.coord[i][j] == 'C') 34 | { 35 | game->maps.cnt.c++; 36 | clst_add_back(&(game->collec.clst), clst_new(j, i)); 37 | } 38 | else if (game->maps.coord[i][j] == 'R') 39 | { 40 | game->enemy.x = j; 41 | game->enemy.x0 = j; 42 | game->enemy.y = i; 43 | game->enemy.y0 = i; 44 | game->maps.cnt.r++; 45 | } 46 | else if (game->maps.coord[i][j] == 'E') 47 | game->maps.cnt.e++; 48 | } 49 | 50 | int check_compo_cnt(t_game *game) 51 | { 52 | if (!(0 < game->maps.cnt.p && game->maps.cnt.p <= COMPO_P_MAX)) 53 | return (FALSE); 54 | if (!(0 < game->maps.cnt.p && game->maps.cnt.p <= COMPO_C_MAX)) 55 | return (FALSE); 56 | if (!(0 < game->maps.cnt.e && game->maps.cnt.e <= COMPO_E_MAX)) 57 | return (FALSE); 58 | if (!(0 <= game->maps.cnt.r && game->maps.cnt.r <= COMPO_R_MAX)) 59 | return (FALSE); 60 | return (TRUE); 61 | } 62 | 63 | void get_compo_coord(t_game *game) 64 | { 65 | int i; 66 | int j; 67 | 68 | init_compo_cnt(game); 69 | i = 0; 70 | while (i < game->maps.rows) 71 | { 72 | j = 0; 73 | while (j < game->maps.cols) 74 | { 75 | _compo_coord(game, i, j); 76 | j++; 77 | } 78 | i++; 79 | } 80 | if (check_compo_cnt(game) == FALSE) 81 | exit_err("Invalid number of components found.\n"); 82 | } 83 | -------------------------------------------------------------------------------- /src_bonus/map_compo_coord_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* map_compo_coord_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/07/27 02:14:54 by jisokang #+# #+# */ 9 | /* Updated: 2021/09/30 01:17:31 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../include_bonus/so_long_bonus.h" 14 | 15 | static void init_compo_cnt(t_game *game) 16 | { 17 | game->maps.cnt.p = 0; 18 | game->maps.cnt.e = 0; 19 | game->maps.cnt.c = 0; 20 | game->maps.cnt.r = 0; 21 | } 22 | 23 | static void _compo_coord(t_game *game, int i, int j) 24 | { 25 | if (game->maps.coord[i][j] == 'P') 26 | { 27 | game->player.spr.x = j; 28 | game->player.spr.x0 = j; 29 | game->player.spr.y = i; 30 | game->player.spr.y0 = i; 31 | game->maps.cnt.p++; 32 | } 33 | else if (game->maps.coord[i][j] == 'C') 34 | { 35 | game->maps.cnt.c++; 36 | clst_add_back(&(game->collec.clst), clst_new(j, i)); 37 | } 38 | else if (game->maps.coord[i][j] == 'R') 39 | { 40 | game->enemy.x = j; 41 | game->enemy.x0 = j; 42 | game->enemy.y = i; 43 | game->enemy.y0 = i; 44 | game->maps.cnt.r++; 45 | } 46 | else if (game->maps.coord[i][j] == 'E') 47 | game->maps.cnt.e++; 48 | } 49 | 50 | int check_compo_cnt(t_game *game) 51 | { 52 | if (!(0 < game->maps.cnt.p && game->maps.cnt.p <= COMPO_P_MAX)) 53 | return (FALSE); 54 | if (!(0 < game->maps.cnt.p && game->maps.cnt.p <= COMPO_C_MAX)) 55 | return (FALSE); 56 | if (!(0 < game->maps.cnt.e && game->maps.cnt.e <= COMPO_E_MAX)) 57 | return (FALSE); 58 | if (!(0 <= game->maps.cnt.r && game->maps.cnt.r <= COMPO_R_MAX)) 59 | return (FALSE); 60 | return (TRUE); 61 | } 62 | 63 | void get_compo_coord(t_game *game) 64 | { 65 | int i; 66 | int j; 67 | 68 | init_compo_cnt(game); 69 | i = 0; 70 | while (i < game->maps.rows) 71 | { 72 | j = 0; 73 | while (j < game->maps.cols) 74 | { 75 | _compo_coord(game, i, j); 76 | j++; 77 | } 78 | i++; 79 | } 80 | if (check_compo_cnt(game) == FALSE) 81 | exit_err("Invalid number of components found.\n"); 82 | } 83 | -------------------------------------------------------------------------------- /lib/src/ft_printf/ft_printf_num_print.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_printf_num_print.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jisokang +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/04/03 17:11:49 by jisokang #+# #+# */ 9 | /* Updated: 2021/06/21 16:40:26 by jisokang ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../../include/ft_printf.h" 14 | 15 | int get_max(int a, int b) 16 | { 17 | if (a > b) 18 | return (a); 19 | else 20 | return (b); 21 | } 22 | 23 | int ft_putchar_len(char c, int *len) 24 | { 25 | int i; 26 | 27 | i = 0; 28 | while ((*len)-- > 0) 29 | i += write(1, &c, 1); 30 | return (i); 31 | } 32 | 33 | int num_itoa(t_info *info, char *num_box, long long num) 34 | { 35 | int len; 36 | 37 | len = 0; 38 | if (num == 0) 39 | num_box[len++] = '0'; 40 | else 41 | { 42 | while (num != 0) 43 | { 44 | num_box[len++] = (DIGITS[num % info->num_base]) | info->locass; 45 | num = num / info->num_base; 46 | } 47 | } 48 | return (len); 49 | } 50 | 51 | int print_sign(t_info *info) 52 | { 53 | int printed; 54 | 55 | printed = 0; 56 | if (info->num_sign == -1) 57 | printed += write(1, "-", 1); 58 | if (info->address == ENABLE) 59 | printed += write(1, "0x", 2); 60 | return (printed); 61 | } 62 | 63 | int print_num(t_info *info, long long num) 64 | { 65 | int len; 66 | int gap; 67 | int printed; 68 | long long tmp_num; 69 | char num_box[21]; 70 | 71 | printed = 0; 72 | tmp_num = num; 73 | len = num_itoa(info, num_box, num); 74 | if (tmp_num == 0 && (info->precision == 0 || info->dot_only == ENABLE)) 75 | len = 0; 76 | gap = info->width - get_max(info->precision, len); 77 | if ((info->minus == DISABLE && gap > 0) && (!(info->zero == ENABLE && 78 | info->precision < 0) || info->dot_only == ENABLE)) 79 | printed += ft_putchar_len(' ', &gap); 80 | info->precision = get_max(info->precision, len); 81 | printed += print_sign(info); 82 | if (info->zero == ENABLE) 83 | printed += ft_putchar_len('0', &gap); 84 | info->precision -= len; 85 | printed += ft_putchar_len('0', &info->precision); 86 | while (len-- > 0) 87 | printed += write(1, &num_box[len], 1); 88 | printed += ft_putchar_len(' ', &gap); 89 | return (printed); 90 | } 91 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: jisokang +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/04/19 15:58:12 by sashin #+# #+# # 9 | # Updated: 2021/07/16 20:38:46 by jisokang ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | # Original version created by sashin from 42 Seoul 14 | # If you want to add library, add "$(SRC)", "$(SRC_DIR)", dependancy of $(NAME) and clean 15 | 16 | NAME = lib_jisokang.a 17 | 18 | CC = gcc 19 | CFLAGS = -Wall -Werror -Wextra 20 | 21 | AR = ar 22 | ARFLAGS = -rcs 23 | 24 | INCLUDES_DIR = include 25 | LIBFT_DIR = src/libft 26 | FT_PRINTF_DIR = src/ft_printf 27 | GNL_DIR = src/get_next_line 28 | 29 | LIBFT = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c \ 30 | ft_memchr.c ft_memcmp.c ft_strlen.c ft_strlcpy.c ft_strlcat.c \ 31 | ft_strchr.c ft_strrchr.c ft_strnstr.c ft_strncmp.c ft_atoi.c \ 32 | ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c \ 33 | ft_toupper.c ft_tolower.c ft_calloc.c ft_strdup.c ft_substr.c \ 34 | ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \ 35 | ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \ 36 | ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back.c \ 37 | ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c ft_swap_int.c \ 38 | ft_num_tobase.c 39 | 40 | FT_PRINTF = ft_printf.c ft_printf_char.c ft_printf_num_print.c \ 41 | ft_printf_num.c ft_printf_parse.c ft_printf_string.c \ 42 | 43 | GNL = get_next_line.c get_next_line_utils.c 44 | 45 | all: $(NAME) 46 | 47 | $(NAME): libft ft_printf gnl 48 | 49 | %.o: %.c 50 | $(CC) $(CFLAGS) -c -o $@ $^ 51 | $(AR) $(ARFLAGS) $(NAME) $@ 52 | 53 | libft: $(addprefix $(LIBFT_DIR)/, $(LIBFT:.c=.o)) 54 | ft_printf: $(addprefix $(FT_PRINTF_DIR)/, $(FT_PRINTF:.c=.o)) 55 | gnl: $(addprefix $(GNL_DIR)/, $(GNL:.c=.o)) 56 | 57 | clean: 58 | rm -rf $(addprefix $(LIBFT_DIR)/, $(LIBFT:.c=.o)) 59 | rm -rf $(addprefix $(FT_PRINTF_DIR)/, $(FT_PRINTF:.c=.o)) 60 | rm -rf $(addprefix $(GNL_DIR)/, $(GNL:.c=.o)) 61 | 62 | fclean: clean 63 | rm -rf $(NAME) 64 | 65 | re: fclean all 66 | 67 | .PHONY: all bonus clean fclean re libft ft_printf gnl 68 | --------------------------------------------------------------------------------