├── cubs ├── test.txt ├── bonus.cub └── test.cub ├── minilibx ├── 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 └── mlx.h ├── textures ├── planks.jpeg └── wood.xpm ├── libft ├── ft_tolower.c ├── ft_putchar_fd.c ├── ft_bzero.c ├── ft_toupper.c ├── ft_putendl_fd.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_isprint.c ├── ft_isalnum.c ├── ft_strlen.c ├── ft_isalpha.c ├── ft_lstdelone.c ├── ft_lstlast.c ├── ft_putstr_fd.c ├── ft_lstadd_front.c ├── ft_lstiter.c ├── ft_lstsize.c ├── ft_lstnew.c ├── ft_calloc.c ├── ft_memset.c ├── ft_strchr.c ├── ft_lstclear.c ├── ft_lstadd_back.c ├── ft_strrchr.c ├── ft_memchr.c ├── ft_memcmp.c ├── ft_strlcpy.c ├── ft_memcpy.c ├── ft_strdup.c ├── ft_strncmp.c ├── ft_putnbr_fd.c ├── ft_strlcat.c ├── ft_memmove.c ├── ft_strmapi.c ├── ft_atoi.c ├── ft_lstmap.c ├── ft_memccpy.c ├── ft_strjoin.c ├── ft_strnstr.c ├── get_next_line.h ├── ft_substr.c ├── ft_itoa.c ├── ft_strtrim.c ├── Makefile ├── ft_split.c ├── get_next_line_utils.c ├── get_next_line.c └── libft.h ├── mandatory_game ├── ft_init2.c ├── color_utils.c ├── ft_initdestroyimg.c ├── horiz_vert_raycomp.c ├── start_game.c ├── start_game_utils3.c ├── bitmap_offsets.c ├── update.c ├── ft_init.c ├── events.c ├── draw.c ├── start_game_utils.c ├── draw2.c ├── start_game_utils2.c ├── cast_rays.c ├── lines.c ├── cast_rays_vertical.c ├── ft_prepare_lines.c ├── cast_rays_horizontal.c ├── update_sprites.c └── bmp_screenshot.c ├── bonus_game ├── ft_init_anim_bonus.c ├── cub3d_bonus.c ├── start_game_bonus.c ├── bitmap_offsets_bonus.c ├── update_bonus.c ├── utils_attack_pickaxe_bonus.c ├── utils_normal_pickaxe_bonus.c ├── draw_bonus.c ├── events_bonus.c ├── lines_bonus.c ├── cast_rays_bonus.c ├── ft_prepare_lines_bonus.c └── draw2_bonus.c ├── other_utils ├── free_utils.c └── ft_error.c ├── includes ├── cub3d.h └── structs.h ├── extract_and_parse ├── ft_parse_map2.c ├── ft_parse_resolution.c ├── ft_parse_utils2.c ├── ft_parse_cub.c ├── ft_parse_textures2.c ├── ft_parse.h ├── ft_parse_utils.c ├── ft_parse_textures.c ├── ft_parse_map.c ├── text_extract.c └── ft_parse_rgbs.c ├── cub3d.c └── Makefile /cubs/test.txt: -------------------------------------------------------------------------------- 1 | ola 2 | -------------------------------------------------------------------------------- /minilibx/font.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleal42/cub3d/HEAD/minilibx/font.xcf -------------------------------------------------------------------------------- /textures/planks.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gleal42/cub3d/HEAD/textures/planks.jpeg -------------------------------------------------------------------------------- /minilibx/mlx_png.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | void *mlx_png_file_to_image(void *xvar, char *file, int *width, int *height); 5 | -------------------------------------------------------------------------------- /minilibx/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 | -------------------------------------------------------------------------------- /minilibx/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 | -------------------------------------------------------------------------------- /cubs/bonus.cub: -------------------------------------------------------------------------------- 1 | R 1920 1080 2 | 3 | NO ./textures/planks.xpm 4 | SO ./textures/grass.xpm 5 | WE ./textures/torch.xpm 6 | EA ./textures/attack_torch.xpm 7 | 8 | S ./textures/creeper.xpm 9 | F 77,92,53 10 | C 163,208,230 11 | 12 | 1111111111111111111111111 13 | 1000000000110000000000001 14 | 1011000001110000002000001 15 | 1001000000000000000002001 16 | 111111111011000001110000000000001 17 | 100000000011000001110111110111111 18 | 11110111111111011100000010001 19 | 11110111111111011101010010001 20 | 11000000110101011100000010001 21 | 10002000000000001100000010001 22 | 10000000000000001101010010001 23 | 11000001110101011111011110N0111 24 | 11110111 1110101 101111010001 25 | 11111111 1111111 111111111111 26 | -------------------------------------------------------------------------------- /cubs/test.cub: -------------------------------------------------------------------------------- 1 | R 1920 1080 2 | 3 | NO ./textures/greystone.xpm 4 | SO ./textures/purplestone.xpm 5 | WE ./textures/redbrick.xpm 6 | EA ./textures/wood.xpm 7 | 8 | S ./textures/creeper.xpm 9 | F 77,92,53 10 | C 163,208,230 11 | 12 | 1111111111111111111111111 13 | 1000000000110000000000001 14 | 1011000001110000002000001 15 | 1001000000000000000002001 16 | 111111111011000001110000000000001 17 | 100000000011000001110111110111111 18 | 11110111111111011100000010001 19 | 11110111111111011101010010001 20 | 11000000110101011100000010001 21 | 10002000000000001100000010001 22 | 10000000000000001101010010001 23 | 11000001110101011111011110N0111 24 | 11110111 1110101 101111010001 25 | 11111111 1111111 111111111111 26 | -------------------------------------------------------------------------------- /libft/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 22:43:24 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 22:45:35 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_tolower(int c) 14 | { 15 | if (c >= 'A' && c <= 'Z') 16 | c += 32; 17 | return (c); 18 | } 19 | -------------------------------------------------------------------------------- /libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/08 22:24:00 by gleal #+# #+# */ 9 | /* Updated: 2021/02/08 22:46:48 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/28 22:17:37 by gleal #+# #+# */ 9 | /* Updated: 2021/01/28 23:32:44 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | if (n != 0) 18 | ft_memset(s, '\0', n); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 21:23:07 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 22:26:33 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (c >= 'a' && c <= 'z') 18 | c -= 32; 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/09 00:10:02 by gleal #+# #+# */ 9 | /* Updated: 2021/02/09 00:22:23 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl_fd(char *s, int fd) 16 | { 17 | ft_putstr_fd(s, fd); 18 | ft_putchar_fd('\n', fd); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 20:14:11 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 20:16:41 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #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 | -------------------------------------------------------------------------------- /libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 18:39:54 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 18:45:22 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #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 | -------------------------------------------------------------------------------- /libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 20:27:34 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 20:38:53 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #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 | -------------------------------------------------------------------------------- /libft/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 18:59:36 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 20:13:53 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #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 | -------------------------------------------------------------------------------- /libft/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/01 01:43:09 by gleal #+# #+# */ 9 | /* Updated: 2021/02/01 01:52:54 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #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]) 21 | i++; 22 | return (i); 23 | } 24 | -------------------------------------------------------------------------------- /libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 17:13:28 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 18:06:23 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #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 | -------------------------------------------------------------------------------- /libft/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/10 19:40:34 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:26:51 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void*)) 16 | { 17 | if (!lst || !del) 18 | return ; 19 | del(lst->content); 20 | free(lst); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/10 17:40:57 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:28:10 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | if (!lst) 18 | return (0); 19 | while (lst->next) 20 | lst = lst->next; 21 | return (lst); 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/08 23:00:50 by gleal #+# #+# */ 9 | /* Updated: 2021/02/09 00:04:37 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr_fd(char *s, int fd) 16 | { 17 | if (!s) 18 | return ; 19 | while (*s) 20 | { 21 | ft_putchar_fd(*s, fd); 22 | s++; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/10 00:28:04 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:26:30 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **lst, t_list *new) 16 | { 17 | if (!lst || !new) 18 | return ; 19 | if (*lst) 20 | new->next = *lst; 21 | *lst = new; 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/10 23:32:17 by gleal #+# #+# */ 9 | /* Updated: 2021/02/10 23:55:11 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | if (!lst || !f) 18 | return ; 19 | while (lst) 20 | { 21 | f(lst->content); 22 | lst = lst->next; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/10 01:34:36 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:27:44 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int count; 18 | 19 | count = 0; 20 | while (lst) 21 | { 22 | lst = lst->next; 23 | count++; 24 | } 25 | return (count); 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/09 23:34:38 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:28:43 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *head; 18 | 19 | head = (t_list*)malloc(sizeof(t_list)); 20 | if (!head) 21 | return (0); 22 | head->content = content; 23 | head->next = 0; 24 | return (head); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 22:49:28 by gleal #+# #+# */ 9 | /* Updated: 2021/02/07 22:11:24 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t count, size_t size) 16 | { 17 | size_t i; 18 | void *ptr; 19 | 20 | i = 0; 21 | ptr = (void *)malloc(size * count); 22 | if (!ptr) 23 | return (0); 24 | ft_bzero(ptr, count * size); 25 | return (ptr); 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/28 19:08:48 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 23:25:12 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *b, int c, size_t len) 16 | { 17 | unsigned char *string; 18 | size_t i; 19 | 20 | string = (unsigned char*)b; 21 | i = 0; 22 | while (i < len) 23 | { 24 | string[i] = (unsigned char)c; 25 | i++; 26 | } 27 | return (b); 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/02 17:27:06 by gleal #+# #+# */ 9 | /* Updated: 2021/02/11 22:44:10 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | char *str; 18 | 19 | str = (char *)s; 20 | while (*str) 21 | { 22 | if (*str == (char)c) 23 | return (str); 24 | str++; 25 | } 26 | if (*str == (char)c) 27 | return (str); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /libft/ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/10 20:34:20 by gleal #+# #+# */ 9 | /* Updated: 2021/02/10 23:25:35 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void*)) 16 | { 17 | t_list *deleter; 18 | 19 | if (!lst || !del || !*lst) 20 | return ; 21 | while (*lst) 22 | { 23 | deleter = *lst; 24 | *lst = (*lst)->next; 25 | ft_lstdelone(deleter, del); 26 | } 27 | *lst = 0; 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/10 19:21:40 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:27:26 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **lst, t_list *new) 16 | { 17 | t_list *head; 18 | 19 | head = *lst; 20 | if (!lst || !new) 21 | return ; 22 | if (!*lst) 23 | { 24 | *lst = new; 25 | return ; 26 | } 27 | while (head->next) 28 | head = head->next; 29 | head->next = new; 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/02 18:43:55 by gleal #+# #+# */ 9 | /* Updated: 2021/02/18 16:12:35 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | char *str; 18 | char *res; 19 | 20 | str = (char *)s; 21 | res = 0; 22 | if (!str) 23 | return (0); 24 | while (*str) 25 | { 26 | if (*str == (char)c) 27 | res = str; 28 | str++; 29 | } 30 | if (*str == (char)c) 31 | res = str; 32 | return (res); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/31 18:03:56 by gleal #+# #+# */ 9 | /* Updated: 2021/01/31 19:34:26 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | size_t i; 18 | unsigned char ch; 19 | unsigned char *string; 20 | 21 | i = 0; 22 | string = (unsigned char*)s; 23 | ch = (unsigned char)c; 24 | while (i < n) 25 | { 26 | if (string[i] == ch) 27 | return (&string[i]); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /mandatory_game/ft_init2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_init2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/10 15:32:26 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:19 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | void ftinit_rays(t_adata *a) 16 | { 17 | a->ray.fov = 60 * (M_PI / 180); 18 | a->ray.fovref_min = 2 * M_PI - (a->ray.fov / 2); 19 | a->ray.fovref_max = a->ray.fov / 2; 20 | a->ray.wall_strip_w = 1; 21 | a->ray.num_rays = a->win.win_w / a->ray.wall_strip_w; 22 | a->ray.distprojplane = (a->win.win_w / 2) / tan(a->ray.fov / 2); 23 | } 24 | -------------------------------------------------------------------------------- /libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/01 00:11:44 by gleal #+# #+# */ 9 | /* Updated: 2021/02/01 01:21:12 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #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 (i < n) 25 | { 26 | if (str1[i] != str2[i]) 27 | return (str1[i] - str2[i]); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/01 19:01:14 by gleal #+# #+# */ 9 | /* Updated: 2021/02/11 20:45:44 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dst || !src) 21 | return (0); 22 | if (dstsize) 23 | { 24 | while (i < (dstsize - 1) && src[i]) 25 | { 26 | dst[i] = src[i]; 27 | i++; 28 | } 29 | dst[i] = '\0'; 30 | } 31 | while (src[i]) 32 | i++; 33 | return (i); 34 | } 35 | -------------------------------------------------------------------------------- /bonus_game/ft_init_anim_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_init_anim_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 21:42:11 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:49:01 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | /* the map r half and b half are variables that I will use to place the weapons in the right bottom quarter of the screen */ 15 | void ft_init_animation(t_adata *a) 16 | { 17 | a->joe.anim_start = 0; 18 | a->joe.anim_count = 0; 19 | a->map.map_r_half = ceil((double)(a->win.win_w / 2)); 20 | a->map.map_b_half = ceil((double)(a->win.win_h / 2)); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/28 23:49:57 by gleal #+# #+# */ 9 | /* Updated: 2021/02/11 17:53:13 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t n) 16 | { 17 | unsigned char *destn; 18 | unsigned char *sourc; 19 | size_t i; 20 | 21 | if (!dst && !src) 22 | return (0); 23 | destn = (unsigned char*)dst; 24 | sourc = (unsigned char*)src; 25 | i = 0; 26 | while (i < n) 27 | { 28 | destn[i] = sourc[i]; 29 | i++; 30 | } 31 | return (dst); 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 23:53:20 by gleal #+# #+# */ 9 | /* Updated: 2021/02/07 22:45:32 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(const char *s1) 16 | { 17 | size_t i; 18 | size_t size; 19 | char *str; 20 | 21 | size = 0; 22 | while (s1[size]) 23 | size++; 24 | str = (char *)malloc(sizeof(char) * (size + 1)); 25 | if (!str) 26 | return (0); 27 | i = 0; 28 | while (s1[i]) 29 | { 30 | str[i] = s1[i]; 31 | i++; 32 | } 33 | str[i] = '\0'; 34 | return (str); 35 | } 36 | -------------------------------------------------------------------------------- /libft/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 00:07:20 by gleal #+# #+# */ 9 | /* Updated: 2021/02/03 00:44:22 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *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 | if (!n) 25 | return (0); 26 | while (str1[i] && str2[i] && i + 1 < n && str1[i] == str2[i]) 27 | i++; 28 | return (str1[i] - str2[i]); 29 | } 30 | -------------------------------------------------------------------------------- /minilibx/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 | -------------------------------------------------------------------------------- /libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/09 00:35:16 by gleal #+# #+# */ 9 | /* Updated: 2021/02/09 00:48:20 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | if (n == -2147483648) 18 | ft_putstr_fd("-2147483648", fd); 19 | else if (n < 0) 20 | { 21 | ft_putchar_fd('-', fd); 22 | ft_putnbr_fd(-n, fd); 23 | } 24 | else if (n < 10) 25 | ft_putchar_fd(n + '0', fd); 26 | else 27 | { 28 | ft_putnbr_fd(n / 10, fd); 29 | n = (n % 10); 30 | ft_putchar_fd(n + '0', fd); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/02 00:25:38 by gleal #+# #+# */ 9 | /* Updated: 2021/02/02 02:22:49 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | i = 0; 21 | j = 0; 22 | while (dst[i]) 23 | i++; 24 | while (i + j + 1 < dstsize && src[j]) 25 | { 26 | dst[i + j] = src[j]; 27 | j++; 28 | } 29 | dst[i + j] = '\0'; 30 | while (src[j]) 31 | j++; 32 | if (i >= dstsize) 33 | return (j + dstsize); 34 | else 35 | return (j + i); 36 | } 37 | -------------------------------------------------------------------------------- /libft/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/30 17:58:53 by gleal #+# #+# */ 9 | /* Updated: 2021/02/11 22:43:25 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dst, const void *src, size_t len) 16 | { 17 | unsigned char *destn; 18 | unsigned char *sourc; 19 | int i; 20 | 21 | destn = (unsigned char*)dst; 22 | sourc = (unsigned char*)src; 23 | i = len - 1; 24 | if (sourc < destn) 25 | { 26 | while (i >= 0) 27 | { 28 | destn[i] = sourc[i]; 29 | i--; 30 | } 31 | } 32 | else 33 | ft_memcpy(dst, src, len); 34 | return (dst); 35 | } 36 | -------------------------------------------------------------------------------- /libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/08 00:43:32 by gleal #+# #+# */ 9 | /* Updated: 2021/02/12 01:41:48 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | unsigned int len; 18 | char *str; 19 | unsigned int i; 20 | 21 | if (!s || !f) 22 | return (0); 23 | len = ft_strlen(s); 24 | i = 0; 25 | str = malloc(sizeof(char) * len + 1); 26 | if (!str) 27 | return (0); 28 | while (i < len) 29 | { 30 | str[i] = f(i, s[i]); 31 | i++; 32 | } 33 | str[i] = '\0'; 34 | return (str); 35 | } 36 | -------------------------------------------------------------------------------- /libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/03 00:50:00 by gleal #+# #+# */ 9 | /* Updated: 2021/02/12 00:17:48 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_atoi(const char *str) 16 | { 17 | int sign; 18 | int number; 19 | 20 | sign = 1; 21 | number = 0; 22 | while (*str == ' ' || (*str >= 9 && *str <= 13)) 23 | str++; 24 | if (*str == '+') 25 | str++; 26 | else if (*str == '-') 27 | { 28 | sign *= -1; 29 | str++; 30 | } 31 | while (*str >= '0' && *str <= '9') 32 | { 33 | number = number * 10 + *str - '0'; 34 | str++; 35 | } 36 | return (number * sign); 37 | } 38 | -------------------------------------------------------------------------------- /mandatory_game/color_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* color_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/21 14:54:52 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:18 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int create_trgb(int t, int r, int g, int b) 16 | { 17 | return (t << 24 | r << 16 | g << 8 | b); 18 | } 19 | 20 | int get_t(int trgb) 21 | { 22 | return (trgb & (0xFF << 24)); 23 | } 24 | 25 | int get_r(int trgb) 26 | { 27 | return (trgb & (0xFF << 16)); 28 | } 29 | 30 | int get_g(int trgb) 31 | { 32 | return (trgb & (0xFF << 8)); 33 | } 34 | 35 | int get_b(int trgb) 36 | { 37 | return (trgb & 0xFF); 38 | } 39 | -------------------------------------------------------------------------------- /libft/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/11 00:12:40 by gleal #+# #+# */ 9 | /* Updated: 2021/02/12 02:19:04 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 16 | { 17 | t_list *new; 18 | t_list *first_l; 19 | 20 | if (!lst || !f) 21 | return (0); 22 | first_l = 0; 23 | while (lst) 24 | { 25 | new = ft_lstnew(f(lst->content)); 26 | if (!new) 27 | { 28 | ft_lstclear(&first_l, del); 29 | return (0); 30 | } 31 | ft_lstadd_back(&first_l, new); 32 | lst = lst->next; 33 | } 34 | return (first_l); 35 | } 36 | -------------------------------------------------------------------------------- /libft/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/29 01:34:43 by gleal #+# #+# */ 9 | /* Updated: 2021/01/29 03:14:50 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memccpy(void *dst, const void *src, int c, size_t n) 16 | { 17 | unsigned char *destn; 18 | unsigned char *sourc; 19 | unsigned char ch; 20 | size_t i; 21 | 22 | destn = (unsigned char*)dst; 23 | sourc = (unsigned char*)src; 24 | ch = (unsigned char)c; 25 | i = 0; 26 | while (i < n) 27 | { 28 | destn[i] = sourc[i]; 29 | if (destn[i] == ch) 30 | return (&dst[i + 1]); 31 | i++; 32 | } 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /libft/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/04 17:26:57 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 16:33:18 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoin(char const *s1, char const *s2) 16 | { 17 | char *str; 18 | size_t count; 19 | size_t j; 20 | 21 | if (!s1 || !s2) 22 | return (0); 23 | count = ft_strlen(s1) + ft_strlen(s2); 24 | j = 0; 25 | str = (char *)malloc(sizeof(char) * (count + 1)); 26 | if (!str) 27 | return (0); 28 | while (*s1) 29 | str[j++] = *(s1++); 30 | while (*s2) 31 | str[j++] = *(s2++); 32 | str[j] = '\0'; 33 | return (str); 34 | } 35 | -------------------------------------------------------------------------------- /mandatory_game/ft_initdestroyimg.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_initdestroyimg.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 17:03:49 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 16:29:57 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int destroyimg(t_adata *a, t_img *img) 16 | { 17 | mlx_destroy_image(a->win.mlx, img->ptr); 18 | img->ptr = 0; 19 | img->addr = 0; 20 | return (0); 21 | } 22 | 23 | void ftinit_img_3d(t_adata *a) 24 | { 25 | a->img_3d.ptr = mlx_new_image(a->win.mlx, a->win.win_w, a->win.win_h); 26 | a->img_3d.addr = (int *)mlx_get_data_addr(a->img_3d.ptr, 27 | &a->img_3d.pixel_bits, &a->img_3d.line_bytes, &a->img_3d.endian); 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/02 19:30:37 by gleal #+# #+# */ 9 | /* Updated: 2021/02/11 22:39:56 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *haystack, const char *needle, size_t len) 16 | { 17 | char *s1; 18 | char *s2; 19 | size_t i; 20 | size_t j; 21 | 22 | s1 = (char *)haystack; 23 | s2 = (char *)needle; 24 | i = 0; 25 | if (!*s2) 26 | return (s1); 27 | while (i < len && s1[i]) 28 | { 29 | j = 0; 30 | while (i + j < len && s1[i + j] && s2[j] && s1[i + j] == s2[j]) 31 | j++; 32 | if (s2[j] == '\0') 33 | return (&s1[i]); 34 | i++; 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /minilibx/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 | -------------------------------------------------------------------------------- /other_utils/free_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* free_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/21 20:41:51 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 16:04:07 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | 15 | void clean_sprites(t_adata *a, t_sps *sps) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (i < sps->number) 21 | { 22 | destroyimg(a, &sps->items[i].imgsp); 23 | i++; 24 | } 25 | free(sps->items); 26 | } 27 | 28 | void *ft_freetext(char **text) 29 | { 30 | size_t i; 31 | 32 | i = 0; 33 | while (text[i]) 34 | { 35 | free(text[i]); 36 | i++; 37 | } 38 | free(text); 39 | return (0); 40 | } 41 | 42 | void free_all_strs(char **strs) 43 | { 44 | while (*strs) 45 | { 46 | free(*strs); 47 | strs++; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libft/get_next_line.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/12 19:04:24 by gleal #+# #+# */ 9 | /* Updated: 2021/03/27 18:38:47 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_H 14 | # define GET_NEXT_LINE_H 15 | 16 | # ifndef BUFFER_SIZE 17 | # define BUFFER_SIZE 64 18 | # endif 19 | 20 | # include 21 | # include 22 | # include 23 | # include 24 | 25 | char *ft_strnew(size_t size); 26 | size_t ft_strlen(const char *s); 27 | char *ft_strchr(const char *s, int c); 28 | char *ft_strdup(const char *s1); 29 | char *ft_strjoin(char const *s1, char const *s2); 30 | char *ft_substr(char const *s, unsigned int start, size_t len); 31 | int get_next_line(int fd, char **line); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libft/ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/04 01:03:42 by gleal #+# #+# */ 9 | /* Updated: 2021/02/08 00:11:33 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_substr(char const *s, unsigned int start, size_t len) 16 | { 17 | size_t i; 18 | char *str; 19 | size_t length; 20 | 21 | length = len; 22 | i = 0; 23 | if (!s) 24 | return (0); 25 | if (ft_strlen(s) - start <= length) 26 | length = ft_strlen(s) - start; 27 | if (ft_strlen(s) <= start) 28 | { 29 | start = 0; 30 | length = 0; 31 | } 32 | str = (char *)malloc(sizeof(char) * (length + 1)); 33 | if (!str) 34 | return (0); 35 | while (s[start] && length--) 36 | str[i++] = s[start++]; 37 | str[i] = '\0'; 38 | return (str); 39 | } 40 | -------------------------------------------------------------------------------- /bonus_game/cub3d_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cub3d_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 17:40:54 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 18:17:03 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | void cub3d(char *cubname) 16 | { 17 | int fd; 18 | t_adata a; 19 | 20 | ft_start_tmap(&a.parse); 21 | fd = open(cubname, O_RDONLY); 22 | cub_extract(&a.parse, fd); 23 | if (a.parse.error) 24 | { 25 | printf("there was an error while extracting"); 26 | return ; 27 | } 28 | if (!ft_parse_cub(a.parse.text, &a.parse)) 29 | return ; 30 | start_game(&a); 31 | } 32 | 33 | int main(int argc, char **argv) 34 | { 35 | if (argc < 2) 36 | printf("You forgot the cub file name"); 37 | else if (argc == 2) 38 | cub3d(argv[1]); 39 | else 40 | printf("WRONG"); 41 | } 42 | -------------------------------------------------------------------------------- /includes/cub3d.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cub3d.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/02 15:13:07 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 20:01:41 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CUB3D_H 14 | # define CUB3D_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | # include 23 | # include 24 | # include 25 | # include "../libft/libft.h" 26 | # include "../libft/get_next_line.h" 27 | # include "../minilibx/mlx.h" 28 | # include "structs.h" 29 | # include "ft_parse.h" 30 | # include "start_game.h" 31 | 32 | # define MAX_X_SIZE 2560 33 | # define MAX_Y_SIZE 1440 34 | # define MAP_CHARS "012NSEW" 35 | # define MAP_INSIDE "02NSEW" 36 | # define PLAYER "NSEW" 37 | 38 | int is_cubfile(char *file); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/07 17:36:51 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:31:08 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int ft_abs(int n) 16 | { 17 | if (n < 0) 18 | return (-n); 19 | return (n); 20 | } 21 | 22 | static int ft_ln_itoa(int n) 23 | { 24 | int ln; 25 | 26 | ln = 0; 27 | if (n <= 0) 28 | ln++; 29 | while (n != 0) 30 | { 31 | ln++; 32 | n /= 10; 33 | } 34 | return (ln); 35 | } 36 | 37 | char *ft_itoa(int n) 38 | { 39 | char *str; 40 | int ln; 41 | 42 | ln = ft_ln_itoa(n); 43 | str = malloc(sizeof(char) * (ln + 1)); 44 | if (!str) 45 | return (0); 46 | str[ln] = '\0'; 47 | if (n < 0) 48 | str[0] = '-'; 49 | else if (n == 0) 50 | str[0] = '0'; 51 | while (n != 0) 52 | { 53 | ln--; 54 | str[ln] = ft_abs(n % 10) + '0'; 55 | n /= 10; 56 | } 57 | return (str); 58 | } 59 | -------------------------------------------------------------------------------- /libft/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/04 18:28:32 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:31:40 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int is_in_set(char c, char *set) 16 | { 17 | while (*set) 18 | { 19 | if (c == *(set)) 20 | return (1); 21 | set++; 22 | } 23 | return (0); 24 | } 25 | 26 | char *ft_strtrim(char const *s1, char const *set) 27 | { 28 | int start; 29 | int end; 30 | int i; 31 | char *str; 32 | 33 | if (!s1 || !set) 34 | return (0); 35 | start = 0; 36 | while (is_in_set(s1[start], (char *)set) && s1[start]) 37 | start++; 38 | end = ft_strlen(s1); 39 | while (is_in_set(s1[end - 1], (char *)set) && start < end) 40 | end--; 41 | str = malloc(sizeof(char) * (end - start + 1)); 42 | if (!str) 43 | return (0); 44 | i = 0; 45 | while (start < end) 46 | str[i++] = s1[start++]; 47 | str[i] = '\0'; 48 | return (str); 49 | } 50 | -------------------------------------------------------------------------------- /mandatory_game/horiz_vert_raycomp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* horiz_vert_raycomp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/19 16:01:04 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:19 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | void horiz_vert_raycomp(t_adata *a, t_ray *ray, 16 | double *horz_dist, double *vert_dist) 17 | { 18 | if (ray->found_hor_wall) 19 | *horz_dist = distancepoints(a->joe.x, a->joe.y, 20 | ray->wall_hit_horx, ray->wall_hit_hory); 21 | else 22 | *horz_dist = INT_MAX; 23 | if (ray->found_ver_wall) 24 | *vert_dist = distancepoints(a->joe.x, a->joe.y, 25 | ray->wall_hit_verx, ray->wall_hit_very); 26 | else 27 | *vert_dist = INT_MAX; 28 | if (*horz_dist < *vert_dist) 29 | { 30 | ray->wall_hit_x = ray->wall_hit_horx; 31 | ray->wall_hit_y = ray->wall_hit_hory; 32 | ray->distance = *horz_dist; 33 | ray->hit_vertical = 0; 34 | } 35 | else 36 | { 37 | ray->wall_hit_x = ray->wall_hit_verx; 38 | ray->wall_hit_y = ray->wall_hit_very; 39 | ray->distance = *vert_dist; 40 | ray->hit_vertical = 1; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /minilibx/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 | -------------------------------------------------------------------------------- /bonus_game/start_game_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* start_game_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 17:52:37 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:04:36 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | void ft_init_all(t_adata *a) 16 | { 17 | ftinit_win(a); 18 | ftinit_map(a); 19 | ftinit_player(a); 20 | ftinit_texts(a); 21 | ftinit_rays(a); 22 | ftinit_sprites(a); 23 | ft_init_animation(a); 24 | } 25 | 26 | int render_next_frame(t_adata *a) 27 | { 28 | ftinit_img_3d(a); 29 | ft_update_player(a); 30 | update_sprites(a); 31 | draw_ceilingrgb(a); 32 | draw3d(a); 33 | draw_map(a); 34 | pickaxe_animation(a); 35 | mlx_put_image_to_window(a->win.mlx, a->win.win, a->img_3d.ptr, 0, 0); 36 | destroyimg(a, &a->img_3d); 37 | return (0); 38 | } 39 | 40 | int start_game(t_adata *a) 41 | { 42 | ft_init_all(a); 43 | mlx_do_key_autorepeatoff(a->win.mlx); 44 | mlx_hook(a->win.win, 2, 1L << 0, &butt_pressed, a); 45 | mlx_hook(a->win.win, 3, 1L << 1, &butt_released, a); 46 | mlx_hook(a->win.win, 17, 1L << 17, &clicked_cross, a); 47 | mlx_loop_hook(a->win.mlx, &render_next_frame, a); 48 | mlx_loop(a->win.mlx); 49 | return (1); 50 | } 51 | -------------------------------------------------------------------------------- /mandatory_game/start_game.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* start_game.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/08 15:20:19 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:41:47 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | /* overview of the drawing operations */ 15 | void ft_init_all(t_adata *a) 16 | { 17 | ftinit_win(a); 18 | ftinit_map(a); 19 | ftinit_player(a); 20 | ftinit_texts(a); 21 | ftinit_rays(a); 22 | ftinit_sprites(a); 23 | } 24 | 25 | int render_next_frame(t_adata *a) 26 | { 27 | ftinit_img_3d(a); 28 | ft_update_player(a); 29 | update_sprites(a); 30 | draw_floorrgb(a); 31 | draw_ceilingrgb(a); 32 | draw3d(a); 33 | draw_map(a); 34 | mlx_put_image_to_window(a->win.mlx, a->win.win, a->img_3d.ptr, 0, 0); 35 | destroyimg(a, &a->img_3d); 36 | return (0); 37 | } 38 | 39 | int start_game(t_adata *a) 40 | { 41 | ft_init_all(a); 42 | mlx_do_key_autorepeatoff(a->win.mlx); 43 | mlx_hook(a->win.win, 2, 1L << 0, &butt_pressed, a); 44 | mlx_hook(a->win.win, 3, 1L << 1, &butt_released, a); 45 | mlx_hook(a->win.win, 17, 1L << 17, &clicked_cross, a); 46 | mlx_loop_hook(a->win.mlx, &render_next_frame, a); 47 | mlx_loop(a->win.mlx); 48 | return (1); 49 | } 50 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_map2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_map2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 18:05:01 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:05:40 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* copying the map to better use the x and y coordinates */ 15 | int ft_copy_map(char **map_start, t_parse *parse) 16 | { 17 | char **temp; 18 | int i; 19 | 20 | i = 0; 21 | temp = malloc(sizeof(char*) * (parse->nbr_str + 2)); 22 | if (!temp) 23 | { 24 | ft_freetext(parse->text); 25 | return (0); 26 | } 27 | while (is_map(map_start[i])) 28 | { 29 | temp[i] = ft_strdup(map_start[i]); 30 | if (!temp[i]) 31 | { 32 | ft_freetext(parse->text); 33 | ft_free_to_str(&temp, i - 1); 34 | return (0); 35 | } 36 | i++; 37 | } 38 | temp[i] = NULL; 39 | parse->mapstr = temp; 40 | return (1); 41 | } 42 | /* If I try to assign the player orientation more than once there's an error */ 43 | int checkmultiplayer(char *str, t_parse *parse) 44 | { 45 | while (*str) 46 | { 47 | if (ft_strchr(PLAYER, *str)) 48 | { 49 | if (!parse->player_or) 50 | parse->player_or = *str; 51 | else 52 | return (0); 53 | } 54 | str++; 55 | } 56 | return (1); 57 | } 58 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_resolution.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_resolution.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 18:03:35 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:07:22 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* extracting the window dimensions and using atoi to turn them into ints */ 15 | int ft_screensize(char *str, t_parse *parse) 16 | { 17 | int i; 18 | 19 | i = 1; 20 | while (ft_isspace(str[i])) 21 | i++; 22 | parse->rx = ft_atoi(&str[i]); 23 | while (ft_isdigit(str[i])) 24 | i++; 25 | while (ft_isspace(str[i])) 26 | i++; 27 | parse->ry = ft_atoi(&str[i]); 28 | if (parse->rx <= 0 || parse->ry <= 0 || 29 | parse->rx > MAX_X_SIZE || parse->ry > MAX_Y_SIZE) 30 | return (0); 31 | return (1); 32 | } 33 | /* confirming that there are not multiple resolutions in the cub and that the dimensions 34 | are not bigger than the school computers*/ 35 | int check_resolution(char **text, t_parse *parse, int *i, int *count) 36 | { 37 | if (text[(*i)][0] == 'R') 38 | { 39 | if (parse->rx || parse->ry) 40 | return (ft_error(MULTIRES)); 41 | if (!ft_screensize(text[(*i)], parse)) 42 | return (ft_error(BADSCREEN)); 43 | (*count)++; 44 | (*i)++; 45 | } 46 | return (1); 47 | } 48 | -------------------------------------------------------------------------------- /cub3d.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cub3d.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/02 15:01:37 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 20:11:25 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | 15 | int cub3d(char *cubname) 16 | { 17 | int fd; 18 | t_adata a; 19 | 20 | ft_start_tmap(&a.parse); 21 | fd = open(cubname, O_RDONLY); 22 | if (fd <= 0) 23 | return (ft_error(INVALID_FILE)); 24 | cub_extract(&a.parse, fd); 25 | if (a.parse.error) 26 | { 27 | printf("there was an error while extracting"); 28 | return (0); 29 | } 30 | if (!ft_parse_cub(a.parse.text, &a.parse)) 31 | { 32 | ft_freetext(a.parse.text); 33 | free_all_texts(&a.parse); 34 | return (0); 35 | } 36 | start_game(&a); 37 | return (1); 38 | } 39 | 40 | int main(int argc, char **argv) 41 | { 42 | if (argc < 2) 43 | printf("You forgot the cub file name"); 44 | else if (argc == 2) 45 | { 46 | if (!is_cubfile(argv[1])) 47 | return (ft_error(NOT_CUB_ERROR)); 48 | cub3d(argv[1]); 49 | } 50 | else if (argc == 3) 51 | { 52 | if (!(ft_strncmp("--save", argv[2], ft_strlen(argv[2]))) && 53 | ft_strlen(argv[2]) == 6) 54 | screenshot(argv[1]); 55 | else 56 | printf("WRONG"); 57 | } 58 | else 59 | printf("WRONG"); 60 | } 61 | -------------------------------------------------------------------------------- /bonus_game/bitmap_offsets_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* bitmap_offsets_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 17:50:38 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:01:31 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | int bitmap_offset_floor(t_adata *a, double *x, double *y) 16 | { 17 | while (*x >= 1) 18 | (*x)--; 19 | while (*y >= 1) 20 | (*y)--; 21 | if (*x >= 0) 22 | *x = *x * a->sotext.imgt.width; 23 | if (*y >= 0) 24 | *y = *y * a->sotext.imgt.height; 25 | return (0); 26 | } 27 | 28 | int bitmap_offset_sp(t_item *item, int col_id) 29 | { 30 | double remainder; 31 | double offset; 32 | 33 | remainder = (double)(((double)col_id - item->xstart) / item->sprite_w); 34 | offset = item->imgsp.width * remainder; 35 | return (offset); 36 | } 37 | 38 | int bitmap_offset(t_ray *ray, t_adata *a) 39 | { 40 | double ray_x; 41 | double ray_y; 42 | double remainder; 43 | int offset; 44 | 45 | ray_x = ray->wall_hit_x / a->map.tile_size; 46 | ray_y = ray->wall_hit_y / a->map.tile_size; 47 | if (ray->hit_vertical) 48 | { 49 | remainder = ray_y - floor(ray_y); 50 | offset = a->notext.imgt.width * remainder; 51 | } 52 | else 53 | { 54 | remainder = ray_x - floor(ray_x); 55 | offset = a->notext.imgt.width * remainder; 56 | } 57 | return (offset); 58 | } 59 | -------------------------------------------------------------------------------- /libft/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: gleal +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/02/09 15:43:58 by gleal #+# #+# # 9 | # Updated: 2021/03/06 15:32:18 by gleal ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | CC = gcc 14 | FLAGS = -Wall -Wextra -Werror 15 | NAME = libft.a 16 | SRCS = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c ft_strlcpy.c ft_strlcat.c ft_strchr.c \ 17 | ft_strrchr.c ft_strnstr.c ft_strncmp.c ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.c \ 18 | ft_calloc.c ft_strdup.c \ 19 | ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \ 20 | ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c \ 21 | ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c \ 22 | ft_lstiter.c ft_lstmap.c \ 23 | get_next_line.c get_next_line_utils.c 24 | 25 | OBJS = $(SRCS:.c=.o) 26 | 27 | all: $(NAME) 28 | 29 | %.o : %.c 30 | $(CC) $(FLAGS) -c $< -o $@ 31 | 32 | $(NAME) : $(OBJS) 33 | ar -rc $(NAME) $(OBJS) 34 | 35 | bonus: $(OBJS) 36 | ar -rc $(NAME) $^ 37 | 38 | clean: 39 | rm -f $(OBJS) 40 | 41 | fclean: clean 42 | rm -f $(NAME) 43 | 44 | re: fclean all 45 | 46 | 47 | 48 | .PHONY: all clean fclean re 49 | -------------------------------------------------------------------------------- /mandatory_game/start_game_utils3.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* raycast_utils3.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 17:52:40 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:20 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int is_sprite_stripe(t_item *item, int col_id) 16 | { 17 | if (col_id >= item->xstart && col_id <= item->xend) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | 23 | int add_sprites(t_item *items, char **strs, t_adata *a) 24 | { 25 | int i; 26 | int j; 27 | int nbr; 28 | 29 | i = 0; 30 | j = 0; 31 | nbr = 0; 32 | while (strs[i]) 33 | { 34 | j = 0; 35 | while (strs[i][j]) 36 | { 37 | if (strs[i][j] == '2') 38 | { 39 | items[nbr].x = (double)(j + 0.5) * a->map.tile_size; 40 | items[nbr].y = (double)(i + 0.5) * a->map.tile_size; 41 | ftinittext(a, &items[nbr].imgsp, a->parse.sprite_text); 42 | nbr++; 43 | } 44 | j++; 45 | } 46 | i++; 47 | } 48 | return (0); 49 | } 50 | 51 | int ft_countsprites(char **strs) 52 | { 53 | int i; 54 | int j; 55 | int counter; 56 | 57 | i = 0; 58 | j = 0; 59 | counter = 0; 60 | while (strs[i]) 61 | { 62 | j = 0; 63 | while (strs[i][j]) 64 | { 65 | if (strs[i][j] == '2') 66 | counter++; 67 | j++; 68 | } 69 | i++; 70 | } 71 | return (counter); 72 | } 73 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_utils2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_utils2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 18:13:39 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 20:12:03 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | 15 | int is_cubfile(char *file) 16 | { 17 | int i; 18 | 19 | i = ft_strlen(file) - 1; 20 | if (file[i--] != 'b') 21 | return (0); 22 | if (file[i--] != 'u') 23 | return (0); 24 | if (file[i--] != 'c') 25 | return (0); 26 | if (file[i] != '.') 27 | return (0); 28 | return (1); 29 | } 30 | 31 | void ft_free_to_str(char ***strs, int prev) 32 | { 33 | if (prev < 0) 34 | { 35 | free(*strs); 36 | return ; 37 | } 38 | while (prev >= 0) 39 | { 40 | free(strs[0][prev]); 41 | strs[0][prev] = 0; 42 | prev--; 43 | } 44 | free(*strs); 45 | } 46 | 47 | void free_texture(char **texture) 48 | { 49 | if (*texture) 50 | { 51 | free(*texture); 52 | *texture = 0; 53 | } 54 | } 55 | 56 | void free_all_texts(t_parse *parse) 57 | { 58 | free_texture(&parse->no_text); 59 | free_texture(&parse->so_text); 60 | free_texture(&parse->we_text); 61 | free_texture(&parse->ea_text); 62 | free_texture(&parse->sprite_text); 63 | } 64 | 65 | void ft_init_textures(t_parse *parse) 66 | { 67 | parse->no_text = 0; 68 | parse->so_text = 0; 69 | parse->we_text = 0; 70 | parse->ea_text = 0; 71 | parse->sprite_text = 0; 72 | } 73 | -------------------------------------------------------------------------------- /bonus_game/update_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* update_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 21:45:24 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 21:45:36 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | void update_position(t_adata *a) 16 | { 17 | double movestep; 18 | double next_playerx; 19 | double next_playery; 20 | double move_angle; 21 | 22 | if (a->joe.walkdir == 0) 23 | return ; 24 | move_angle = a->joe.rotangle; 25 | if (a->joe.walkdir == 'w') 26 | move_angle = normalrad(move_angle); 27 | else if (a->joe.walkdir == 's') 28 | move_angle = normalrad(move_angle + M_PI); 29 | else if (a->joe.walkdir == 'a') 30 | move_angle = normalrad(move_angle - M_PI_2); 31 | else if (a->joe.walkdir == 'd') 32 | move_angle = normalrad(move_angle + M_PI_2); 33 | movestep = a->joe.movespeed * a->map.tile_size; 34 | next_playerx = a->joe.x + (cos(move_angle) * movestep); 35 | next_playery = a->joe.y + (sin(move_angle) * movestep); 36 | if (!has_wall(next_playerx, next_playery, a)) 37 | { 38 | a->joe.x = next_playerx; 39 | a->joe.y = next_playery; 40 | } 41 | } 42 | 43 | void update_orientation(t_adata *a) 44 | { 45 | if (a->joe.turndir == 0) 46 | return ; 47 | a->joe.rotangle = normalrad(a->joe.rotangle + 48 | (a->joe.turndir * a->joe.rotatespeed)); 49 | } 50 | 51 | void ft_update_player(t_adata *a) 52 | { 53 | update_orientation(a); 54 | update_position(a); 55 | } 56 | -------------------------------------------------------------------------------- /bonus_game/utils_attack_pickaxe_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_utils_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 16:06:15 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:44:25 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | int calc_texy_attack(double small_dist, double big_dist, t_adata *a) 16 | { 17 | int result; 18 | 19 | result = (int)((small_dist / big_dist) * (a->eatext.imgt.height - 1)); 20 | return (result); 21 | } 22 | 23 | int calc_texx_attack(double small_dist, double big_dist, t_adata *a) 24 | { 25 | int result; 26 | 27 | result = (int)((small_dist / big_dist) * (a->eatext.imgt.width - 1)); 28 | return (result); 29 | } 30 | 31 | void draw_attack_pickaxe(t_adata *a) 32 | { 33 | double p_w; 34 | double p_h; 35 | int m_y; 36 | int m_x; 37 | 38 | p_h = a->map.map_b_half; 39 | while ((int)p_h < a->win.win_h) 40 | { 41 | p_w = a->map.map_r_half; 42 | while ((int)p_w < a->win.win_w) 43 | { 44 | m_y = calc_texy_attack(p_h - a->map.map_b_half, 45 | a->win.win_h - 1 - a->map.map_b_half, a); 46 | m_x = calc_texx_attack(p_w - a->map.map_r_half, 47 | a->win.win_w - 1 - a->map.map_r_half, a); 48 | if (a->eatext.imgt.addr[m_y * a->eatext.imgt.width + m_x]) 49 | { 50 | a->img_3d.addr[(int)(int)p_h * (int)a->win.win_w + (int)p_w] = 51 | a->eatext.imgt.addr[m_y * a->eatext.imgt.width + m_x]; 52 | } 53 | p_w++; 54 | } 55 | p_h++; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /bonus_game/utils_normal_pickaxe_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* utils_normal_pickaxe.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 17:06:06 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:43:35 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | int calc_texy_normal(double small_dist, double big_dist, t_adata *a) 16 | { 17 | int result; 18 | 19 | result = (int)((small_dist / big_dist) * (a->wetext.imgt.height - 1)); 20 | return (result); 21 | } 22 | 23 | int calc_texx_normal(double small_dist, double big_dist, t_adata *a) 24 | { 25 | int result; 26 | 27 | result = (int)((small_dist / big_dist) * (a->wetext.imgt.width - 1)); 28 | return (result); 29 | } 30 | 31 | void draw_normal_pickaxe(t_adata *a) 32 | { 33 | double p_w; 34 | double p_h; 35 | int m_y; 36 | int m_x; 37 | 38 | p_h = a->map.map_b_half; 39 | while ((int)p_h < a->win.win_h) 40 | { 41 | p_w = a->map.map_r_half; 42 | while ((int)p_w < a->win.win_w) 43 | { 44 | m_y = calc_texy_normal(p_h - a->map.map_b_half, 45 | a->win.win_h - 1 - a->map.map_b_half, a); 46 | m_x = calc_texx_normal(p_w - a->map.map_r_half, 47 | a->win.win_w - 1 - a->map.map_r_half, a); 48 | if (a->wetext.imgt.addr[m_y * a->wetext.imgt.width + m_x]) 49 | { 50 | a->img_3d.addr[(int)(int)p_h * (int)a->win.win_w + (int)p_w] = 51 | a->wetext.imgt.addr[m_y * a->wetext.imgt.width + m_x]; 52 | } 53 | p_w++; 54 | } 55 | p_h++; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /minilibx/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/03/18 17:27:38 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:30:20 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | /* before I calculated the beginning and end of each sprite on the screen. as well as their width 15 | So if the col_id / width x strip is the same as the start we will assign them the start of the sprite texture */ 16 | int bitmap_offset_sp(t_item *item, int col_id) 17 | { 18 | double remainder; 19 | double offset; 20 | 21 | remainder = (double)(((double)col_id - item->xstart) / item->sprite_w); 22 | offset = (item->imgsp.width - 1) * remainder; 23 | return (offset); 24 | } 25 | /* Here I converted the map_tile_size to 1 so that we could use the floor function to calculate the right part of the texture 26 | E.g. If we were in x = 5 and tile size is 2. After conversion x = 2.5. Floor (2.5) = 2 27 | 2.5 - 2 = 0.5 so we are pointing at the middle of the texture. */ 28 | int bitmap_offset(t_ray *ray, t_adata *a) 29 | { 30 | double ray_x; 31 | double ray_y; 32 | double remainder; 33 | int offset; 34 | 35 | ray_x = ray->wall_hit_x / a->map.tile_size; 36 | ray_y = ray->wall_hit_y / a->map.tile_size; 37 | if (ray->hit_vertical) 38 | { 39 | remainder = ray_y - floor(ray_y); 40 | offset = (ray->text_wallhit.imgt.width - 1) * remainder; 41 | } 42 | else 43 | { 44 | remainder = ray_x - floor(ray_x); 45 | offset = (ray->text_wallhit.imgt.width - 1) * remainder; 46 | } 47 | return (offset); 48 | } 49 | -------------------------------------------------------------------------------- /mandatory_game/update.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* update.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/10 19:02:02 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:46:19 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | /* PI is the same as 180 degrees so you're going backwards 15 | PI/2 is the same as 90 degrees to the right 16 | -PI/2 is the same as -90 degrees or the same as 90 degrees to the left */ 17 | void update_position(t_adata *a) 18 | { 19 | double movestep; 20 | double next_playerx; 21 | double next_playery; 22 | double move_angle; 23 | 24 | if (a->joe.walkdir == 0) 25 | return ; 26 | move_angle = a->joe.rotangle; 27 | if (a->joe.walkdir == 'w') 28 | move_angle = normalrad(move_angle); 29 | else if (a->joe.walkdir == 's') 30 | move_angle = normalrad(move_angle + M_PI); 31 | else if (a->joe.walkdir == 'a') 32 | move_angle = normalrad(move_angle - M_PI_2); 33 | else if (a->joe.walkdir == 'd') 34 | move_angle = normalrad(move_angle + M_PI_2); 35 | movestep = a->joe.movespeed * a->map.tile_size; 36 | next_playerx = a->joe.x + (cos(move_angle) * movestep); 37 | next_playery = a->joe.y + (sin(move_angle) * movestep); 38 | if (!has_wall(next_playerx, next_playery, a)) 39 | { 40 | a->joe.x = next_playerx; 41 | a->joe.y = next_playery; 42 | } 43 | } 44 | 45 | void update_orientation(t_adata *a) 46 | { 47 | if (a->joe.turndir == 0) 48 | return ; 49 | a->joe.rotangle = normalrad(a->joe.rotangle + 50 | (a->joe.turndir * a->joe.rotatespeed)); 51 | } 52 | 53 | void ft_update_player(t_adata *a) 54 | { 55 | update_orientation(a); 56 | update_position(a); 57 | } 58 | -------------------------------------------------------------------------------- /mandatory_game/ft_init.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_init.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/08 17:40:35 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:18 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int ftinit_sprites(t_adata *a) 16 | { 17 | a->sps.number = ft_countsprites(a->map.maptxt); 18 | a->sps.items = malloc(sizeof(t_item) * (a->sps.number)); 19 | add_sprites(a->sps.items, a->map.maptxt, a); 20 | return (0); 21 | } 22 | 23 | int ftinit_texts(t_adata *a) 24 | { 25 | ftinittext(a, &a->notext.imgt, a->parse.no_text); 26 | ftinittext(a, &a->sotext.imgt, a->parse.so_text); 27 | ftinittext(a, &a->wetext.imgt, a->parse.we_text); 28 | ftinittext(a, &a->eatext.imgt, a->parse.ea_text); 29 | return (0); 30 | } 31 | 32 | void ftinit_player(t_adata *a) 33 | { 34 | ft_playerinfo(&a->map, &a->joe, a->map.maptxt); 35 | a->joe.radius = a->map.tile_size / 6; 36 | a->joe.turndir = 0; 37 | a->joe.walkdir = 0; 38 | a->joe.movespeed = 0.35; 39 | a->joe.rotatespeed = 7 * (M_PI / 180); 40 | } 41 | 42 | void ftinit_map(t_adata *a) 43 | { 44 | a->map.maptxt = a->parse.mapstr; 45 | a->map.map_rows = ft_count_lines(a->map.maptxt); 46 | a->map.map_cols = ft_max_strlen(a->map.maptxt); 47 | a->map.tile_size = calculate_tilesize(a); 48 | a->map.map_h = a->map.map_rows * a->map.tile_size; 49 | a->map.map_w = a->map.map_cols * a->map.tile_size; 50 | } 51 | 52 | void ftinit_win(t_adata *a) 53 | { 54 | a->win.mlx = mlx_init(); 55 | a->win.win_w = a->parse.rx; 56 | a->win.win_h = a->parse.ry; 57 | a->win.win = mlx_new_window(a->win.mlx, a->win.win_w, 58 | a->win.win_h, "Wolfenstein3D"); 59 | } 60 | -------------------------------------------------------------------------------- /mandatory_game/events.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* events.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/09 19:42:43 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:18 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | void cleanclose(t_adata *a) 16 | { 17 | free(a->parse.no_text); 18 | free(a->parse.so_text); 19 | free(a->parse.we_text); 20 | free(a->parse.ea_text); 21 | free(a->parse.sprite_text); 22 | clean_sprites(a, &a->sps); 23 | ft_freetext(a->parse.mapstr); 24 | mlx_destroy_window(a->win.mlx, a->win.win); 25 | exit(EXIT_SUCCESS); 26 | } 27 | 28 | int clicked_cross(int keycode, t_adata *a) 29 | { 30 | (void)keycode; 31 | (void)a; 32 | exit(EXIT_SUCCESS); 33 | return (0); 34 | } 35 | 36 | int butt_released(int keycode, t_adata *a) 37 | { 38 | if (keycode == W_KEY) 39 | a->joe.walkdir = 0; 40 | else if (keycode == S_KEY) 41 | a->joe.walkdir = 0; 42 | else if (keycode == A_KEY) 43 | a->joe.walkdir = 0; 44 | else if (keycode == D_KEY) 45 | a->joe.walkdir = 0; 46 | else if (keycode == RIGHT_ARROW) 47 | a->joe.turndir = 0; 48 | else if (keycode == LEFT_ARROW) 49 | a->joe.turndir = 0; 50 | return (0); 51 | } 52 | 53 | int butt_pressed(int keycode, t_adata *a) 54 | { 55 | if (keycode == ESC_KEY) 56 | cleanclose(a); 57 | if (keycode == W_KEY) 58 | a->joe.walkdir = 'w'; 59 | else if (keycode == S_KEY) 60 | a->joe.walkdir = 's'; 61 | else if (keycode == A_KEY) 62 | a->joe.walkdir = 'a'; 63 | else if (keycode == D_KEY) 64 | a->joe.walkdir = 'd'; 65 | else if (keycode == RIGHT_ARROW) 66 | a->joe.turndir = 1; 67 | else if (keycode == LEFT_ARROW) 68 | a->joe.turndir = -1; 69 | return (0); 70 | } 71 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_cub.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_cub.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/03 20:01:55 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:05:38 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* The reason I separated the map and the rest of the components is because on the Project PDF we had this sentence: 15 | 16 | "Except for the map content which always has to be the last, each type of 17 | element can be set in any order in the file." */ 18 | int all_but_map(char **text, t_parse *parse, int *i, int *count) 19 | { 20 | ft_init_textures(parse); 21 | while (text[(*i)] && (*count) < 8) 22 | { 23 | if (!check_resolution(text, parse, i, count) || 24 | !check_textures(text, parse, i, count) || 25 | !check_rgbs(text, parse, i, count)) 26 | return (0); 27 | if (!check_valid_chars(text, i)) 28 | return (ft_error(INVALIDCHAR)); 29 | if (text[(*i)][0] == '\0') 30 | (*i)++; 31 | } 32 | return (1); 33 | } 34 | /* Everytime there is a parsing error the function will return 0 35 | and go through the fr_error functions, which will printf an error message */ 36 | int ft_parse_cub(char **text, t_parse *parse) 37 | { 38 | int i; 39 | int count; 40 | 41 | count = 0; 42 | i = 0; 43 | if (!all_but_map(text, parse, &i, &count)) 44 | return (0); 45 | if (!text[i]) 46 | return (ft_error(MISSINGPARAMS)); 47 | while (!is_map(text[i]) && text[i]) 48 | i++; 49 | if (!text[i]) 50 | return (ft_error(INVALIDMAP)); 51 | if (!check_valid_map(&text[i], parse)) 52 | return (ft_error(INVALIDMAP)); 53 | while (is_map(text[i + 1]) && text[i]) 54 | i++; 55 | ft_freetext(parse->text); 56 | return (1); 57 | } 58 | -------------------------------------------------------------------------------- /bonus_game/draw_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 19:10:30 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:01:53 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | int draw3dline(double ray_angle, t_ray *ray, t_adata *a, int col_id) 16 | { 17 | ft_prepare_3d_line(ray_angle, ray, a, col_id); 18 | line3d(ray, a); 19 | return (0); 20 | } 21 | 22 | int draw_comp_circle(int p_w, int p_h, t_adata *a) 23 | { 24 | if (sqrt(pow(a->joe.x - p_w, 2) + pow(a->joe.y - p_h, 2)) <= a->joe.radius) 25 | a->img_3d.addr[(p_h * (int)a->win.win_w + p_w)] = 0xb87cb3; 26 | return (0); 27 | } 28 | 29 | int draw_comp_map(int p_w, int p_h, t_adata *a) 30 | { 31 | int cur_x; 32 | int cur_y; 33 | 34 | cur_x = (int)p_w / a->map.tile_size; 35 | cur_y = (int)p_h / a->map.tile_size; 36 | if (cur_x >= (int)ft_strlen(a->map.maptxt[cur_y])) 37 | return (0); 38 | else if (a->map.maptxt[cur_y][cur_x] == '1') 39 | a->img_3d.addr[(int)(p_h * (int)a->win.win_w + p_w)] = 0x85b569; 40 | else if (ft_strchr("02NSWE", a->map.maptxt[cur_y][cur_x])) 41 | a->img_3d.addr[(int)(p_h * (int)a->win.win_w + p_w)] = 0xebdbb7; 42 | else 43 | return (0); 44 | return (1); 45 | } 46 | 47 | int draw_comp(t_adata *a, int (*comp)(int, int, t_adata *)) 48 | { 49 | int pixel_w; 50 | int pixel_h; 51 | 52 | pixel_h = 0; 53 | while (pixel_h < a->map.map_h) 54 | { 55 | pixel_w = 0; 56 | while (pixel_w < a->map.map_w) 57 | { 58 | comp(pixel_w, pixel_h, a); 59 | pixel_w++; 60 | } 61 | pixel_h++; 62 | } 63 | return (0); 64 | } 65 | 66 | int draw_map(t_adata *a) 67 | { 68 | draw_comp(a, &draw_comp_map); 69 | draw_comp(a, &draw_comp_circle); 70 | ft_initline(a); 71 | line(a->line, a); 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /mandatory_game/draw.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/11 20:57:10 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:18 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int draw3dline(double ray_angle, t_ray *ray, t_adata *a, int col_id) 16 | { 17 | ft_prepare_3d_line(ray_angle, ray, a, col_id); 18 | line3d(ray, a, ray->text_wallhit); 19 | return (0); 20 | } 21 | 22 | int draw_comp_circle(int p_w, int p_h, t_adata *a) 23 | { 24 | if (sqrt(pow(a->joe.x - p_w, 2) + pow(a->joe.y - p_h, 2)) <= a->joe.radius) 25 | a->img_3d.addr[(p_h * (int)a->win.win_w + p_w)] = 0xb87cb3; 26 | return (0); 27 | } 28 | 29 | int draw_comp_map(int p_w, int p_h, t_adata *a) 30 | { 31 | int cur_x; 32 | int cur_y; 33 | 34 | cur_x = (int)p_w / a->map.tile_size; 35 | cur_y = (int)p_h / a->map.tile_size; 36 | if (cur_x >= (int)ft_strlen(a->map.maptxt[cur_y])) 37 | return (0); 38 | else if (a->map.maptxt[cur_y][cur_x] == '1') 39 | a->img_3d.addr[(int)(p_h * (int)a->win.win_w + p_w)] = 0x85b569; 40 | else if (ft_strchr("02NSWE", a->map.maptxt[cur_y][cur_x])) 41 | a->img_3d.addr[(int)(p_h * (int)a->win.win_w + p_w)] = 0xebdbb7; 42 | else 43 | return (0); 44 | return (1); 45 | } 46 | 47 | int draw_comp(t_adata *a, int (*comp)(int, int, t_adata *)) 48 | { 49 | int pixel_w; 50 | int pixel_h; 51 | 52 | pixel_h = 0; 53 | while (pixel_h < a->map.map_h) 54 | { 55 | pixel_w = 0; 56 | while (pixel_w < a->map.map_w) 57 | { 58 | comp(pixel_w, pixel_h, a); 59 | pixel_w++; 60 | } 61 | pixel_h++; 62 | } 63 | return (0); 64 | } 65 | 66 | int draw_map(t_adata *a) 67 | { 68 | draw_comp(a, &draw_comp_map); 69 | draw_comp(a, &draw_comp_circle); 70 | ft_initline(a); 71 | line(a->line, a); 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /bonus_game/events_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* events_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 16:32:16 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:02:24 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | void cleanclose(t_adata *a) 16 | { 17 | free(a->parse.no_text); 18 | free(a->parse.so_text); 19 | free(a->parse.we_text); 20 | free(a->parse.ea_text); 21 | free(a->parse.sprite_text); 22 | clean_sprites(a, &a->sps); 23 | ft_freetext(a->parse.mapstr); 24 | mlx_destroy_window(a->win.mlx, a->win.win); 25 | exit(EXIT_SUCCESS); 26 | } 27 | 28 | int clicked_cross(int keycode, t_adata *a) 29 | { 30 | (void)keycode; 31 | (void)a; 32 | exit(EXIT_SUCCESS); 33 | return (0); 34 | } 35 | 36 | int butt_released(int keycode, t_adata *a) 37 | { 38 | if (keycode == W_KEY) 39 | a->joe.walkdir = 0; 40 | else if (keycode == S_KEY) 41 | a->joe.walkdir = 0; 42 | else if (keycode == A_KEY) 43 | a->joe.walkdir = 0; 44 | else if (keycode == D_KEY) 45 | a->joe.walkdir = 0; 46 | else if (keycode == RIGHT_ARROW) 47 | a->joe.turndir = 0; 48 | else if (keycode == LEFT_ARROW) 49 | a->joe.turndir = 0; 50 | else if (keycode == SPACE_BAR) 51 | a->joe.anim_start = 0; 52 | return (0); 53 | } 54 | 55 | int butt_pressed(int keycode, t_adata *a) 56 | { 57 | if (keycode == ESC_KEY) 58 | cleanclose(a); 59 | if (keycode == W_KEY) 60 | a->joe.walkdir = 'w'; 61 | else if (keycode == S_KEY) 62 | a->joe.walkdir = 's'; 63 | else if (keycode == A_KEY) 64 | a->joe.walkdir = 'a'; 65 | else if (keycode == D_KEY) 66 | a->joe.walkdir = 'd'; 67 | else if (keycode == RIGHT_ARROW) 68 | a->joe.turndir = 1; 69 | else if (keycode == LEFT_ARROW) 70 | a->joe.turndir = -1; 71 | else if (keycode == SPACE_BAR) 72 | a->joe.anim_start = 1; 73 | return (0); 74 | } 75 | -------------------------------------------------------------------------------- /mandatory_game/start_game_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* raycast_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/07 13:21:39 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:20 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | double spawnrotation(char c) 16 | { 17 | if (c == 'E') 18 | return (0); 19 | else if (c == 'S') 20 | return (M_PI_2); 21 | else if (c == 'W') 22 | return (M_PI); 23 | else 24 | return (3 * M_PI_2); 25 | } 26 | 27 | void ft_playerinfo(t_map2d *map, t_player *joe, char **strs) 28 | { 29 | int i; 30 | int j; 31 | 32 | i = 0; 33 | while (strs[i]) 34 | { 35 | j = 0; 36 | while (strs[i][j]) 37 | { 38 | if (ft_strchr("NSEW", strs[(int)i][(int)j])) 39 | { 40 | joe->x = (double)((j + 0.5) * map->tile_size); 41 | joe->y = (double)((i + 0.5) * map->tile_size); 42 | joe->rotangle = spawnrotation(strs[i][j]); 43 | } 44 | j++; 45 | } 46 | i++; 47 | } 48 | } 49 | 50 | double calculate_tilesize(t_adata *a) 51 | { 52 | int map_resratio_x; 53 | int map_resratio_y; 54 | 55 | map_resratio_x = (int)((a->parse.rx / a->map.map_cols) / 3); 56 | map_resratio_y = (int)((a->parse.ry / a->map.map_rows) / 3); 57 | if (map_resratio_x < map_resratio_y) 58 | return ((double)(map_resratio_x)); 59 | else 60 | return ((double)(map_resratio_y)); 61 | } 62 | 63 | int ft_max_strlen(char **strs) 64 | { 65 | int i; 66 | int j; 67 | int max_len; 68 | 69 | i = 0; 70 | j = 0; 71 | max_len = 0; 72 | while (strs[i]) 73 | { 74 | j = 0; 75 | while (strs[i][j]) 76 | j++; 77 | if (j > max_len) 78 | max_len = j; 79 | i++; 80 | } 81 | return (max_len); 82 | } 83 | 84 | int ft_count_lines(char **strs) 85 | { 86 | int i; 87 | 88 | i = 0; 89 | while (strs[i]) 90 | i++; 91 | return (i); 92 | } 93 | -------------------------------------------------------------------------------- /mandatory_game/draw2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 21:51:03 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:37:17 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | /* To draw the floor and ceiling I just 2 rectangles behind the 3d wall projections */ 15 | int drawsps(t_ray *ray, t_adata *a, int col_id) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (i < a->sps.number) 21 | { 22 | if ((a->sps.items[i]).is_visible && 23 | is_sprite_stripe(&a->sps.items[i], col_id) 24 | && ray->distance > a->sps.items[i].distance 25 | && a->sps.items[i].xstart > 0 && a->sps.items[i].xend < a->win.win_w) 26 | { 27 | ft_prepare_sprite_line(&a->sps.items[i], a, col_id); 28 | linesprite(&a->sps.items[i], a, col_id); 29 | } 30 | i++; 31 | } 32 | return (0); 33 | } 34 | 35 | int draw_ceilingrgb(t_adata *a) 36 | { 37 | int p_w; 38 | int p_h; 39 | double adjust_height_half; 40 | 41 | adjust_height_half = ceil((double)(a->win.win_h / 2)) - 1; 42 | p_h = 0; 43 | while (p_h < (int)adjust_height_half) 44 | { 45 | p_w = 0; 46 | while (p_w < a->win.win_w) 47 | { 48 | a->img_3d.addr[(int)(p_h * a->win.win_w + p_w)] = 49 | create_trgb(0, a->parse.rceil, 50 | a->parse.gceil, a->parse.bceil); 51 | p_w++; 52 | } 53 | p_h++; 54 | } 55 | return (0); 56 | } 57 | 58 | int draw_floorrgb(t_adata *a) 59 | { 60 | int p_w; 61 | int p_h; 62 | double adjust_height_half; 63 | 64 | adjust_height_half = ceil((double)(a->win.win_h / 2)) - 1; 65 | p_h = (int)adjust_height_half; 66 | while (p_h < a->win.win_h) 67 | { 68 | p_w = 0; 69 | while (p_w < a->win.win_w) 70 | { 71 | a->img_3d.addr[(int)(p_h * a->win.win_w + p_w)] = 72 | create_trgb(0, a->parse.rfloor, 73 | a->parse.gfloor, a->parse.bfloor); 74 | p_w++; 75 | } 76 | p_h++; 77 | } 78 | return (0); 79 | } 80 | -------------------------------------------------------------------------------- /minilibx/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 | -------------------------------------------------------------------------------- /libft/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/04 23:26:13 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 16:42:02 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_freestrs(char **strs, size_t prev) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < prev) 21 | { 22 | free(strs[i]); 23 | i++; 24 | } 25 | free(strs); 26 | return (0); 27 | } 28 | 29 | size_t ft_len(char *str, char c) 30 | { 31 | int count; 32 | 33 | count = 0; 34 | while (*str != c && *str) 35 | { 36 | str++; 37 | count++; 38 | } 39 | return (count); 40 | } 41 | 42 | size_t ft_wordnr(char *str, char del) 43 | { 44 | int count; 45 | 46 | count = 0; 47 | while (*str) 48 | { 49 | while (*str == del && *str) 50 | str++; 51 | if (*str != del && *str) 52 | { 53 | count++; 54 | while (*str != del && *str) 55 | str++; 56 | } 57 | } 58 | return (count); 59 | } 60 | 61 | void *ft_put_strings(char **new, char *str, char c) 62 | { 63 | size_t ptr; 64 | size_t i; 65 | 66 | i = 0; 67 | ptr = 0; 68 | while (str[ptr]) 69 | { 70 | while (str[ptr] == c && str[ptr]) 71 | ptr++; 72 | if (str[ptr] != c && str[ptr]) 73 | { 74 | new[i] = ft_substr(str, ptr, ft_len(&(str[ptr]), c)); 75 | if (!new[i]) 76 | return (ft_freestrs(new, i)); 77 | while (str[ptr] != c && str[ptr]) 78 | ptr++; 79 | i++; 80 | } 81 | } 82 | new[i] = 0; 83 | return (new); 84 | } 85 | 86 | char **ft_split(char const *s, char c) 87 | { 88 | char **new; 89 | char *str; 90 | int words; 91 | 92 | str = (char *)s; 93 | if (!s) 94 | return (0); 95 | words = ft_wordnr(str, c); 96 | new = malloc(sizeof(char*) * (words + 1)); 97 | if (!new) 98 | return (0); 99 | ft_put_strings(new, str, c); 100 | return (new); 101 | } 102 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_textures2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_textures2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 18:06:51 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:11:31 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* checking if the texture files exist. Probably it would be a good idea to make sure that these are XPM*/ 15 | int ft_parsespritetext(char *str, t_parse *parse) 16 | { 17 | int i; 18 | 19 | i = 1; 20 | while (ft_isspace(str[i])) 21 | i++; 22 | parse->sprite_text = ft_strdup(&str[i]); 23 | if (!parse->sprite_text) 24 | return (0); 25 | if (open(parse->sprite_text, O_RDONLY) < 0) 26 | return (0); 27 | return (1); 28 | } 29 | 30 | int ft_parseeasttext(char *str, t_parse *parse) 31 | { 32 | int i; 33 | 34 | i = 2; 35 | while (ft_isspace(str[i])) 36 | i++; 37 | parse->ea_text = ft_strdup(&str[i]); 38 | if (!parse->ea_text) 39 | return (0); 40 | if (open(parse->ea_text, O_RDONLY) < 0) 41 | return (0); 42 | return (1); 43 | } 44 | 45 | int ft_parsewesttext(char *str, t_parse *parse) 46 | { 47 | int i; 48 | 49 | i = 2; 50 | while (ft_isspace(str[i])) 51 | i++; 52 | parse->we_text = ft_strdup(&str[i]); 53 | if (!parse->we_text) 54 | return (0); 55 | if (open(parse->we_text, O_RDONLY) < 0) 56 | return (0); 57 | return (1); 58 | } 59 | 60 | int ft_parsesouthtext(char *str, t_parse *parse) 61 | { 62 | int i; 63 | 64 | i = 2; 65 | while (ft_isspace(str[i])) 66 | i++; 67 | parse->so_text = ft_strdup(&str[i]); 68 | if (!parse->so_text) 69 | return (0); 70 | if (open(parse->so_text, O_RDONLY) < 0) 71 | return (0); 72 | return (1); 73 | } 74 | 75 | int ft_parsenorthtext(char *str, t_parse *parse) 76 | { 77 | int i; 78 | 79 | i = 2; 80 | while (ft_isspace(str[i])) 81 | i++; 82 | parse->no_text = ft_strdup(&str[i]); 83 | if (!parse->no_text) 84 | return (0); 85 | if (open(parse->no_text, O_RDONLY) < 0) 86 | return (0); 87 | return (1); 88 | } 89 | -------------------------------------------------------------------------------- /mandatory_game/start_game_utils2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* start_game_utils2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 16:42:55 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:40:16 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int find_text_wallhit(double ray_angle, t_ray *ray, t_adata *a) 16 | { 17 | if (ray->hit_vertical) 18 | { 19 | if (normalrad(ray_angle) > M_PI_2 && 20 | normalrad(ray_angle) < (3 * M_PI_2)) 21 | ray->text_wallhit = a->wetext; 22 | else 23 | ray->text_wallhit = a->eatext; 24 | } 25 | else 26 | { 27 | if (normalrad(ray_angle) > M_PI && 28 | normalrad(ray_angle) < 2 * M_PI) 29 | ray->text_wallhit = a->notext; 30 | else 31 | ray->text_wallhit = a->sotext; 32 | } 33 | return (0); 34 | } 35 | 36 | int has_wall(double x, double y, t_adata *a) 37 | { 38 | int mapgridx; 39 | int mapgridy; 40 | 41 | if ((int)x < 0 || (int)x > a->map.map_w || 42 | (int)y < 0 || (int)y > a->map.map_h) 43 | return (1); 44 | mapgridx = (int)x / a->map.tile_size; 45 | mapgridy = (int)y / a->map.tile_size; 46 | if (mapgridx >= (int)ft_strlen(a->map.maptxt[mapgridy])) 47 | return (1); 48 | if (a->map.maptxt[(int)mapgridy][(int)mapgridx] == '1') 49 | return (1); 50 | return (0); 51 | } 52 | /* to prevent the angle in radians to turn negative or above 2PI */ 53 | double normalrad(double movestep) 54 | { 55 | if (movestep >= (2 * M_PI)) 56 | movestep -= (2 * M_PI); 57 | if (movestep < (0)) 58 | movestep += (2 * M_PI); 59 | return (movestep); 60 | } 61 | 62 | double distancepoints(double x1, double y1, double x2, double y2) 63 | { 64 | return (sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2))); 65 | } 66 | 67 | int ftinittext(t_adata *a, t_img *imgt, char *textpath) 68 | { 69 | imgt->ptr = mlx_xpm_file_to_image(a->win.mlx, 70 | textpath, &imgt->width, &imgt->height); 71 | imgt->addr = (int *)mlx_get_data_addr(imgt->ptr, 72 | &imgt->pixel_bits, &imgt->line_bytes, 73 | &imgt->endian); 74 | return (0); 75 | } 76 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/27 21:41:45 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:15:13 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_PARSE_H 14 | # define FT_PARSE_H 15 | /* An enumerator will create different numbers for each one of these errors 16 | It is equivalent to having 17 | # define NOT_CUB_ERROR 0 18 | # define INVALID_FILE 1 19 | etc*/ 20 | enum e_errors 21 | { 22 | NOT_CUB_ERROR, 23 | INVALID_FILE, 24 | PARSING_ERROR, 25 | MALLOCERROR, 26 | MULTIRES, 27 | BADSCREEN, 28 | MULTINO, 29 | BADNO, 30 | MULTISO, 31 | BADSO, 32 | MULTIWE, 33 | BADWE, 34 | MULTIEA, 35 | BADEA, 36 | MULTISPRITE, 37 | BADSPRITE, 38 | MULTIFLOOR, 39 | BADFLOOR, 40 | MULTICEIL, 41 | BADCEIL, 42 | INVALIDMAP, 43 | INVALIDCHAR, 44 | MISSINGPARAMS 45 | }; 46 | 47 | int check_resolution(char **text, t_parse *parse, int *i, int *count); 48 | int check_textures(char **text, t_parse *parse, int *i, int *count); 49 | int check_rgbs(char **text, t_parse *parse, int *i, int *count); 50 | int check_valid_chars(char **text, int *i); 51 | int is_map(char *str); 52 | void *ft_realloctabs(char *str, int tab_nbr); 53 | void *ft_freetext(char **strs); 54 | void ft_start_tmap(t_parse *parse); 55 | int ft_countchr(char *str, char c); 56 | int cub_extract(t_parse *parse, int fd); 57 | int ft_parse_cub(char **text, t_parse *parse); 58 | int ft_isspace(char c); 59 | int ft_error(int errornbr); 60 | int ft_parsenorthtext(char *str, t_parse *parse); 61 | int ft_parsesouthtext(char *str, t_parse *parse); 62 | int ft_parsewesttext(char *str, t_parse *parse); 63 | int ft_parseeasttext(char *str, t_parse *parse); 64 | int ft_parsespritetext(char *str, t_parse *parse); 65 | int checkmultiplayer(char *str, t_parse *parse); 66 | int check_valid_map(char **strs, t_parse *parse); 67 | int ft_copy_map(char **map_start, t_parse *parse); 68 | int start_game(t_adata *a); 69 | void screenshot(char *cubname); 70 | void ft_free_to_str(char ***strs, int prev); 71 | void ft_init_textures(t_parse *parse); 72 | void free_all_texts(t_parse *parse); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /libft/get_next_line_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/14 22:17:48 by gleal #+# #+# */ 9 | /* Updated: 2021/02/18 14:34:54 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (s[i]) 21 | i++; 22 | return (i); 23 | } 24 | 25 | char *ft_strchr(const char *s, int c) 26 | { 27 | char *str; 28 | 29 | str = (char *)s; 30 | while (*str) 31 | { 32 | if (*str == (char)c) 33 | return (str); 34 | str++; 35 | } 36 | if (*str == (char)c) 37 | return (str); 38 | return (0); 39 | } 40 | 41 | char *ft_strdup(const char *s1) 42 | { 43 | size_t i; 44 | size_t size; 45 | char *str; 46 | 47 | size = 0; 48 | while (s1[size]) 49 | size++; 50 | str = (char *)malloc(sizeof(char) * (size + 1)); 51 | if (!str) 52 | return (0); 53 | i = 0; 54 | while (s1[i]) 55 | { 56 | str[i] = s1[i]; 57 | i++; 58 | } 59 | str[i] = '\0'; 60 | return (str); 61 | } 62 | 63 | char *ft_strjoin(char const *s1, char const *s2) 64 | { 65 | char *str; 66 | size_t count; 67 | size_t j; 68 | 69 | if (!s1 || !s2) 70 | return (0); 71 | count = ft_strlen(s1) + ft_strlen(s2); 72 | j = 0; 73 | if (!count) 74 | return (0); 75 | str = (char *)malloc(sizeof(char) * (count + 1)); 76 | if (!str) 77 | return (0); 78 | while (*s1) 79 | str[j++] = *(s1++); 80 | while (*s2) 81 | str[j++] = *(s2++); 82 | str[j] = '\0'; 83 | return (str); 84 | } 85 | 86 | char *ft_substr(char const *s, unsigned int start, size_t len) 87 | { 88 | size_t i; 89 | char *str; 90 | size_t length; 91 | 92 | length = len; 93 | i = 0; 94 | if (!s) 95 | return (0); 96 | if (ft_strlen(s) - start <= length) 97 | length = ft_strlen(s) - start; 98 | if (ft_strlen(s) <= start) 99 | { 100 | start = 0; 101 | length = 0; 102 | } 103 | str = (char *)malloc(sizeof(char) * (length + 1)); 104 | if (!str) 105 | return (0); 106 | while (s[start] && length--) 107 | str[i++] = s[start++]; 108 | str[i] = '\0'; 109 | return (str); 110 | } 111 | -------------------------------------------------------------------------------- /other_utils/ft_error.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_error.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/25 17:16:11 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 20:06:51 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | 15 | int ft_error_pt3(int errornbr) 16 | { 17 | if (errornbr == NOT_CUB_ERROR) 18 | printf("please cub"); 19 | if (errornbr == INVALID_FILE) 20 | printf("invalid file"); 21 | return (0); 22 | } 23 | 24 | int ft_error_pt2(int errornbr) 25 | { 26 | if (errornbr == BADSPRITE) 27 | printf("can't open sprite textures"); 28 | if (errornbr == MULTIFLOOR) 29 | printf("multiple floor colors"); 30 | if (errornbr == BADFLOOR) 31 | printf("invalid floor colors"); 32 | if (errornbr == MULTICEIL) 33 | printf("multiple ceiling colors"); 34 | if (errornbr == BADCEIL) 35 | printf("invalid ceiling colors"); 36 | if (errornbr == INVALIDMAP) 37 | printf("invalid map"); 38 | if (errornbr == INVALIDCHAR) 39 | printf("invalid character in cub text"); 40 | if (errornbr == MISSINGPARAMS) 41 | printf("missing at least one parameter"); 42 | if (errornbr == PARSING_ERROR) 43 | printf("there was an error while parsing"); 44 | return (0); 45 | } 46 | 47 | int ft_error_pt1(int errornbr) 48 | { 49 | if (errornbr == MULTIRES) 50 | printf("multiple resolutions"); 51 | if (errornbr == BADSCREEN) 52 | printf("invalid screensize!"); 53 | if (errornbr == MULTINO) 54 | printf("multiple north textures"); 55 | if (errornbr == BADNO) 56 | printf("can't open north textures"); 57 | if (errornbr == MULTISO) 58 | printf("multiple south textures"); 59 | if (errornbr == BADSO) 60 | printf("can't open south textures"); 61 | if (errornbr == MULTIWE) 62 | printf("multiple west textures"); 63 | if (errornbr == BADWE) 64 | printf("can't open west textures"); 65 | if (errornbr == MULTIEA) 66 | printf("multiple east textures"); 67 | if (errornbr == BADEA) 68 | printf("can't open east textures"); 69 | if (errornbr == MULTISPRITE) 70 | printf("multiple sprite textures"); 71 | return (0); 72 | } 73 | 74 | int ft_error(int errornbr) 75 | { 76 | ft_error_pt1(errornbr); 77 | ft_error_pt2(errornbr); 78 | ft_error_pt3(errornbr); 79 | return (0); 80 | } 81 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 18:13:02 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:12:37 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* if there is a line break the get next line function will turn in into a zero so if the 15 | first character is a zero I know someone added a linebreak in the middle of the map */ 16 | int is_map(char *str) 17 | { 18 | if (*str == '\0') 19 | return (0); 20 | while (*str) 21 | { 22 | if (!ft_isspace(*str) && !ft_strchr(MAP_CHARS, *str)) 23 | return (0); 24 | str++; 25 | } 26 | return (1); 27 | } 28 | 29 | void ft_start_tmap(t_parse *parse) 30 | { 31 | parse->lnbr = 0; 32 | parse->text = malloc(sizeof(char *) * 2); 33 | if (!parse->text) 34 | return ; 35 | parse->text[0] = 0; 36 | parse->text[1] = 0; 37 | parse->rx = 0; 38 | parse->ry = 0; 39 | parse->error = 0; 40 | parse->no_text = 0; 41 | parse->so_text = 0; 42 | parse->we_text = 0; 43 | parse->ea_text = 0; 44 | parse->sprite_text = 0; 45 | parse->rfloor = 0; 46 | parse->gfloor = 0; 47 | parse->bfloor = 0; 48 | parse->rceil = 0; 49 | parse->gceil = 0; 50 | parse->bceil = 0; 51 | parse->map_size = 0; 52 | parse->player_or = 0; 53 | } 54 | 55 | int ft_countchr(char *str, char c) 56 | { 57 | int count; 58 | 59 | count = 0; 60 | while (*str) 61 | { 62 | if (*str == c) 63 | count++; 64 | str++; 65 | } 66 | return (count); 67 | } 68 | 69 | int ft_isspace(char c) 70 | { 71 | if (c == ' ' || (c >= 9 && c <= 13)) 72 | return (1); 73 | else 74 | return (0); 75 | } 76 | 77 | int check_valid_chars(char **text, int *i) 78 | { 79 | if (text[(*i)][0] == 'N' && text[(*i)][1] == 'O') 80 | return (1); 81 | if (text[(*i)][0] == 'S' && text[(*i)][1] == 'O') 82 | return (1); 83 | if (text[(*i)][0] == 'W' && text[(*i)][1] == 'E') 84 | return (1); 85 | if (text[(*i)][0] == 'E' && text[(*i)][1] == 'A') 86 | return (1); 87 | if (text[(*i)][0] == 'S' && text[(*i)][1] != 'O') 88 | return (1); 89 | if (text[(*i)][0] == 'F') 90 | return (1); 91 | if (text[(*i)][0] == 'C') 92 | return (1); 93 | if (text[(*i)][0] == '\0') 94 | return (1); 95 | if (text[(*i)] == NULL) 96 | return (1); 97 | return (0); 98 | } 99 | -------------------------------------------------------------------------------- /bonus_game/lines_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* lines_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 18:53:52 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:02:46 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | int linesprite(t_item *item, 16 | t_adata *a, int col_id) 17 | { 18 | double remain_pixels; 19 | double pixelx; 20 | double pixely; 21 | double texx; 22 | double texy; 23 | 24 | pixelx = a->line_sp.start_x; 25 | pixely = a->line_sp.start_y; 26 | texy = 0; 27 | texx = bitmap_offset_sp(item, col_id); 28 | remain_pixels = a->line_sp.pixels; 29 | while (remain_pixels > 0) 30 | { 31 | if (item->imgsp.addr[(int)texy * (int)item->imgsp.width + (int)texx]) 32 | a->img_3d.addr[((int)pixely * (int)a->win.win_w + (int)pixelx)] = 33 | item->imgsp.addr[(int)texy * (int)item->imgsp.width + (int)texx]; 34 | pixelx += a->line_sp.deltax; 35 | pixely += a->line_sp.deltay; 36 | texy = ((pixely - a->line_sp.start_y) * 37 | item->imgsp.width) / a->line_sp.pixels; 38 | --remain_pixels; 39 | } 40 | return (0); 41 | } 42 | 43 | int line3d(t_ray *ray, t_adata *a) 44 | { 45 | double remain_pixels; 46 | double pixelx; 47 | double pixely; 48 | int texx; 49 | int texy; 50 | 51 | pixelx = a->line_3d.start_x; 52 | pixely = a->line_3d.start_y; 53 | texy = 0; 54 | texx = bitmap_offset(ray, a); 55 | remain_pixels = a->line_3d.pixels; 56 | while (remain_pixels > 0) 57 | { 58 | a->img_3d.addr[((int)pixely * (int)a->win.win_w + (int)pixelx)] = 59 | a->notext.imgt.addr[(int)texy * 60 | (int)a->notext.imgt.width + (int)texx]; 61 | pixelx += a->line_3d.deltax; 62 | pixely += a->line_3d.deltay; 63 | texy = ((pixely - a->line_3d.start_y) * 64 | a->notext.imgt.width) / a->line_3d.pixels; 65 | --remain_pixels; 66 | } 67 | return (0); 68 | } 69 | 70 | int line(t_line line, t_adata *a) 71 | { 72 | double remain_pixels; 73 | double pixelx; 74 | double pixely; 75 | 76 | pixelx = line.start_x; 77 | pixely = line.start_y; 78 | remain_pixels = line.pixels; 79 | while (remain_pixels > 0) 80 | { 81 | a->img_3d.addr[(int)pixely * (int)a->win.win_w + 82 | (int)pixelx] = line.color; 83 | pixelx += line.deltax; 84 | pixely += line.deltay; 85 | --remain_pixels; 86 | } 87 | return (0); 88 | } 89 | -------------------------------------------------------------------------------- /mandatory_game/cast_rays.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cast_rays.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/12 16:36:09 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 16:36:50 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int ray_construct(double ray_angle, t_ray *ray) 16 | { 17 | ray->wall_hit_horx = 0; 18 | ray->wall_hit_hory = 0; 19 | ray->wall_hit_verx = 0; 20 | ray->wall_hit_very = 0; 21 | ray->wall_hit_x = 0; 22 | ray->wall_hit_y = 0; 23 | ray->found_hor_wall = 0; 24 | ray->found_ver_wall = 0; 25 | ray->hit_vertical = 0; 26 | if (ray_angle > 0 && ray_angle < M_PI) 27 | ray->facing_down = 1; 28 | else 29 | ray->facing_down = 0; 30 | if (ray_angle > M_PI_2 && ray_angle < (3 * M_PI_2)) 31 | ray->facing_left = 1; 32 | else 33 | ray->facing_left = 0; 34 | return (0); 35 | } 36 | 37 | int vertical_cast(t_ray *ray, t_adata *a) 38 | { 39 | double nexttouch_verx; 40 | double nexttouch_very; 41 | 42 | vertical_interstep(a, ray, &nexttouch_verx, &nexttouch_very); 43 | vertical_cast_facingleft(a, ray, &nexttouch_verx, &nexttouch_very); 44 | vertical_cast_facingright(a, ray, &nexttouch_verx, &nexttouch_very); 45 | return (0); 46 | } 47 | 48 | int horizontal_cast(t_ray *ray, t_adata *a) 49 | { 50 | double nexttouch_horx; 51 | double nexttouch_hory; 52 | 53 | horizontal_interstep(a, ray, &nexttouch_horx, &nexttouch_hory); 54 | horizontal_cast_facingup(a, ray, &nexttouch_horx, &nexttouch_hory); 55 | horizontal_cast_facingdown(a, ray, &nexttouch_horx, &nexttouch_hory); 56 | return (0); 57 | } 58 | 59 | int dda_alg(t_ray *ray, t_adata *a) 60 | { 61 | double horz_dist; 62 | double vert_dist; 63 | 64 | horizontal_cast(ray, a); 65 | vertical_cast(ray, a); 66 | horiz_vert_raycomp(a, ray, &horz_dist, &vert_dist); 67 | return (0); 68 | } 69 | 70 | int draw3d(t_adata *a) 71 | { 72 | t_ray ray; 73 | int col_id; 74 | 75 | col_id = 0; 76 | ray.ray_angle = normalrad(a->joe.rotangle - (a->ray.fov / 2)); 77 | while (col_id < a->ray.num_rays) 78 | { 79 | ray_construct(ray.ray_angle, &ray); 80 | dda_alg(&ray, a); 81 | draw3dline(ray.ray_angle, &ray, a, col_id); 82 | drawsps(&ray, a, col_id); 83 | ray.ray_angle = normalrad(ray.ray_angle 84 | + (a->ray.fov / a->ray.num_rays)); 85 | col_id++; 86 | } 87 | return (0); 88 | } 89 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_textures.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_textures.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 18:06:19 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:09:43 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* Using the elements initials to identify them. We need to use both because sprites and south both start with S */ 15 | int check_walltextures_horiz(char **text, t_parse *parse, 16 | int *i, int *count) 17 | { 18 | if (text[(*i)][0] == 'N' && text[(*i)][1] == 'O') 19 | { 20 | if (parse->no_text) 21 | return (ft_error(MULTINO)); 22 | if (!ft_parsenorthtext(text[(*i)], parse)) 23 | return (ft_error(BADNO)); 24 | (*count)++; 25 | (*i)++; 26 | } 27 | if (text[(*i)][0] == 'S' && text[(*i)][1] == 'O') 28 | { 29 | if (parse->so_text) 30 | return (ft_error(MULTISO)); 31 | if (!ft_parsesouthtext(text[(*i)], parse)) 32 | return (ft_error(BADSO)); 33 | (*count)++; 34 | (*i)++; 35 | } 36 | return (1); 37 | } 38 | 39 | int check_walltextures_vert(char **text, t_parse *parse, int *i, int *count) 40 | { 41 | if (text[(*i)][0] == 'W' && text[(*i)][1] == 'E') 42 | { 43 | if (parse->we_text) 44 | return (ft_error(MULTIWE)); 45 | if (!ft_parsewesttext(text[(*i)], parse)) 46 | return (ft_error(BADWE)); 47 | (*count)++; 48 | (*i)++; 49 | } 50 | if (text[(*i)][0] == 'E' && text[(*i)][1] == 'A') 51 | { 52 | if (parse->ea_text) 53 | return (ft_error(MULTIEA)); 54 | if (!ft_parseeasttext(text[(*i)], parse)) 55 | return (ft_error(BADEA)); 56 | (*count)++; 57 | (*i)++; 58 | } 59 | return (1); 60 | } 61 | 62 | int check_spritetextures(char **text, t_parse *parse, int *i, int *count) 63 | { 64 | if (text[(*i)][0] == 'S' && text[(*i)][1] != 'O') 65 | { 66 | if (parse->sprite_text) 67 | return (ft_error(MULTISPRITE)); 68 | if (!ft_parsespritetext(text[(*i)], parse)) 69 | return (ft_error(BADSPRITE)); 70 | (*count)++; 71 | (*i)++; 72 | } 73 | return (1); 74 | } 75 | 76 | int check_textures(char **text, t_parse *parse, int *i, int *count) 77 | { 78 | if (!check_walltextures_horiz(text, parse, i, count)) 79 | return (0); 80 | if (!check_walltextures_vert(text, parse, i, count)) 81 | return (0); 82 | if (!check_spritetextures(text, parse, i, count)) 83 | return (0); 84 | return (1); 85 | } 86 | -------------------------------------------------------------------------------- /bonus_game/cast_rays_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cast_rays_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 17:50:23 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 17:02:34 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | int ray_construct(double ray_angle, t_ray *ray) 16 | { 17 | ray->wall_hit_horx = 0; 18 | ray->wall_hit_hory = 0; 19 | ray->wall_hit_verx = 0; 20 | ray->wall_hit_very = 0; 21 | ray->wall_hit_x = 0; 22 | ray->wall_hit_y = 0; 23 | ray->found_hor_wall = 0; 24 | ray->found_ver_wall = 0; 25 | ray->hit_vertical = 0; 26 | if (ray_angle > 0 && ray_angle < M_PI) 27 | ray->facing_down = 1; 28 | else 29 | ray->facing_down = 0; 30 | if (ray_angle > M_PI_2 && ray_angle < (3 * M_PI_2)) 31 | ray->facing_left = 1; 32 | else 33 | ray->facing_left = 0; 34 | return (0); 35 | } 36 | 37 | int vertical_cast(t_ray *ray, t_adata *a) 38 | { 39 | double nexttouch_verx; 40 | double nexttouch_very; 41 | 42 | vertical_interstep(a, ray, &nexttouch_verx, &nexttouch_very); 43 | vertical_cast_facingleft(a, ray, &nexttouch_verx, &nexttouch_very); 44 | vertical_cast_facingright(a, ray, &nexttouch_verx, &nexttouch_very); 45 | return (0); 46 | } 47 | 48 | int horizontal_cast(t_ray *ray, t_adata *a) 49 | { 50 | double nexttouch_horx; 51 | double nexttouch_hory; 52 | 53 | horizontal_interstep(a, ray, &nexttouch_horx, &nexttouch_hory); 54 | horizontal_cast_facingup(a, ray, &nexttouch_horx, &nexttouch_hory); 55 | horizontal_cast_facingdown(a, ray, &nexttouch_horx, &nexttouch_hory); 56 | return (0); 57 | } 58 | 59 | int dda_alg(t_ray *ray, t_adata *a) 60 | { 61 | double horz_dist; 62 | double vert_dist; 63 | 64 | horizontal_cast(ray, a); 65 | vertical_cast(ray, a); 66 | horiz_vert_raycomp(a, ray, &horz_dist, &vert_dist); 67 | return (0); 68 | } 69 | 70 | int draw3d(t_adata *a) 71 | { 72 | t_ray ray; 73 | int col_id; 74 | 75 | col_id = 0; 76 | ray.ray_angle = normalrad(a->joe.rotangle - (a->ray.fov / 2)); 77 | while (col_id < a->ray.num_rays) 78 | { 79 | ray_construct(ray.ray_angle, &ray); 80 | dda_alg(&ray, a); 81 | draw3dline(ray.ray_angle, &ray, a, col_id); 82 | drawfloortxt(&ray, a, col_id); 83 | drawsps(&ray, a, col_id); 84 | ray.ray_angle = normalrad(ray.ray_angle 85 | + (a->ray.fov / a->ray.num_rays)); 86 | col_id++; 87 | } 88 | return (0); 89 | } 90 | -------------------------------------------------------------------------------- /libft/get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/02/12 19:01:21 by gleal #+# #+# */ 9 | /* Updated: 2021/02/18 16:45:58 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | 15 | char *ft_strnew(size_t size) 16 | { 17 | char *str; 18 | 19 | if (!(str = (char *)malloc(sizeof(char) * size + 1))) 20 | return (NULL); 21 | str[size] = '\0'; 22 | while (size--) 23 | str[size] = '\0'; 24 | return (str); 25 | } 26 | 27 | void ft_strdel(char **str_ptr) 28 | { 29 | if (str_ptr) 30 | { 31 | free(*str_ptr); 32 | *str_ptr = 0; 33 | } 34 | } 35 | 36 | static int ft_next_line_save_extra(char **extra_text, char **line, int fd) 37 | { 38 | int i; 39 | char *trim; 40 | 41 | i = 0; 42 | while (extra_text[fd][i] && extra_text[fd][i] != '\n') 43 | i++; 44 | if (extra_text[fd][i] == '\n') 45 | { 46 | *line = ft_substr(extra_text[fd], 0, i); 47 | trim = ft_strdup(&extra_text[fd][i + 1]); 48 | ft_strdel(&extra_text[fd]); 49 | extra_text[fd] = trim; 50 | if (extra_text[fd][0] == '\0') 51 | ft_strdel(&extra_text[fd]); 52 | } 53 | else 54 | { 55 | *line = ft_strdup(extra_text[fd]); 56 | ft_strdel(&extra_text[fd]); 57 | return (0); 58 | } 59 | return (1); 60 | } 61 | 62 | static int ft_loopbuffer(char **extra_text, int fd) 63 | { 64 | int i; 65 | char buf[BUFFER_SIZE + 1]; 66 | char *add_buffer; 67 | 68 | i = 1; 69 | i = read(fd, buf, BUFFER_SIZE); 70 | while (i > 0) 71 | { 72 | buf[i] = '\0'; 73 | if (extra_text[fd]) 74 | { 75 | add_buffer = ft_strjoin(extra_text[fd], buf); 76 | ft_strdel(&extra_text[fd]); 77 | extra_text[fd] = add_buffer; 78 | } 79 | else 80 | extra_text[fd] = ft_strdup(buf); 81 | if (ft_strchr(extra_text[fd], '\n')) 82 | break ; 83 | else 84 | i = read(fd, buf, BUFFER_SIZE); 85 | } 86 | return (i); 87 | } 88 | 89 | int get_next_line(int fd, char **line) 90 | { 91 | static char *extra_text[10000]; 92 | int i; 93 | 94 | if (fd < 0 || fd > 10000 || !line || read(fd, 0, 0) < 0) 95 | return (-1); 96 | if (!extra_text[fd]) 97 | extra_text[fd] = ft_strnew(0); 98 | i = ft_loopbuffer(extra_text, fd); 99 | if (!i && !extra_text[fd]) 100 | return (0); 101 | return (ft_next_line_save_extra(extra_text, line, fd)); 102 | } 103 | -------------------------------------------------------------------------------- /mandatory_game/lines.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* lines.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 16:56:54 by gleal #+# #+# */ 9 | /* Updated: 2021/03/29 19:37:46 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int linesprite(t_item *item, 16 | t_adata *a, int col_id) 17 | { 18 | double remain_pixels; 19 | double pixelx; 20 | double pixely; 21 | double texx; 22 | double texy; 23 | 24 | pixelx = a->line_sp.start_x; 25 | pixely = a->line_sp.start_y; 26 | texy = 0; 27 | texx = bitmap_offset_sp(item, col_id); 28 | remain_pixels = a->line_sp.pixels; 29 | while (remain_pixels > 0) 30 | { 31 | if (item->imgsp.addr[(int)texy * (int)item->imgsp.width + (int)texx]) 32 | a->img_3d.addr[((int)pixely * (int)a->win.win_w + (int)pixelx)] = 33 | item->imgsp.addr[(int)texy * (int)item->imgsp.width + (int)texx]; 34 | pixelx += a->line_sp.deltax; 35 | pixely += a->line_sp.deltay; 36 | texy = ((pixely - a->line_sp.start_y) * 37 | item->imgsp.width) / a->line_sp.pixels; 38 | --remain_pixels; 39 | } 40 | return (0); 41 | } 42 | 43 | int line3d(t_ray *ray, t_adata *a, t_text text_wallhit) 44 | { 45 | double remain_pixels; 46 | double pixelx; 47 | double pixely; 48 | int texx; 49 | int texy; 50 | 51 | pixelx = a->line_3d.start_x; 52 | pixely = a->line_3d.start_y; 53 | texy = 0; 54 | texx = bitmap_offset(ray, a); 55 | remain_pixels = a->line_3d.pixels; 56 | while (remain_pixels > 0) 57 | { 58 | if (texy == text_wallhit.imgt.width) 59 | texy = text_wallhit.imgt.width - 1; 60 | a->img_3d.addr[((int)pixely * (int)a->win.win_w + (int)pixelx)] = 61 | text_wallhit.imgt.addr[(int)texy * 62 | (int)text_wallhit.imgt.width + (int)texx]; 63 | pixelx += a->line_3d.deltax; 64 | pixely += a->line_3d.deltay; 65 | texy = ((pixely - a->line_3d.start_y) * 66 | text_wallhit.imgt.width) / a->line_3d.pixels; 67 | --remain_pixels; 68 | } 69 | return (0); 70 | } 71 | 72 | int line(t_line line, t_adata *a) 73 | { 74 | double remain_pixels; 75 | double pixelx; 76 | double pixely; 77 | 78 | pixelx = line.start_x; 79 | pixely = line.start_y; 80 | remain_pixels = line.pixels; 81 | while (remain_pixels > 0) 82 | { 83 | a->img_3d.addr[(int)pixely * (int)a->win.win_w + 84 | (int)pixelx] = line.color; 85 | pixelx += line.deltax; 86 | pixely += line.deltay; 87 | --remain_pixels; 88 | } 89 | return (0); 90 | } 91 | -------------------------------------------------------------------------------- /bonus_game/ft_prepare_lines_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_prepare_lines.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 19:17:21 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 18:08:52 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | 15 | int ft_prepare_sprite_line(t_item *item, t_adata *a, 16 | int col_id) 17 | { 18 | double line_height; 19 | 20 | line_height = item->sprite_h; 21 | a->line_sp.start_x = col_id; 22 | a->line_sp.start_y = (a->win.win_h / 2) - (line_height * 11 / 40); 23 | if (a->line_sp.start_y < 0) 24 | a->line_sp.start_y = 0; 25 | a->line_sp.end_x = col_id; 26 | a->line_sp.end_y = (a->win.win_h / 2) + (line_height * 29 / 40); 27 | if (a->line_sp.end_y >= a->win.win_h) 28 | a->line_sp.end_y = a->win.win_h - 1.0; 29 | a->line_sp.deltax = a->line_sp.end_x - a->line_sp.start_x; 30 | a->line_sp.deltay = a->line_sp.end_y - a->line_sp.start_y; 31 | a->line_sp.pixels = sqrt(pow(a->line_sp.deltax, 2) 32 | + pow(a->line_sp.deltay, 2)); 33 | a->line_sp.deltax /= a->line_sp.pixels; 34 | a->line_sp.deltay /= a->line_sp.pixels; 35 | return (0); 36 | } 37 | 38 | int ft_prepare_3d_line(double ray_angle, t_ray *ray, t_adata *a, int col_id) 39 | { 40 | double line_height; 41 | double nofish_dist; 42 | 43 | nofish_dist = (ray->distance / a->map.tile_size) * 44 | cos(ray_angle - a->joe.rotangle); 45 | line_height = a->ray.distprojplane / nofish_dist; 46 | a->line_3d.start_x = col_id; 47 | a->line_3d.start_y = (a->win.win_h / 2) - (line_height / 2); 48 | if (a->line_3d.start_y < 0) 49 | a->line_3d.start_y = 0; 50 | a->line_3d.end_x = col_id; 51 | a->line_3d.end_y = (a->win.win_h / 2) + (line_height / 2); 52 | if (a->line_3d.end_y >= a->win.win_h) 53 | a->line_3d.end_y = a->win.win_h - 1.0; 54 | a->line_3d.deltax = a->line_3d.end_x - a->line_3d.start_x; 55 | a->line_3d.deltay = a->line_3d.end_y - a->line_3d.start_y; 56 | a->line_3d.pixels = sqrt(pow(a->line_3d.deltax, 2) + 57 | pow(a->line_3d.deltay, 2)); 58 | a->line_3d.deltax /= a->line_3d.pixels; 59 | a->line_3d.deltay /= a->line_3d.pixels; 60 | return (0); 61 | } 62 | 63 | int ft_initline(t_adata *a) 64 | { 65 | a->line.start_x = a->joe.x; 66 | a->line.start_y = a->joe.y; 67 | a->line.end_x = a->joe.x + (cos(a->joe.rotangle) * a->map.tile_size); 68 | a->line.end_y = a->joe.y + (sin(a->joe.rotangle) * a->map.tile_size); 69 | a->line.deltax = a->line.end_x - a->line.start_x; 70 | a->line.deltay = a->line.end_y - a->line.start_y; 71 | a->line.pixels = sqrt(pow(a->line.deltax, 2) + pow(a->line.deltay, 2)); 72 | a->line.deltax /= a->line.pixels; 73 | a->line.deltay /= a->line.pixels; 74 | a->line.color = 0xb87cb3; 75 | return (0); 76 | } 77 | -------------------------------------------------------------------------------- /mandatory_game/cast_rays_vertical.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cast_rays_vertical.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/19 15:58:10 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:35:00 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | /* Vertical casting is different if the player is left or right because we need to check if a particular wall intersection is a hit or not. 15 | But because these wall hits are located on the perifery of the wall we need to add or subtract 1 to the x position to make sure that is is inside the wall*/ 16 | int vertical_cast_facingright(t_adata *a, t_ray *ray, 17 | double *nexttouch_verx, double *nexttouch_very) 18 | { 19 | if (!ray->facing_left) 20 | { 21 | while (*nexttouch_verx >= 0 && (*nexttouch_verx) < a->map.map_w - 1 && 22 | *nexttouch_very >= 0 && (*nexttouch_very) < a->map.map_h - 1) 23 | { 24 | if (has_wall((*nexttouch_verx) + 1, *nexttouch_very, a)) 25 | { 26 | ray->found_ver_wall = 1; 27 | ray->wall_hit_verx = *nexttouch_verx; 28 | ray->wall_hit_very = *nexttouch_very; 29 | return (0); 30 | } 31 | else 32 | { 33 | *nexttouch_verx += ray->verxstep; 34 | *nexttouch_very += ray->verystep; 35 | } 36 | } 37 | } 38 | return (0); 39 | } 40 | 41 | int vertical_cast_facingleft(t_adata *a, t_ray *ray, 42 | double *nexttouch_verx, double *nexttouch_very) 43 | { 44 | if (ray->facing_left) 45 | { 46 | while (*nexttouch_verx >= 0 && *nexttouch_verx < a->map.map_w && 47 | *nexttouch_very >= 0 && *nexttouch_very < a->map.map_h) 48 | { 49 | if (has_wall((*nexttouch_verx) - 1, *nexttouch_very, a)) 50 | { 51 | ray->found_ver_wall = 1; 52 | ray->wall_hit_verx = *nexttouch_verx; 53 | ray->wall_hit_very = *nexttouch_very; 54 | break ; 55 | } 56 | else 57 | { 58 | *nexttouch_verx += ray->verxstep; 59 | *nexttouch_very += ray->verystep; 60 | } 61 | } 62 | } 63 | return (0); 64 | } 65 | 66 | int vertical_interstep(t_adata *a, t_ray *ray, 67 | double *nexttouch_verx, double *nexttouch_very) 68 | { 69 | double inter_y; 70 | double inter_x; 71 | 72 | inter_x = floor(a->joe.x / a->map.tile_size) * a->map.tile_size; 73 | if (!ray->facing_left) 74 | inter_x += a->map.tile_size; 75 | inter_y = a->joe.y + ((inter_x - a->joe.x) * tan(ray->ray_angle)); 76 | ray->verxstep = a->map.tile_size; 77 | if (ray->facing_left) 78 | ray->verxstep *= -1; 79 | ray->verystep = a->map.tile_size * tan(ray->ray_angle); 80 | if (!ray->facing_down && ray->verystep > 0) 81 | ray->verystep *= -1; 82 | if (ray->facing_down && ray->verystep < 0) 83 | ray->verystep *= -1; 84 | *nexttouch_verx = inter_x; 85 | *nexttouch_very = inter_y; 86 | return (0); 87 | } 88 | -------------------------------------------------------------------------------- /libft/libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/01/28 19:17:56 by gleal #+# #+# */ 9 | /* Updated: 2021/02/16 19:47:28 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | 23 | typedef struct s_list 24 | { 25 | void *content; 26 | struct s_list *next; 27 | } t_list; 28 | 29 | void *ft_memset(void *b, int c, size_t len); 30 | void ft_bzero(void *s, size_t n); 31 | void *ft_memcpy(void *dst, const void *src, size_t n); 32 | void *ft_memccpy(void *dst, const void *src, int c, size_t n); 33 | void *ft_memmove(void *dst, const void *src, size_t len); 34 | void *ft_memchr(const void *s, int c, size_t n); 35 | int ft_memcmp(const void *s1, const void *s2, size_t n); 36 | size_t ft_strlen(const char *s); 37 | size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); 38 | size_t ft_strlcat(char *dst, const char *src, size_t dstsize); 39 | char *ft_strchr(const char *s, int c); 40 | char *ft_strrchr(const char *s, int c); 41 | char *ft_strnstr(const char *haystack, const char *needle, 42 | size_t len); 43 | int ft_strncmp(const char *s1, const char *s2, size_t n); 44 | int ft_atoi(const char *str); 45 | int ft_isalpha(int c); 46 | int ft_isdigit(int c); 47 | int ft_isalnum(int c); 48 | int ft_isascii(int c); 49 | int ft_isprint(int c); 50 | int ft_toupper(int c); 51 | int ft_tolower(int c); 52 | void *ft_calloc(size_t count, size_t size); 53 | char *ft_strdup(const char *s1); 54 | char *ft_substr(char const *s, unsigned int start, size_t len); 55 | char *ft_strjoin(char const *s1, char const *s2); 56 | char *ft_strtrim(char const *s1, char const *set); 57 | char **ft_split(char const *s, char c); 58 | char *ft_itoa(int n); 59 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 60 | void ft_putchar_fd(char c, int fd); 61 | void ft_putstr_fd(char *s, int fd); 62 | void ft_putendl_fd(char *s, int fd); 63 | void ft_putnbr_fd(int n, int fd); 64 | void ft_putnbr_fd(int n, int fd); 65 | t_list *ft_lstnew(void *content); 66 | void ft_lstadd_front(t_list **lst, t_list *new); 67 | int ft_lstsize(t_list *lst); 68 | t_list *ft_lstlast(t_list *lst); 69 | void ft_lstadd_back(t_list **lst, t_list *new); 70 | void ft_lstdelone(t_list *lst, void (*del)(void*)); 71 | void ft_lstclear(t_list **lst, void (*del)(void*)); 72 | void ft_lstiter(t_list *lst, void (*f)(void *)); 73 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), 74 | void (*del)(void *)); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_map.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_map.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/25 17:36:21 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:05:39 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* The way I interpreted a closed map was a map in which the inside of the map is completely 15 | surrounded by walls (including corners), this will is important when doing raycasting to identify if 16 | there is a wall in that coordinate */ 17 | int check_all_sides(char **strs, int j) 18 | { 19 | if (ft_isspace(strs[-1][j - 1]) || !strs[-1][j - 1]) 20 | return (0); 21 | if (ft_isspace(strs[-1][j]) || !strs[-1][j]) 22 | return (0); 23 | if (ft_isspace(strs[-1][j + 1]) || !strs[-1][j + 1]) 24 | return (0); 25 | if (ft_isspace(strs[0][j - 1]) || !strs[0][j - 1]) 26 | return (0); 27 | if (ft_isspace(strs[0][j + 1]) || !strs[0][j + 1]) 28 | return (0); 29 | if (ft_isspace(strs[1][j - 1]) || !strs[1][j - 1]) 30 | return (0); 31 | if (ft_isspace(strs[1][j]) || !strs[1][j]) 32 | return (0); 33 | if (ft_isspace(strs[1][j + 1]) || !strs[1][j + 1]) 34 | return (0); 35 | return (1); 36 | } 37 | 38 | int checkmapclosed(char **strs) 39 | { 40 | int j; 41 | 42 | j = 0; 43 | while (strs[0][j]) 44 | { 45 | if (ft_strchr(MAP_INSIDE, strs[0][j])) 46 | { 47 | if (!check_all_sides(strs, j)) 48 | return (0); 49 | } 50 | j++; 51 | } 52 | return (1); 53 | } 54 | /* making sure there is a player in game after parsing the map */ 55 | int playeringame(t_parse *parse) 56 | { 57 | if (!parse->player_or) 58 | return (0); 59 | else 60 | return (1); 61 | } 62 | /* The first wall can only have spaces and 1s */ 63 | int checkwall(char *str) 64 | { 65 | while (*str) 66 | { 67 | if (*str != '1' && !ft_isspace(*str)) 68 | return (0); 69 | str++; 70 | } 71 | return (1); 72 | } 73 | /* I also do the check for the last wall. In case someone decides to separate the map in 2 one of the halves won't have 74 | a player and it will trigger an error */ 75 | int check_valid_map(char **strs, t_parse *parse) 76 | { 77 | int i; 78 | 79 | i = -1; 80 | while (is_map(strs[++i])) 81 | { 82 | parse->nbr_str = i; 83 | if (i == 0 && !checkwall(strs[i])) 84 | return (0); 85 | else if (!is_map(strs[i + 1])) 86 | { 87 | if (i < 2) 88 | return (0); 89 | if (!playeringame(parse)) 90 | return (0); 91 | } 92 | else 93 | { 94 | if (!checkmapclosed(&strs[i]) || 95 | !checkmultiplayer(strs[i], parse)) 96 | return (0); 97 | } 98 | } 99 | if (!ft_copy_map(strs, parse)) 100 | return (0); 101 | return (1); 102 | } 103 | -------------------------------------------------------------------------------- /mandatory_game/ft_prepare_lines.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_prepare_lines.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 19:17:21 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 16:36:50 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | int ft_prepare_sprite_line(t_item *item, t_adata *a, 16 | int col_id) 17 | { 18 | double line_height; 19 | 20 | line_height = item->sprite_h; 21 | a->line_sp.start_x = col_id; 22 | a->line_sp.start_y = (a->win.win_h / 2) - (line_height * 11 / 40); 23 | if (a->line_sp.start_y < 0) 24 | a->line_sp.start_y = 0; 25 | a->line_sp.end_x = col_id; 26 | a->line_sp.end_y = (a->win.win_h / 2) + (line_height * 29 / 40); 27 | if (a->line_sp.end_y >= a->win.win_h) 28 | a->line_sp.end_y = a->win.win_h - 1.0; 29 | a->line_sp.deltax = a->line_sp.end_x - a->line_sp.start_x; 30 | a->line_sp.deltay = a->line_sp.end_y - a->line_sp.start_y; 31 | a->line_sp.pixels = sqrt(pow(a->line_sp.deltax, 2) 32 | + pow(a->line_sp.deltay, 2)); 33 | a->line_sp.deltax /= a->line_sp.pixels; 34 | a->line_sp.deltay /= a->line_sp.pixels; 35 | return (0); 36 | } 37 | 38 | int ft_prepare_3d_line(double ray_angle, t_ray *ray, t_adata *a, int col_id) 39 | { 40 | double line_height; 41 | double nofish_dist; 42 | 43 | nofish_dist = (ray->distance / a->map.tile_size) * 44 | cos(ray_angle - a->joe.rotangle); 45 | line_height = a->ray.distprojplane / nofish_dist; 46 | a->line_3d.start_x = col_id; 47 | a->line_3d.start_y = (a->win.win_h / 2) - (line_height / 2); 48 | if (a->line_3d.start_y < 0) 49 | a->line_3d.start_y = 0; 50 | a->line_3d.end_x = col_id; 51 | a->line_3d.end_y = (a->win.win_h / 2) + (line_height / 2); 52 | if (a->line_3d.end_y >= a->win.win_h) 53 | a->line_3d.end_y = a->win.win_h - 1.0; 54 | a->line_3d.deltax = a->line_3d.end_x - a->line_3d.start_x; 55 | a->line_3d.deltay = a->line_3d.end_y - a->line_3d.start_y; 56 | a->line_3d.pixels = sqrt(pow(a->line_3d.deltax, 2) + 57 | pow(a->line_3d.deltay, 2)); 58 | a->line_3d.deltax /= a->line_3d.pixels; 59 | a->line_3d.deltay /= a->line_3d.pixels; 60 | find_text_wallhit(ray_angle, ray, a); 61 | return (0); 62 | } 63 | 64 | int ft_initline(t_adata *a) 65 | { 66 | a->line.start_x = a->joe.x; 67 | a->line.start_y = a->joe.y; 68 | a->line.end_x = a->joe.x + (cos(a->joe.rotangle) * a->map.tile_size); 69 | a->line.end_y = a->joe.y + (sin(a->joe.rotangle) * a->map.tile_size); 70 | a->line.deltax = a->line.end_x - a->line.start_x; 71 | a->line.deltay = a->line.end_y - a->line.start_y; 72 | a->line.pixels = sqrt(pow(a->line.deltax, 2) + pow(a->line.deltay, 2)); 73 | a->line.deltax /= a->line.pixels; 74 | a->line.deltay /= a->line.pixels; 75 | a->line.color = 0xb87cb3; 76 | return (0); 77 | } 78 | -------------------------------------------------------------------------------- /mandatory_game/cast_rays_horizontal.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cast_rays_horizontal.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/19 15:56:05 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:35:09 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | /* Horizontal casting is different if the player is facing up or down because we need to check if a particular wall intersection is a hit or not. 15 | But because these wall hits are located on the perifery of the wall we need to add or subtract 1 to the y position to make sure that is is inside the wall*/ 16 | int horizontal_cast_facingdown(t_adata *a, t_ray *ray, 17 | double *nexttouch_horx, double *nexttouch_hory) 18 | { 19 | if (ray->facing_down) 20 | { 21 | while (*nexttouch_horx >= 0 && (*nexttouch_horx) < a->map.map_w && 22 | *nexttouch_hory >= 0 && (*nexttouch_hory) < a->map.map_h) 23 | { 24 | if (has_wall(*nexttouch_horx, (*nexttouch_hory) + 1, a)) 25 | { 26 | ray->found_hor_wall = 1; 27 | ray->wall_hit_horx = (*nexttouch_horx); 28 | ray->wall_hit_hory = (*nexttouch_hory); 29 | return (0); 30 | } 31 | else 32 | { 33 | *nexttouch_horx += ray->horxstep; 34 | *nexttouch_hory += ray->horystep; 35 | } 36 | } 37 | } 38 | return (0); 39 | } 40 | 41 | int horizontal_cast_facingup(t_adata *a, t_ray *ray, 42 | double *nexttouch_horx, double *nexttouch_hory) 43 | { 44 | if (!ray->facing_down) 45 | { 46 | while (*nexttouch_horx >= 0 && *nexttouch_horx < a->map.map_w && 47 | *nexttouch_hory >= 0 && *nexttouch_hory < a->map.map_h) 48 | { 49 | if (has_wall(*nexttouch_horx, (*nexttouch_hory) - 1, a)) 50 | { 51 | ray->found_hor_wall = 1; 52 | ray->wall_hit_horx = (*nexttouch_horx); 53 | ray->wall_hit_hory = (*nexttouch_hory); 54 | break ; 55 | } 56 | else 57 | { 58 | (*nexttouch_horx) += ray->horxstep; 59 | (*nexttouch_hory) += ray->horystep; 60 | } 61 | } 62 | } 63 | return (0); 64 | } 65 | 66 | int horizontal_interstep(t_adata *a, t_ray *ray, 67 | double *nexttouch_horx, double *nexttouch_hory) 68 | { 69 | double inter_y; 70 | double inter_x; 71 | 72 | inter_y = floor(a->joe.y / a->map.tile_size) * a->map.tile_size; 73 | if (ray->facing_down) 74 | inter_y += a->map.tile_size; 75 | inter_x = a->joe.x + ((inter_y - a->joe.y) / tan(ray->ray_angle)); 76 | ray->horystep = a->map.tile_size; 77 | if (!ray->facing_down) 78 | ray->horystep *= -1; 79 | ray->horxstep = a->map.tile_size / tan(ray->ray_angle); 80 | if (ray->facing_left && ray->horxstep > 0) 81 | ray->horxstep *= -1; 82 | if (!ray->facing_left && ray->horxstep < 0) 83 | ray->horxstep *= -1; 84 | *nexttouch_horx = inter_x; 85 | *nexttouch_hory = inter_y; 86 | return (0); 87 | } 88 | -------------------------------------------------------------------------------- /bonus_game/draw2_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw2_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/28 17:28:05 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:47:44 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "bonuscub.h" 14 | /* Here is where I added the new textures and animations */ 15 | void pickaxe_animation(t_adata *a) 16 | { 17 | if (a->joe.anim_count == 0) 18 | { 19 | if (a->joe.anim_start) 20 | { 21 | draw_attack_pickaxe(a); 22 | a->joe.anim_count++; 23 | } 24 | else 25 | draw_normal_pickaxe(a); 26 | } 27 | else 28 | { 29 | draw_attack_pickaxe(a); 30 | a->joe.anim_count++; 31 | if (a->joe.anim_count >= 5) 32 | a->joe.anim_count = 0; 33 | } 34 | } 35 | 36 | int drawfloortxt(t_ray *ray, t_adata *a, int col_id) 37 | { 38 | double column_angle; 39 | int row; 40 | double x; 41 | double y; 42 | double distance; 43 | 44 | column_angle = normalrad(ray->ray_angle - a->joe.rotangle); 45 | row = a->line_3d.end_y + 1; 46 | while (row < a->win.win_h) 47 | { 48 | distance = ((0.5 / (row - a->win.win_h / 2)) * a->ray.distprojplane) / 49 | cos(column_angle); 50 | x = (a->joe.x / a->map.tile_size) + (distance * cos(ray->ray_angle)); 51 | y = (a->joe.y / a->map.tile_size) + (distance * sin(ray->ray_angle)); 52 | bitmap_offset_floor(a, &x, &y); 53 | if (x >= a->sotext.imgt.width) 54 | x = a->sotext.imgt.width - 1.0; 55 | if (y >= a->sotext.imgt.height) 56 | y = a->sotext.imgt.height - 1.0; 57 | a->img_3d.addr[(row * (int)a->win.win_w + col_id)] = 58 | a->sotext.imgt.addr[(int)y * a->sotext.imgt.width + (int)x]; 59 | row++; 60 | } 61 | return (0); 62 | } 63 | 64 | int draw_ceilingrgb(t_adata *a) 65 | { 66 | int p_w; 67 | int p_h; 68 | double adjust_height_half; 69 | 70 | adjust_height_half = ceil((double)(a->win.win_h / 2)) - 1; 71 | p_h = 0; 72 | while (p_h < (int)adjust_height_half) 73 | { 74 | p_w = 0; 75 | while (p_w < a->win.win_w) 76 | { 77 | a->img_3d.addr[(int)(p_h * a->win.win_w + p_w)] = 78 | create_trgb(0, a->parse.rceil, 79 | a->parse.gceil, a->parse.bceil); 80 | p_w++; 81 | } 82 | p_h++; 83 | } 84 | return (0); 85 | } 86 | 87 | int drawsps(t_ray *ray, t_adata *a, int col_id) 88 | { 89 | int i; 90 | 91 | i = 0; 92 | while (i < a->sps.number) 93 | { 94 | if ((a->sps.items[i]).is_visible && 95 | is_sprite_stripe(&a->sps.items[i], col_id) 96 | && ray->distance > a->sps.items[i].distance 97 | && a->sps.items[i].xstart > 0 && a->sps.items[i].xend < a->win.win_w) 98 | { 99 | ft_prepare_sprite_line(&a->sps.items[i], a, col_id); 100 | linesprite(&a->sps.items[i], a, col_id); 101 | } 102 | i++; 103 | } 104 | return (0); 105 | } 106 | -------------------------------------------------------------------------------- /extract_and_parse/text_extract.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* text_extract.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/03 19:53:19 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:20:38 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | 15 | void ft_replacetabs(char **temp, char **str, int len) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | temp[0][0] = '\0'; 21 | i = 0; 22 | j = 0; 23 | while (i < ft_strlen(str[0])) 24 | { 25 | if (str[0][i] == '\t') 26 | { 27 | strlcat((void *)temp[0], " ", len); 28 | j += 4; 29 | } 30 | else 31 | { 32 | temp[0][j] = str[0][i]; 33 | j++; 34 | } 35 | i++; 36 | } 37 | temp[0][j] = '\0'; 38 | free(*str); 39 | *str = 0; 40 | } 41 | 42 | void *ft_realloctabs(char *str, int tab_nbr) 43 | { 44 | int len; 45 | char *temp; 46 | 47 | len = ft_strlen(str) + (tab_nbr * 3); 48 | temp = malloc(sizeof(char) * len + 1); 49 | if (!temp) 50 | return (0); 51 | ft_replacetabs(&temp, &str, len); 52 | return (temp); 53 | } 54 | /* As I mention in the Readme file one thing that we need to do is to replace tabs for spaces. 55 | To realloc tabs I multiply by 3 because we add 4 spaces and delete a tab */ 56 | int ft_tabtospace(t_parse *parse) 57 | { 58 | int i; 59 | int tab_nbr; 60 | 61 | i = 0; 62 | while (parse->text[i]) 63 | { 64 | if (ft_strchr(parse->text[i], '\t')) 65 | { 66 | tab_nbr = ft_countchr(parse->text[i], '\t'); 67 | parse->text[i] = ft_realloctabs(parse->text[i], tab_nbr); 68 | if (!parse->text[i]) 69 | { 70 | ft_free_to_str(&parse->text, i - 1); 71 | return (0); 72 | } 73 | } 74 | i++; 75 | } 76 | return (1); 77 | } 78 | 79 | int ft_new_line(t_parse *parse) 80 | { 81 | char **temp; 82 | int i; 83 | 84 | i = 0; 85 | (parse->lnbr)++; 86 | temp = malloc(sizeof(char *) * ((parse->lnbr) + 2)); 87 | if (!temp) 88 | { 89 | ft_freetext(parse->text); 90 | return (0); 91 | } 92 | while (parse->text[i]) 93 | { 94 | temp[i] = parse->text[i]; 95 | i++; 96 | } 97 | temp[parse->lnbr] = 0; 98 | temp[parse->lnbr + 1] = 0; 99 | free(parse->text); 100 | parse->text = temp; 101 | return (1); 102 | } 103 | /* To extract the text I first created a char ** with space for 2 strings and put zero on both of them. 104 | Then in my loop, as long as get_next_line function doesnt reach the end I keep adding space (reallocating memory) 105 | so that new lines can be added */ 106 | int cub_extract(t_parse *parse, int fd) 107 | { 108 | while (get_next_line(fd, &(parse->text[parse->lnbr])) > 0) 109 | { 110 | if (!ft_new_line(parse)) 111 | return (ft_error(PARSING_ERROR)); 112 | } 113 | if (!ft_tabtospace(parse)) 114 | return (ft_error(PARSING_ERROR)); 115 | return (1); 116 | } 117 | -------------------------------------------------------------------------------- /mandatory_game/update_sprites.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* update_sprites.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/18 18:32:47 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:43:53 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | /* the reason I multiply it by 0.8 is because I felt the some sprites were too big.(unnecessary)*/ 15 | int spritescreenposition(t_item *item, t_adata *a) 16 | { 17 | double centersprite; 18 | 19 | item->sprite_w = ((item->imgsp.width / item->imgsp.height) * 20 | a->ray.distprojplane) * 0.8 / 21 | (item->distance / a->map.tile_size); 22 | item->sprite_h = a->ray.distprojplane * 0.8 / 23 | (item->distance / a->map.tile_size); 24 | item->ystart = a->win.win_h / 2 - 25 | (item->sprite_h / 2); 26 | item->yend = item->ystart + item->sprite_h; 27 | centersprite = tan(item->angle) * a->ray.distprojplane; 28 | item->xstart = a->win.win_w / 2 + centersprite - item->sprite_w / 2; 29 | item->xend = item->xstart + item->sprite_w; 30 | return (0); 31 | } 32 | 33 | int sps_pos_on_screen(t_item *item, t_adata *a) 34 | { 35 | int i; 36 | 37 | i = 0; 38 | while (i < a->sps.number) 39 | { 40 | if (item[i].is_visible) 41 | spritescreenposition(&item[i], a); 42 | i++; 43 | } 44 | return (0); 45 | } 46 | 47 | int sort_sps(t_item *items, t_adata *a) 48 | { 49 | int further; 50 | int check; 51 | t_item swap; 52 | 53 | check = 0; 54 | further = 0; 55 | while (further < a->sps.number) 56 | { 57 | check = further + 1; 58 | while (check < a->sps.number) 59 | { 60 | if (items[check].distance > items[further].distance) 61 | { 62 | swap = items[further]; 63 | items[further] = items[check]; 64 | items[check] = swap; 65 | } 66 | check++; 67 | } 68 | further++; 69 | } 70 | return (0); 71 | } 72 | 73 | int update_info_sps(t_item **item, t_adata *a) 74 | { 75 | int i; 76 | double sp_anglemap; 77 | double vetx; 78 | double vety; 79 | 80 | i = 0; 81 | while (i < a->sps.number) 82 | { 83 | vetx = (*item)[i].x - a->joe.x; 84 | vety = (*item)[i].y - a->joe.y; 85 | sp_anglemap = normalrad(atan2(vety, vetx)); 86 | (*item)[i].angle = normalrad(sp_anglemap - a->joe.rotangle); 87 | if (((*item)[i].angle > a->ray.fovref_min && 88 | (*item)[i].angle < 2 * M_PI) || 89 | ((*item)[i].angle >= 0 && (*item)[i].angle < a->ray.fovref_max)) 90 | (*item)[i].is_visible = 1; 91 | else 92 | (*item)[i].is_visible = 0; 93 | (*item)[i].distance = (double)(sqrt(pow(vetx, 2) + pow(vety, 2))); 94 | i++; 95 | } 96 | return (0); 97 | } 98 | 99 | int update_sprites(t_adata *a) 100 | { 101 | update_info_sps(&a->sps.items, a); 102 | sort_sps(a->sps.items, a); 103 | sps_pos_on_screen(a->sps.items, a); 104 | return (0); 105 | } 106 | -------------------------------------------------------------------------------- /extract_and_parse/ft_parse_rgbs.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_parse_rgbs.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/29 18:03:13 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:08:20 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "cub3d.h" 14 | /* checking if the RGB values given are valid */ 15 | int ft_rgb_ceil_check(t_parse *parse) 16 | { 17 | if (parse->rceil < 0 || parse->rceil > 255) 18 | return (0); 19 | if (parse->gceil < 0 || parse->gceil > 255) 20 | return (0); 21 | if (parse->bceil < 0 || parse->bceil > 255) 22 | return (0); 23 | return (1); 24 | } 25 | 26 | int ft_rgb_floor_check(t_parse *parse) 27 | { 28 | if (parse->rfloor < 0 || parse->rfloor > 255) 29 | return (0); 30 | if (parse->gfloor < 0 || parse->gfloor > 255) 31 | return (0); 32 | if (parse->bfloor < 0 || parse->bfloor > 255) 33 | return (0); 34 | return (1); 35 | } 36 | 37 | int ft_parseceilcolor(char *str, t_parse *parse) 38 | { 39 | int i; 40 | 41 | i = 1; 42 | while (ft_isspace(str[i]) || str[i] == ',') 43 | i++; 44 | if (!isdigit(str[i])) 45 | return (0); 46 | parse->rceil = ft_atoi(&str[i]); 47 | while (ft_isdigit(str[i])) 48 | i++; 49 | while (ft_isspace(str[i]) || str[i] == ',') 50 | i++; 51 | if (!isdigit(str[i])) 52 | return (0); 53 | parse->gceil = ft_atoi(&str[i]); 54 | while (ft_isdigit(str[i])) 55 | i++; 56 | while (ft_isspace(str[i]) || str[i] == ',') 57 | i++; 58 | if (!isdigit(str[i])) 59 | return (0); 60 | parse->bceil = ft_atoi(&str[i]); 61 | return (ft_rgb_ceil_check(parse)); 62 | } 63 | 64 | int ft_parsefloorcolor(char *str, t_parse *parse) 65 | { 66 | int i; 67 | 68 | i = 1; 69 | while (ft_isspace(str[i]) || str[i] == ',') 70 | i++; 71 | if (!isdigit(str[i])) 72 | return (0); 73 | parse->rfloor = ft_atoi(&str[i]); 74 | while (ft_isdigit(str[i])) 75 | i++; 76 | while (ft_isspace(str[i]) || str[i] == ',') 77 | i++; 78 | if (!isdigit(str[i])) 79 | return (0); 80 | parse->gfloor = ft_atoi(&str[i]); 81 | while (ft_isdigit(str[i])) 82 | i++; 83 | while (ft_isspace(str[i]) || str[i] == ',') 84 | i++; 85 | if (!isdigit(str[i])) 86 | return (0); 87 | parse->bfloor = ft_atoi(&str[i]); 88 | return (ft_rgb_floor_check(parse)); 89 | } 90 | 91 | int check_rgbs(char **text, t_parse *parse, int *i, int *count) 92 | { 93 | if (text[(*i)][0] == 'F') 94 | { 95 | if (parse->rfloor || parse->gfloor || parse->bfloor) 96 | return (ft_error(MULTIFLOOR)); 97 | if (!ft_parsefloorcolor(text[(*i)], parse)) 98 | return (ft_error(BADFLOOR)); 99 | (*count)++; 100 | (*i)++; 101 | } 102 | if (text[(*i)][0] == 'C') 103 | { 104 | if (parse->rceil || parse->gceil || parse->bceil) 105 | return (ft_error(MULTICEIL)); 106 | if (!ft_parseceilcolor(text[(*i)], parse)) 107 | return (ft_error(BADCEIL)); 108 | (*count)++; 109 | (*i)++; 110 | } 111 | return (1); 112 | } 113 | -------------------------------------------------------------------------------- /mandatory_game/bmp_screenshot.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* bmp_screenshot.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/22 16:07:24 by gleal #+# #+# */ 9 | /* Updated: 2021/03/28 15:54:17 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "start_game.h" 14 | 15 | static void set_header(unsigned char *header, int param) 16 | { 17 | header[0] = (unsigned char)(param); 18 | header[1] = (unsigned char)(param >> 8); 19 | header[2] = (unsigned char)(param >> 16); 20 | header[3] = (unsigned char)(param >> 24); 21 | } 22 | 23 | static void init_header(t_adata *a, t_bmp *bmp) 24 | { 25 | int i; 26 | 27 | i = 0; 28 | while (i < 14) 29 | bmp->fileheader[i++] = 0; 30 | bmp->fileheader[0] = 'B'; 31 | bmp->fileheader[1] = 'M'; 32 | bmp->fileheader[10] = 54; 33 | i = 0; 34 | while (i < 40) 35 | bmp->infoheader[i++] = 0; 36 | bmp->infoheader[0] = 40; 37 | bmp->infoheader[12] = 1; 38 | bmp->infoheader[14] = 24; 39 | i = 0; 40 | while (i < 3) 41 | bmp->pad[i++] = 0; 42 | set_header(&bmp->fileheader[2], bmp->filesize); 43 | set_header(&bmp->infoheader[4], a->win.win_w); 44 | set_header(&bmp->infoheader[8], a->win.win_h); 45 | write(bmp->fd, bmp->fileheader, 14); 46 | write(bmp->fd, bmp->infoheader, 40); 47 | } 48 | 49 | static void draw_bmp(t_adata *a, t_bmp *bmp) 50 | { 51 | int i; 52 | int j; 53 | unsigned char buffer[3]; 54 | 55 | j = (a->win.win_h - 1); 56 | while (j >= 0) 57 | { 58 | i = 0; 59 | while (i <= a->win.win_w - 1) 60 | { 61 | buffer[0] = (unsigned char)(a->img_3d.addr[((int)j * 62 | (int)(a->win.win_w) + (int)i)]); 63 | buffer[1] = (unsigned char)(a->img_3d.addr[((int)j * 64 | (int)(a->win.win_w) + (int)i)] >> 8); 65 | buffer[2] = (unsigned char)(a->img_3d.addr[((int)j * 66 | (int)(a->win.win_w) + (int)i)] >> 16); 67 | write(bmp->fd, buffer, 3); 68 | i++; 69 | } 70 | j--; 71 | } 72 | } 73 | 74 | void convert_bmp(t_adata *a) 75 | { 76 | t_bmp bmp; 77 | 78 | bmp.filesize = 54 + 3 * (a->win.win_w) * (a->win.win_h); 79 | bmp.img = malloc((sizeof(char) * 3 * (a->win.win_w) * (a->win.win_h))); 80 | ft_memset(bmp.img, 0, 3 * (a->win.win_w) * (a->win.win_h)); 81 | bmp.fd = open("img.bmp", O_CREAT | O_WRONLY, S_IRWXU); 82 | init_header(a, &bmp); 83 | draw_bmp(a, &bmp); 84 | free(bmp.img); 85 | close(bmp.fd); 86 | } 87 | 88 | void screenshot(char *cubname) 89 | { 90 | int fd; 91 | t_adata a; 92 | 93 | ft_start_tmap(&a.parse); 94 | fd = open(cubname, O_RDONLY); 95 | cub_extract(&a.parse, fd); 96 | if (a.parse.error) 97 | { 98 | printf("there was an error while extracting"); 99 | return ; 100 | } 101 | if (!ft_parse_cub(a.parse.text, &a.parse)) 102 | return ; 103 | ft_init_all(&a); 104 | ftinit_img_3d(&a); 105 | ft_update_player(&a); 106 | update_sprites(&a); 107 | draw_floorrgb(&a); 108 | draw_ceilingrgb(&a); 109 | draw3d(&a); 110 | draw_map(&a); 111 | convert_bmp(&a); 112 | destroyimg(&a, &a.img_3d); 113 | } 114 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: gleal +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/02/09 15:43:58 by gleal #+# #+# # 9 | # Updated: 2021/03/29 22:17:15 by gleal ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | CC := gcc 14 | FLAGS := -Wall -Wextra -Werror 15 | INCLUDE_DIRS := includes \ 16 | extract_and_parse \ 17 | mandatory_game 18 | INCLUDES := $(addprefix -I, $(INCLUDE_DIRS)) 19 | NAME := cub3D 20 | SRCS_COMMON := ./extract_and_parse/text_extract.c \ 21 | ./extract_and_parse/ft_parse_cub.c \ 22 | ./extract_and_parse/ft_parse_resolution.c \ 23 | ./extract_and_parse/ft_parse_textures.c \ 24 | ./extract_and_parse/ft_parse_textures2.c \ 25 | ./extract_and_parse/ft_parse_rgbs.c \ 26 | ./extract_and_parse/ft_parse_map.c \ 27 | ./extract_and_parse/ft_parse_map2.c \ 28 | ./extract_and_parse/ft_parse_utils.c \ 29 | ./extract_and_parse/ft_parse_utils2.c \ 30 | ./mandatory_game/ft_init.c \ 31 | ./mandatory_game/ft_init2.c \ 32 | ./mandatory_game/ft_initdestroyimg.c \ 33 | ./mandatory_game/update_sprites.c \ 34 | ./mandatory_game/cast_rays_horizontal.c \ 35 | ./mandatory_game/cast_rays_vertical.c \ 36 | ./mandatory_game/horiz_vert_raycomp.c \ 37 | ./mandatory_game/start_game_utils.c \ 38 | ./mandatory_game/start_game_utils2.c \ 39 | ./mandatory_game/start_game_utils3.c \ 40 | ./mandatory_game/color_utils.c \ 41 | ./other_utils/free_utils.c \ 42 | ./other_utils/ft_error.c 43 | OBJS_COMMON := $(SRCS_COMMON:.c=.o) 44 | SRCS_MANDATORY := cub3d.c \ 45 | ./mandatory_game/start_game.c \ 46 | ./mandatory_game/events.c \ 47 | ./mandatory_game/update.c \ 48 | ./mandatory_game/cast_rays.c \ 49 | ./mandatory_game/ft_prepare_lines.c \ 50 | ./mandatory_game/lines.c \ 51 | ./mandatory_game/draw.c \ 52 | ./mandatory_game/draw2.c \ 53 | ./mandatory_game/bitmap_offsets.c \ 54 | ./mandatory_game/bmp_screenshot.c 55 | OBJS_MANDATORY := $(SRCS_MANDATORY:.c=.o) 56 | SRCS_BONUS := ./bonus_game/cub3d_bonus.c \ 57 | ./bonus_game/start_game_bonus.c \ 58 | ./bonus_game/events_bonus.c \ 59 | ./bonus_game/update_bonus.c \ 60 | ./bonus_game/cast_rays_bonus.c \ 61 | ./bonus_game/ft_prepare_lines_bonus.c \ 62 | ./bonus_game/lines_bonus.c \ 63 | ./bonus_game/draw_bonus.c \ 64 | ./bonus_game/draw2_bonus.c \ 65 | ./bonus_game/bitmap_offsets_bonus.c \ 66 | ./bonus_game/ft_init_anim_bonus.c \ 67 | ./bonus_game/utils_normal_pickaxe_bonus.c \ 68 | ./bonus_game/utils_attack_pickaxe_bonus.c 69 | OBJS_BONUS := $(SRCS_BONUS:.c=.o) 70 | 71 | all: libft minilibx $(NAME) 72 | 73 | libft: 74 | make -C libft/ 75 | 76 | minilibx: 77 | make -C minilibx/ 78 | 79 | %.o : %.c 80 | $(CC) $(FLAGS) -c $^ -o $@ $(INCLUDES) 81 | 82 | $(NAME) : $(OBJS_COMMON) $(OBJS_MANDATORY) 83 | $(CC) $(FLAGS) $^ -Lminilibx/ -lmlx -framework OpenGL -framework AppKit -Llibft -lft -o $@ $(INCLUDES) 84 | 85 | bonus: libft minilibx bonus_comp 86 | 87 | bonus_comp: $(OBJS_COMMON) $(OBJS_BONUS) 88 | $(CC) $(FLAGS) $^ -Lminilibx/ -lmlx -framework OpenGL -framework AppKit -Llibft -lft -o bonus $(INCLUDES) 89 | 90 | clean: 91 | rm -f $(OBJS_COMMON) 92 | rm -f $(OBJS_MANDATORY) 93 | rm -f $(OBJS_BONUS) 94 | $(MAKE) -C libft/ clean 95 | $(MAKE) -C minilibx/ clean 96 | 97 | fclean: clean 98 | rm -f $(NAME) 99 | rm -f bonus 100 | $(MAKE) -C libft/ fclean 101 | 102 | re: fclean all 103 | 104 | .PHONY: libft minilibx all bonus clean fclean re 105 | -------------------------------------------------------------------------------- /includes/structs.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* structs.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: gleal +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/03/19 19:46:44 by gleal #+# #+# */ 9 | /* Updated: 2021/04/01 00:22:16 by gleal ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef STRUCTS_H 14 | # define STRUCTS_H 15 | /* Having multiple structs helps us have variables organized by their usage. 16 | We can then have a master struct which connects all the structs */ 17 | typedef struct s_bmp 18 | { 19 | int filesize; 20 | char *img; 21 | unsigned char fileheader[14]; 22 | unsigned char infoheader[40]; 23 | unsigned char pad[3]; 24 | int color; 25 | int fd; 26 | } t_bmp; 27 | 28 | typedef struct s_parse 29 | { 30 | int lnbr; 31 | char **text; 32 | int error; 33 | int rx; 34 | int ry; 35 | char *no_text; 36 | char *so_text; 37 | char *we_text; 38 | char *ea_text; 39 | char *sprite_text; 40 | int rfloor; 41 | int gfloor; 42 | int bfloor; 43 | int rceil; 44 | int gceil; 45 | int bceil; 46 | int map_size; 47 | char player_or; 48 | char **mapstr; 49 | int nbr_str; 50 | } t_parse; 51 | 52 | typedef struct s_win 53 | { 54 | void *mlx; 55 | double win_w; 56 | double win_h; 57 | void *win; 58 | } t_win; 59 | 60 | typedef struct s_img 61 | { 62 | void *ptr; 63 | int *addr; 64 | int pixel_bits; 65 | int line_bytes; 66 | int endian; 67 | int width; 68 | int height; 69 | } t_img; 70 | 71 | typedef struct s_map2d 72 | { 73 | double tile_size; 74 | char **maptxt; 75 | int map_w; 76 | int map_h; 77 | double map_rows; 78 | double map_cols; 79 | double map_r_half; 80 | double map_b_half; 81 | } t_map2d; 82 | 83 | typedef struct s_player 84 | { 85 | double x; 86 | double y; 87 | double radius; 88 | char walkdir; 89 | int turndir; 90 | double rotangle; 91 | double movespeed; 92 | double rotatespeed; 93 | int anim_start; 94 | int anim_count; 95 | } t_player; 96 | 97 | typedef struct s_line 98 | { 99 | double start_x; 100 | double start_y; 101 | double end_x; 102 | double end_y; 103 | int color; 104 | double deltax; 105 | double deltay; 106 | double pixels; 107 | } t_line; 108 | 109 | typedef struct s_text 110 | { 111 | char *text_name; 112 | t_img imgt; 113 | } t_text; 114 | 115 | typedef struct s_ray 116 | { 117 | double fov; 118 | double fovref_min; 119 | double fovref_max; 120 | double wall_strip_w; 121 | int num_rays; 122 | double distprojplane; 123 | double ray_angle; 124 | int facing_down; 125 | int facing_left; 126 | double horxstep; 127 | double horystep; 128 | double verxstep; 129 | double verystep; 130 | double wall_hit_horx; 131 | double wall_hit_hory; 132 | double wall_hit_verx; 133 | double wall_hit_very; 134 | double wall_hit_x; 135 | double wall_hit_y; 136 | int found_hor_wall; 137 | int found_ver_wall; 138 | double distance; 139 | int hit_vertical; 140 | t_text text_wallhit; 141 | t_line line; 142 | } t_ray; 143 | 144 | typedef struct s_item 145 | { 146 | double x; 147 | double y; 148 | double angle; 149 | double distance; 150 | double sprite_h; 151 | double sprite_w; 152 | double ystart; 153 | double yend; 154 | double xstart; 155 | double xend; 156 | int is_visible; 157 | t_img imgsp; 158 | } t_item; 159 | 160 | typedef struct s_sps 161 | { 162 | int number; 163 | t_item *items; 164 | } t_sps; 165 | 166 | typedef struct s_adata 167 | { 168 | t_parse parse; 169 | t_win win; 170 | t_map2d map; 171 | t_player joe; 172 | t_img img_m; 173 | t_img img_3d; 174 | t_line line_3d; 175 | t_line line; 176 | t_ray ray; 177 | t_text notext; 178 | t_text sotext; 179 | t_text eatext; 180 | t_text wetext; 181 | t_sps sps; 182 | t_line line_sp; 183 | t_img imgflr; 184 | } t_adata; 185 | 186 | #endif 187 | -------------------------------------------------------------------------------- /minilibx/mlx.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx.h for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 16:37:50 2000 Charlie Root 8 | ** Last update Tue Oct 01 16:23:28 2014 Olivier Crouzet 9 | */ 10 | 11 | /* 12 | ** MinilibX - Please report bugs 13 | */ 14 | 15 | 16 | /* 17 | ** FR msg - FR msg - FR msg 18 | ** 19 | ** MacOSX 20 | ** La MinilibX utilise 2 frameworks Mac : OpenGL et AppKit 21 | ** qu'il faut ajouter a la compilation : 22 | ** -framework OpenGL -framework AppKit 23 | ** 24 | ** UNIX / Linux 25 | ** La MinilibX utilise 2 librairies supplementaires qu'il 26 | ** est necessaire de rajouter a la compilation : 27 | ** -lmlx -lXext -lX11 28 | ** 29 | ** La MinilibX permet le chargement des images de type Xpm. 30 | ** Notez que cette implementation est incomplete. 31 | ** 32 | ** Il y a des differences entre X11 et MacOS. 33 | ** les numeros des touches ne sont pas les memes, 34 | ** les numeros des boutons souris ne sont pas les memes. 35 | ** Egalement l'expose est gere differemment, et sous MacOS 36 | ** il est preferable d'entrer le plus tot possible dans mlx_loop, 37 | ** il est normal que les fenetres n'apparaissent pas avant mlx_loop 38 | ** (ou bien forcez avec mlx_do_sync mais c'est pas genial). 39 | ** Sous MacOS, l'octet Alpha est pris en compte dans toutes les 40 | ** images, et represente la transparence et non l'opacite comme 41 | ** c'est normalement le cas. 42 | */ 43 | 44 | 45 | #ifndef MLX_H 46 | 47 | #define MLX_H 48 | 49 | 50 | void *mlx_init(); 51 | /* 52 | ** needed before everything else. 53 | ** return (void *)0 if failed 54 | */ 55 | 56 | 57 | /* 58 | ** Basic actions 59 | */ 60 | 61 | void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title); 62 | /* 63 | ** return void *0 if failed 64 | */ 65 | int mlx_clear_window(void *mlx_ptr, void *win_ptr); 66 | int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color); 67 | /* 68 | ** origin for x & y is top left corner of the window 69 | ** y down is positive 70 | ** color is 0x00RRGGBB 71 | */ 72 | 73 | 74 | /* 75 | ** Image stuff 76 | */ 77 | 78 | void *mlx_new_image(void *mlx_ptr,int width,int height); 79 | /* 80 | ** return void *0 if failed 81 | */ 82 | char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel, 83 | int *size_line, int *endian); 84 | /* 85 | ** endian : 0 = sever X is little endian, 1 = big endian 86 | ** endian : useless on macos, client and graphical framework have the same endian 87 | */ 88 | int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr, 89 | int x, int y); 90 | unsigned int mlx_get_color_value(void *mlx_ptr, int color); 91 | 92 | 93 | /* 94 | ** dealing with Events 95 | */ 96 | 97 | int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param); 98 | int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param); 99 | int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param); 100 | 101 | int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param); 102 | int mlx_loop (void *mlx_ptr); 103 | 104 | 105 | /* 106 | ** hook funct are called as follow : 107 | ** 108 | ** expose_hook(void *param); 109 | ** key_hook(int keycode, void *param); 110 | ** mouse_hook(int button, int x,int y, void *param); 111 | ** loop_hook(void *param); 112 | ** 113 | */ 114 | 115 | 116 | /* 117 | ** Usually asked... 118 | */ 119 | 120 | int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color, 121 | char *string); 122 | void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data, 123 | int *width, int *height); 124 | void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename, 125 | int *width, int *height); 126 | void *mlx_png_file_to_image(void *mlx_ptr, char *file, int *width, int *height); 127 | 128 | int mlx_destroy_window(void *mlx_ptr, void *win_ptr); 129 | 130 | int mlx_destroy_image(void *mlx_ptr, void *img_ptr); 131 | 132 | /* 133 | ** generic hook system for all events, and minilibX functions that 134 | ** can be hooked. Some macro and defines from X11/X.h are needed here. 135 | */ 136 | 137 | int mlx_hook(void *win_ptr, int x_event, int x_mask, 138 | int (*funct)(), void *param); 139 | 140 | int mlx_mouse_hide(); 141 | int mlx_mouse_show(); 142 | int mlx_mouse_move(void *win_ptr, int x, int y); 143 | int mlx_mouse_get_pos(void *win_ptr, int *x, int *y); 144 | 145 | int mlx_do_key_autorepeatoff(void *mlx_ptr); 146 | int mlx_do_key_autorepeaton(void *mlx_ptr); 147 | int mlx_do_sync(void *mlx_ptr); 148 | 149 | #endif /* MLX_H */ 150 | -------------------------------------------------------------------------------- /textures/wood.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char *adc6dd8294a5417e8d21c5646f9668a5PAKLOnoIxrZECZgF[] = { 3 | /* columns rows colors chars-per-pixel */ 4 | "64 64 9 1 ", 5 | " c #28200C", 6 | ". c #382C14", 7 | "X c #403018", 8 | "o c #483818", 9 | "O c #543C1C", 10 | "+ c #5C4020", 11 | "@ c #6C4824", 12 | "# c #744C28", 13 | "$ c #905C34", 14 | /* pixels */ 15 | "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 16 | "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", 17 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", 18 | "OOOOOOO.O .OOOOOOOOOOOOOO.O .OOOO.O .OOOOOO.O .OOOOOOOOOOO.O .OO", 19 | "oo@####O$ O$+oooo##o@o@ooO$ O$#o#O$ O$+ooo+O$ O$o#oo#o#o##O$ O$@", 20 | "oo@###+O$ O$@oooO##o@o@ooO$ O$#o#O$ O$#+o+#O$ O$o#oo#o#o##O$ O$@", 21 | "oo+###OO$ O$#OooO##o@o@ooO$ O$@o#O$ O$##+##O$ O$o#oo#o#o##O$ O$@", 22 | "OoO@##OO$ O$#Ooo+#@o@o@ooO$ O$@o#O$ O$#####O$ O$o#oo#o#o##O$ O$@", 23 | "@oo+#+oO$ O$#+oO@#@o@o@ooO$ O$@o#O$ O$#####O$ O$o#oo#o#o@#O$ O$O", 24 | "@oOo+OoO$ O$#@o+##+o@o@ooO$ O$+o#O$ O$#####O$ O$o#oo#o#o@#O$ O$O", 25 | "#OooOooO$ O$##+@##+o@o@ooO$ O$+o#O$ O$#####O$ O$o#oo#o#o+#O$ O$O", 26 | "#OooooOO$ O$##@###Oo@o@ooO$ O$oo#O$ O$#####O$ O$o#oo#o#o+#O$ O$o", 27 | "@#oooO#O$ O$##@###Oo@o@ooO$ O$o+#O$ O$@####O$ O$o#oo#o#Oo#O$ O$o", 28 | "@#OooO#O$ O$#####@oo@o@ooO$ O$o+#O$ O$@###@O$ O$o#oo#o#Oo#O$ O$o", 29 | "+##oO##O$ O$#####@oo@o@ooO$ O$o##O$ O$+###@O$ O$o#oo#o#Oo#O$ O$o", 30 | "O###O#+O$ O$@####@oo@o@ooO$ O$+##O$ O$o@#@+O$ O$o#oo#o#Oo#O$ O$O", 31 | "o@##+#OO$ O$@####+oo@o@ooO$ O$+#@O$ O$o+@+oO$ O$o#oo#o#+o#O$ O$O", 32 | "o@####OO$ O$+####+oo@o@ooO$ O$##@O$ O$oo+ooO$ O$o#oo#o#+o@O$ O$O", 33 | "o+@###oO$ O$+####Ooo@o@ooO$ O$##+O$ O$oooooO$ O$o#oo#o#@o@O$ O$@", 34 | "oO@##+oO$ O$O@###OoO@o@ooO$ O$#@+O$ O$oooooO$ O$o#oo#o#@o@O$ O$@", 35 | "oo+##OoO$ O$O@##@ooO@o@ooO$ O$#@oO$ O$oooooO$ O$o#oo#o#@o+O$ O$@", 36 | "ooO##OoO$ O$o+##@ooO@o@ooO$ O$#+oO$ O$+ooo+O$ O$o#oo#o##o+O$ O$@", 37 | "OoO+OooO$ O$o+##+oo+@o@ooO$ O$@ooO$ O$@+o+@O$ O$o#oo#o@#ooO$ O$@", 38 | "OooOooOO$ O$oO@@+oo+@o@ooO$ O$+ooO$ O$#@+@#O$ O$o#oo#o@#OoO$ O$@", 39 | "OoooooOO$ O$oO++Ooo++o@ooO$ O$oooO$ O$##@##O$ O$o#oo#o+#OoO$ O$+", 40 | "@ooooo@O$ O$ooOOooo@Oo@ooO$ O$oooO$ O$#####O$ O$o#oo#o+#+oO$ O$O", 41 | "@ooooo@O$ O$ooooooo@Oo@ooO$ O$ooOO$ O$#####O$ O$o#oo#oO#+oO$ O$O", 42 | "@OoooO+O$ O$ooooooO#oo@ooO$ O$ooOO$ O$#####O$ O$o#oo#oO#@OO$ O$o", 43 | "+OoooOOO$ O$oooooo+#oo@ooO$ O$oo+O$ O$@####O$ O$o#oo#oO#@OO$ O$o", 44 | "O@ooo@OO$ O$oooooo+#oo@ooO$ O$oo@O$ O$@####O$ O$o#oo#oo##+o$ O$o", 45 | "O@Ooo@oO$ O$oooooo@#oo@ooO$ O$oO@O$ O$+###@O$ O$o#oo#oo##+O$ O$o", 46 | "o+Oo@+oO$ O$Oooooo@#oo@ooO$ O$o+#O$ O$+@##@O$ O$o#oo#oo@#@O$ O$o", 47 | "oO@O@OoO$ O$+ooooO#@oO@ooO$ O$O@#O$ O$o@##+O$ O$o#oo#oo@#@O$ O$o", 48 | "oO@O@OoO$ O$@Oooo+#@oO@ooO$ O$+##O$ O$o+#@oO$ O$o#oo#Oo+##O$ O$o", 49 | "oo+@+ooO$ O$#+ooO+#+o+@ooO$ O$@##O$ O$oo@+oO$ O$o#oo#Oo+##O$ O$O", 50 | "ooO+OooO$ O$#@OoO##Oo+@ooO$ O$###O$ O$oo+ooO$ O$o#oo#OoO##O$ O$O", 51 | "oooOoooO$ O$##+o+##Oo+@ooO$ O$##@O$ O$oooooO$ O$o#oo#OoO##O$ O$+", 52 | "oooooooO$ O$###+###oo@@ooO$ O$##@O$ O$oooooO$ O$o#oo#+oO##O$ O$@", 53 | "ooooooOO$ O$######@oo@@ooO$ O$##+O$ O$oooooO$ O$o#oo#+oo@#O$ O$@", 54 | "OoooooOO$ O$@#####@oo#@ooO$ O$#@+O$ O$+ooooO$ O$o#oo#@oo@#O$ O$@", 55 | "Oooooo+O$ O$@#####+oo#@ooO$ O$#@oO$ O$+ooooO$ O$o#oo@@oo+#O$ O$O", 56 | "@OoooO+O$ O$+#####Ooo#+ooO$ O$#+oO$ O$@+oo+O$ O$o#oo@#oo+#O$ O$O", 57 | "@OoooO@O$ O$O#####ooo#+ooO$ O$@+oO$ O$#+o++O$ O$o#oo+#OoO@O$ O$o", 58 | "@+OoO+@O$ O$o@###@ooO#oooO$ O$@ooO$ O$#@++@O$ O$o#oo+#OoO@O$ O$o", 59 | "@@OOO@+O$ O$o+###+oo+#oooO$ O$+ooO$ O$##+@#O$ O$o#ooO#OoO+O$ O$o", 60 | "+@+O+@OO$ O$oO@#@Ooo@#oooO$ O$oooO$ O$##@##O$ O$o#ooO#+oo+O$ O$o", 61 | "O@@+@@OO$ O$ooO@+ooo@#oooO$ O$ooOO$ O$#####O$ O$o#ooO#+OoOO$ O$o", 62 | "O@@+@@oO$ O$oooOOooo#@oooO$ O$ooOO$ O$#####O$ O$o#ooO#@OoOO$ O$o", 63 | "o@###@oO$ O$OooooooO#@oooO$ O$oo+O$ O$####@O$ O$o#ooo#@OoOO$ O$o", 64 | "o+###@oO$ O$Ooooooo+#+oooO$ O$oO@O$ O$@###@O$ O$o#ooo@#+ooO$ O$o", 65 | "oO@##@oO$ O$+oooooo@#+oooO$ O$o+#O$ O$@###+O$ O$o#ooo@#+OoO$ O$o", 66 | "oO@##+oO$ O$@Oooooo@#ooooO$ O$O@#O$ O$+###+O$ O$o#ooo+#@OoO$ O$O", 67 | "oo+#@+oO$ O$#OooooO#@ooooO$ O$@##O$ O$+##@OO$ O$o#ooo+#@+oO$ O$O", 68 | "ooO@@OoO$ O$#+oooo+#@oo+oO$ O$###O$ O$O@#@OO$ O$o#OooO@#+OO$ O$+", 69 | "ooO@+OoO$ O$@@Oooo@#+oo+oO$ O$###O$ O$O@#+oO$ O$o#OooO+#@OO$ O$+", 70 | "ooo++ooO$ O$@#OooO@#ooo@oO$ O$###O$ O$o+@OoO$ O$o#Oooo+#@OO$ O$@", 71 | "oooOOooO$ O$+#@OoO##ooo@oO$ O$###O$ O$oO+ooO$ O$o#OoooO@#OO$ O$@", 72 | "OoooooOO$ O$o@#@O##@ooo@oO$ O$###O$ O$ooOooO$ O$o@+oooO+#@O$ O$#", 73 | "OoooooOO$ O$o+#####+ooo#oO$ O$##@O$ O$oooooO$ O$o@@oooo+#@O$ O$#", 74 | "+ooooo@O$ O$oo####@ooo+#oO$ O$##@O$ O$oooooO$ O$o+@OoooO@@O$ O$#", 75 | "+OoooO@O$ O$oo+@#@+ooo@#oO$ O$#@+O$ O$oooooO$ O$o+#Ooooo++O$ O$#", 76 | "@OoooO@O$ O$ooo+@+oooo@#oO$ O$#@+O$ O$oooooO$ O$oo#OoooooOO$ O$#", 77 | "@+oooO@O$ O$oooo+oooo@##+O$ O$@+oO$ O$oooooO$ O$+o#+ooooooO$ O$#", 78 | "+++++++O$ O$+ooooooo+++++O$ O$+ooO$ O$+ooo+O$ O$+o++ooooooO$ O$+" 79 | }; 80 | --------------------------------------------------------------------------------