├── textures ├── key_e.png ├── key_o.png ├── key_p.png ├── spike.png ├── subject.png ├── wanted.png ├── cardboard.png ├── dresser3 (1).png ├── dresser3 (2).png ├── dresser3 (3).png ├── full_heart_2.png ├── piano_midmid.png ├── piano_topmid.png ├── dialog_box_mid.png ├── murder_article.png ├── piano_downleft.png ├── piano_downmid.png ├── piano_midleft.png ├── piano_midright.png ├── piano_topright.png ├── preview_story.png ├── commode_sized_cut.png ├── dialog_box_left.png ├── dialog_box_right.png ├── dresser_downleft.png ├── dresser_downright.png ├── dresser_topleft.png ├── dresser_topright.png ├── piano_downright.png ├── preview_dialogbox.png ├── preview_key_event.png └── commode_sized_cut (1).png ├── map ├── valid_map.ber ├── piano.ber ├── valid_map2.ber └── furniture.ber ├── mlx ├── mlx_int_do_nothing.c ├── mlx_screen_size.c ├── mlx_loop_hook.c ├── Makefile ├── mlx_clear_window.c ├── mlx_flush_event.c ├── mlx_expose_hook.c ├── mlx_int_wait_first_expose.c ├── mlx_key_hook.c ├── mlx_mouse_hook.c ├── mlx_get_data_addr.c ├── test │ ├── new_win.c │ ├── Makefile.mk │ └── run_tests.sh ├── mlx_pixel_put.c ├── mlx_string_put.c ├── mlx_int_anti_resize_win.c ├── mlx_int_set_win_event_mask.c ├── mlx_hook.c ├── mlx_destroy_image.c ├── mlx_destroy_window.c ├── .gitignore ├── mlx_get_color_value.c ├── mlx_int_get_visual.c ├── rgb2c.pl ├── mlx_put_image_to_window.c ├── mlx_destroy_display.c ├── LICENSE ├── mlx_set_font.c ├── mlx_mouse.c ├── mlx_loop.c ├── man │ ├── man1 │ │ ├── mlx_new_window.1 │ │ ├── mlx_pixel_put.1 │ │ ├── mlx.1 │ │ └── mlx_loop.1 │ └── man3 │ │ ├── mlx_new_window.3 │ │ ├── mlx_pixel_put.3 │ │ └── mlx.3 ├── Makefile.mk ├── README.md ├── mlx_new_window.c ├── mlx_int_str_to_wordtab.c ├── mlx_lib_xpm.c ├── mlx_init.c ├── mlx_int_param_event.c ├── mlx_ext_randr.c ├── mlx_int.h └── configure ├── srcs ├── draw_2_lenght_wall.c ├── ft_putpixel.c ├── draw_collectibles.c ├── draw_trap.c ├── draw_dialogbox.c ├── write_event.c ├── exit.c ├── draw_map.c ├── handle_keypress.c ├── norme4.c ├── exec_moves.c ├── initialize.c ├── draw_on_images.c ├── exec_events.c ├── initialize_functionnalities.c ├── draw_exit.c ├── draw_furnitures2.c ├── draw_stats.c ├── handle_event.c ├── check_errors.c ├── draw_furnitures_cond.c ├── draw_furnitures.c ├── check_map_elem.c └── draw_player.c ├── libft ├── ft_putchar_fd.c ├── ft_isprint.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_tolower.c ├── ft_toupper.c ├── ft_lstdelone.c ├── ft_putendl_fd.c ├── ft_isalnum.c ├── ft_isalpha.c ├── ft_strlen.c ├── ft_lstiter.c ├── ft_lstadd_front.c ├── ft_lstsize.c ├── ft_lstlast.c ├── ft_strchr.c ├── ft_bzero.c ├── ft_putstr_fd.c ├── ft_lstnew.c ├── ft_calloc.c ├── ft_memset.c ├── ft_lstadd_back.c ├── ft_memchr.c ├── ft_memcpy.c ├── ft_lstclear.c ├── ft_strdup.c ├── ft_memmove.c ├── ft_putnbr_fd.c ├── ft_strrchr.c ├── ft_memcmp.c ├── ft_strlcat.c ├── ft_memccpy.c ├── ft_strlcpy.c ├── ft_strncmp.c ├── ft_strmapi.c ├── ft_lstmap.c ├── ft_strnstr.c ├── ft_strjoin.c ├── ft_itoa.c ├── ft_substr.c ├── ft_strtrim.c ├── ft_atoi.c ├── Makefile ├── ft_split.c └── libft.h ├── get_next_line ├── get_next_line.h ├── get_next_line_utils.c └── get_next_line.c ├── Makefile └── main.c /textures/key_e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/key_e.png -------------------------------------------------------------------------------- /textures/key_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/key_o.png -------------------------------------------------------------------------------- /textures/key_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/key_p.png -------------------------------------------------------------------------------- /textures/spike.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/spike.png -------------------------------------------------------------------------------- /textures/subject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/subject.png -------------------------------------------------------------------------------- /textures/wanted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/wanted.png -------------------------------------------------------------------------------- /textures/cardboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/cardboard.png -------------------------------------------------------------------------------- /textures/dresser3 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dresser3 (1).png -------------------------------------------------------------------------------- /textures/dresser3 (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dresser3 (2).png -------------------------------------------------------------------------------- /textures/dresser3 (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dresser3 (3).png -------------------------------------------------------------------------------- /textures/full_heart_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/full_heart_2.png -------------------------------------------------------------------------------- /textures/piano_midmid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_midmid.png -------------------------------------------------------------------------------- /textures/piano_topmid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_topmid.png -------------------------------------------------------------------------------- /map/valid_map.ber: -------------------------------------------------------------------------------- 1 | 1111111111111 2 | 1C01000000001 3 | 1000011111001 4 | 1P0011E000001 5 | 1111111111111 6 | -------------------------------------------------------------------------------- /textures/dialog_box_mid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dialog_box_mid.png -------------------------------------------------------------------------------- /textures/murder_article.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/murder_article.png -------------------------------------------------------------------------------- /textures/piano_downleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_downleft.png -------------------------------------------------------------------------------- /textures/piano_downmid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_downmid.png -------------------------------------------------------------------------------- /textures/piano_midleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_midleft.png -------------------------------------------------------------------------------- /textures/piano_midright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_midright.png -------------------------------------------------------------------------------- /textures/piano_topright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_topright.png -------------------------------------------------------------------------------- /textures/preview_story.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/preview_story.png -------------------------------------------------------------------------------- /textures/commode_sized_cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/commode_sized_cut.png -------------------------------------------------------------------------------- /textures/dialog_box_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dialog_box_left.png -------------------------------------------------------------------------------- /textures/dialog_box_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dialog_box_right.png -------------------------------------------------------------------------------- /textures/dresser_downleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dresser_downleft.png -------------------------------------------------------------------------------- /textures/dresser_downright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dresser_downright.png -------------------------------------------------------------------------------- /textures/dresser_topleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dresser_topleft.png -------------------------------------------------------------------------------- /textures/dresser_topright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/dresser_topright.png -------------------------------------------------------------------------------- /textures/piano_downright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/piano_downright.png -------------------------------------------------------------------------------- /textures/preview_dialogbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/preview_dialogbox.png -------------------------------------------------------------------------------- /textures/preview_key_event.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/preview_key_event.png -------------------------------------------------------------------------------- /map/piano.ber: -------------------------------------------------------------------------------- 1 | 111111111111 2 | 101110101101 3 | 1T00000000C1 4 | 10000000CC01 5 | 1P00000000E1 6 | 111111111111 7 | -------------------------------------------------------------------------------- /textures/commode_sized_cut (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethan0905/so_long/HEAD/textures/commode_sized_cut (1).png -------------------------------------------------------------------------------- /map/valid_map2.ber: -------------------------------------------------------------------------------- 1 | 111111111111111 2 | 1000001010101T1 3 | 1P0C00000000001 4 | 110000011110001 5 | 1E00000CCCC1111 6 | 111111111111111 7 | -------------------------------------------------------------------------------- /map/furniture.ber: -------------------------------------------------------------------------------- 1 | 111111111111111111111111 2 | 1101101110111101101110E1 3 | 100000000000000000000001 4 | 100100111001001100100CC1 5 | 1P0000000000000000000CC1 6 | 111111111111111111111111 7 | -------------------------------------------------------------------------------- /mlx/mlx_int_do_nothing.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_do_nothing.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Aug 8 12:58:24 2000 Charlie Root 8 | ** Last update Tue Sep 25 15:56:22 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | int mlx_int_do_nothing(void *param) 14 | { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /mlx/mlx_screen_size.c: -------------------------------------------------------------------------------- 1 | #include "mlx_int.h" 2 | 3 | int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey) 4 | { 5 | XWindowAttributes xwAttr; 6 | Status ret; 7 | t_xvar *xvar; 8 | 9 | xvar = mlx_ptr; 10 | ret = XGetWindowAttributes(xvar->display, xvar->root, &xwAttr); 11 | (*sizex) = xwAttr.width; 12 | (*sizey) = xwAttr.height; 13 | } 14 | -------------------------------------------------------------------------------- /mlx/mlx_loop_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_loop_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:11:39 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_loop_hook(t_xvar *xvar,int (*funct)(),void *param) 18 | { 19 | xvar->loop_hook = funct; 20 | xvar->loop_param = param; 21 | } 22 | -------------------------------------------------------------------------------- /mlx/Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx 3 | ## 4 | ## Made by Olivier Crouzet 5 | ## Login 6 | ## 7 | ## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet 8 | ## Last update Tue May 15 15:44:41 2007 Olivier Crouzet 9 | ## 10 | 11 | ## Please use configure script 12 | 13 | 14 | 15 | all : do_configure 16 | 17 | do_configure : 18 | ./configure 19 | 20 | clean : 21 | ./configure clean 22 | 23 | re : clean all 24 | -------------------------------------------------------------------------------- /mlx/mlx_clear_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_clear_window.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Sep 7 19:46:15 2000 Charlie Root 8 | ** Last update Tue Sep 25 17:11:19 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | int mlx_clear_window(t_xvar *xvar,t_win_list *win) 17 | { 18 | XClearWindow(xvar->display,win->window); 19 | if (xvar->do_flush) 20 | XFlush(xvar->display); 21 | } 22 | -------------------------------------------------------------------------------- /mlx/mlx_flush_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_flush_event.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Aug 2 18:58:11 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:08:48 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_flush_event(t_xvar *xvar) 18 | { 19 | XEvent ev; 20 | 21 | while (XPending(xvar->display)) 22 | { 23 | XNextEvent(xvar->display,&ev); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mlx/mlx_expose_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_expose_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:07:42 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_expose_hook(t_win_list *win,int (*funct)(),void *param) 18 | { 19 | win->hooks[Expose].hook = funct; 20 | win->hooks[Expose].param = param; 21 | win->hooks[Expose].mask = ExposureMask; 22 | } 23 | -------------------------------------------------------------------------------- /mlx/mlx_int_wait_first_expose.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_wait_first_expose.c for minilibx in 3 | ** 4 | ** Made by olivier crouzet 5 | ** Login 6 | ** 7 | ** Started on Tue Oct 17 09:26:45 2000 olivier crouzet 8 | ** Last update Fri Feb 23 17:27:10 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | 17 | int mlx_int_wait_first_expose(t_xvar *xvar,Window win) 18 | { 19 | XEvent ev; 20 | 21 | XWindowEvent(xvar->display,win,ExposureMask,&ev); 22 | XPutBackEvent(xvar->display,&ev); 23 | } 24 | -------------------------------------------------------------------------------- /mlx/mlx_key_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_key_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:10:09 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_key_hook(t_win_list *win,int (*funct)(),void *param) 18 | { 19 | win->hooks[KeyRelease].hook = funct; 20 | win->hooks[KeyRelease].param = param; 21 | win->hooks[KeyRelease].mask = KeyReleaseMask; 22 | } 23 | -------------------------------------------------------------------------------- /mlx/mlx_mouse_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_mouse_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:11:05 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_mouse_hook(t_win_list *win,int (*funct)(),void *param) 18 | { 19 | win->hooks[ButtonPress].hook = funct; 20 | win->hooks[ButtonPress].param = param; 21 | win->hooks[ButtonPress].mask = ButtonPressMask; 22 | } 23 | -------------------------------------------------------------------------------- /mlx/mlx_get_data_addr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_get_data_addr.c for MiniLibX in raytraceur 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Aug 14 15:45:57 2000 Charlie Root 8 | ** Last update Thu Sep 27 19:05:25 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | char *mlx_get_data_addr(t_img *img,int *bits_per_pixel, 17 | int *size_line,int *endian) 18 | { 19 | *bits_per_pixel = img->bpp; 20 | *size_line = img->size_line; 21 | *endian = img->image->byte_order; 22 | return (img->data); 23 | } 24 | -------------------------------------------------------------------------------- /mlx/test/new_win.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "mlx.h" 5 | 6 | 7 | void *mlx; 8 | void *win1; 9 | void *win2; 10 | 11 | 12 | 13 | int gere_mouse(int x,int y,int button,void*toto) 14 | { 15 | printf("Mouse event - new win\n"); 16 | mlx_destroy_window(mlx,win1); 17 | win1 = mlx_new_window(mlx,random()%500,random()%500,"new win"); 18 | mlx_mouse_hook(win1,gere_mouse,0); 19 | } 20 | 21 | 22 | int main() 23 | { 24 | srandom(time(0)); 25 | mlx = mlx_init(); 26 | win1 = mlx_new_window(mlx,300,300,"win1"); 27 | win2 = mlx_new_window(mlx,600,600,"win2"); 28 | mlx_mouse_hook(win1,gere_mouse,0); 29 | mlx_mouse_hook(win2,gere_mouse,0); 30 | mlx_loop(mlx); 31 | } 32 | -------------------------------------------------------------------------------- /mlx/mlx_pixel_put.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_pixel_put.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 19:01:33 2000 Charlie Root 8 | ** Last update Tue Sep 25 17:09:49 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | int mlx_pixel_put(t_xvar *xvar,t_win_list *win, 17 | int x,int y,int color) 18 | { 19 | XGCValues xgcv; 20 | 21 | xgcv.foreground = mlx_int_get_good_color(xvar,color); 22 | XChangeGC(xvar->display,win->gc,GCForeground,&xgcv); 23 | XDrawPoint(xvar->display,win->window,win->gc,x,y); 24 | if (xvar->do_flush) 25 | XFlush(xvar->display); 26 | } 27 | -------------------------------------------------------------------------------- /mlx/mlx_string_put.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_string_put.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 19:01:33 2000 Charlie Root 8 | ** Last update Tue Sep 25 17:11:47 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | int mlx_string_put(t_xvar *xvar,t_win_list *win, 17 | int x,int y,int color,char *string) 18 | { 19 | XGCValues xgcv; 20 | 21 | xgcv.foreground = mlx_int_get_good_color(xvar,color); 22 | XChangeGC(xvar->display,win->gc,GCForeground,&xgcv); 23 | XDrawString(xvar->display,win->window,win->gc,x,y,string,strlen(string)); 24 | if (xvar->do_flush) 25 | XFlush(xvar->display); 26 | } 27 | -------------------------------------------------------------------------------- /mlx/mlx_int_anti_resize_win.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_anti_resize_win.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Aug 8 14:31:05 2000 Charlie Root 8 | ** Last update Tue Sep 25 15:56:58 2001 Charlie Root 9 | */ 10 | 11 | #include "mlx_int.h" 12 | 13 | 14 | int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h) 15 | { 16 | XSizeHints hints; 17 | long toto; 18 | 19 | XGetWMNormalHints(xvar->display,win,&hints,&toto); 20 | hints.width = w; 21 | hints.height = h; 22 | hints.min_width = w; 23 | hints.min_height = h; 24 | hints.max_width = w; 25 | hints.max_height = h; 26 | hints.flags = PPosition | PSize | PMinSize | PMaxSize; 27 | XSetWMNormalHints(xvar->display,win,&hints); 28 | } 29 | -------------------------------------------------------------------------------- /mlx/mlx_int_set_win_event_mask.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_set_win_event_mask.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:07:42 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_int_set_win_event_mask(t_xvar *xvar) 18 | { 19 | t_win_list *win; 20 | int mask; 21 | int i; 22 | XSetWindowAttributes xwa; 23 | 24 | win = xvar->win_list; 25 | while (win) 26 | { 27 | xwa.event_mask = 0; 28 | i = MLX_MAX_EVENT; 29 | while (i--) 30 | xwa.event_mask |= win->hooks[i].mask; 31 | XChangeWindowAttributes(xvar->display, win->window, CWEventMask, &xwa); 32 | win = win->next; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mlx/mlx_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Jan 28 17:05:28 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_hook(t_win_list *win, int x_event, int x_mask, 18 | int (*funct)(),void *param) 19 | { 20 | win->hooks[x_event].hook = funct; 21 | win->hooks[x_event].param = param; 22 | win->hooks[x_event].mask = x_mask; 23 | } 24 | 25 | 26 | int mlx_do_key_autorepeatoff(t_xvar *xvar) 27 | { 28 | XAutoRepeatOff(xvar->display); 29 | } 30 | 31 | int mlx_do_key_autorepeaton(t_xvar *xvar) 32 | { 33 | XAutoRepeatOn(xvar->display); 34 | } 35 | 36 | 37 | int mlx_do_sync(t_xvar *xvar) 38 | { 39 | XSync(xvar->display, False); 40 | } 41 | -------------------------------------------------------------------------------- /mlx/mlx_destroy_image.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_destroy_image.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Mar 12 10:25:15 2002 Charlie Root 8 | ** Last update Tue May 15 16:45:54 2007 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_destroy_image(t_xvar *xvar, t_img *img) 16 | { 17 | if (img->type == MLX_TYPE_SHM_PIXMAP || 18 | img->type == MLX_TYPE_SHM) 19 | { 20 | XShmDetach(xvar->display, &(img->shm)); 21 | shmdt(img->shm.shmaddr); 22 | /* shmctl IPC_RMID already done */ 23 | } 24 | XDestroyImage(img->image); /* For image & shm-image. Also free img->data */ 25 | XFreePixmap(xvar->display, img->pix); 26 | if (img->gc) 27 | XFreeGC(xvar->display, img->gc); 28 | free(img); 29 | if (xvar->do_flush) 30 | XFlush(xvar->display); 31 | } 32 | -------------------------------------------------------------------------------- /mlx/mlx_destroy_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_destroy_window.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Mar 12 10:25:15 2002 Charlie Root 8 | ** Last update Tue May 15 16:46:08 2007 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_destroy_window(t_xvar *xvar,t_win_list *win) 16 | { 17 | t_win_list *w; 18 | t_win_list *prev; 19 | t_win_list first; 20 | 21 | first.next = xvar->win_list; 22 | prev = &first; 23 | w = prev->next; 24 | while (w) 25 | { 26 | if (w==win) 27 | prev->next = w->next; 28 | else 29 | prev = w; 30 | w = w->next; 31 | } 32 | xvar->win_list = first.next; 33 | XDestroyWindow(xvar->display,win->window); 34 | XFreeGC(xvar->display,win->gc); 35 | free(win); 36 | if (xvar->do_flush) 37 | XFlush(xvar->display); 38 | } 39 | -------------------------------------------------------------------------------- /mlx/.gitignore: -------------------------------------------------------------------------------- 1 | ## Mlx related 2 | Makefile.gen 3 | /test/mlx-test 4 | 5 | ## Editor 6 | .vscode/* 7 | *~ 8 | \#*\# 9 | 10 | ## Other 11 | .DS_STORE 12 | 13 | 14 | 15 | ## Template from https://github.com/github/gitignore 16 | # Prerequisites 17 | *.d 18 | 19 | # Object files 20 | *.o 21 | *.ko 22 | *.obj 23 | *.elf 24 | 25 | # Linker output 26 | *.ilk 27 | *.map 28 | *.exp 29 | 30 | # Precompiled Headers 31 | *.gch 32 | *.pch 33 | 34 | # Libraries 35 | *.lib 36 | *.a 37 | *.la 38 | *.lo 39 | 40 | # Shared objects (inc. Windows DLLs) 41 | *.dll 42 | *.so 43 | *.so.* 44 | *.dylib 45 | 46 | # Executables 47 | *.exe 48 | *.out 49 | *.app 50 | *.i*86 51 | *.x86_64 52 | *.hex 53 | 54 | # Debug files 55 | *.dSYM/ 56 | *.su 57 | *.idb 58 | *.pdb 59 | 60 | # Kernel Module Compile Results 61 | *.mod* 62 | *.cmd 63 | .tmp_versions/ 64 | modules.order 65 | Module.symvers 66 | Mkfile.old 67 | dkms.conf -------------------------------------------------------------------------------- /mlx/test/Makefile.mk: -------------------------------------------------------------------------------- 1 | 2 | INC=%%%% 3 | 4 | INCLIB=$(INC)/../lib 5 | 6 | UNAME := $(shell uname) 7 | 8 | CFLAGS= -I$(INC) -O3 -I.. -g 9 | 10 | NAME= mlx-test 11 | SRC = main.c 12 | OBJ = $(SRC:%.c=%.o) 13 | 14 | LFLAGS = -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm 15 | 16 | ifeq ($(UNAME), Darwin) 17 | # mac 18 | CC = clang 19 | else ifeq ($(UNAME), FreeBSD) 20 | # FreeBSD 21 | CC = clang 22 | else 23 | #Linux and others... 24 | CC = gcc 25 | LFLAGS += -lbsd 26 | endif 27 | 28 | all: $(NAME) 29 | 30 | $(NAME): $(OBJ) 31 | $(CC) -o $(NAME) $(OBJ) $(LFLAGS) 32 | 33 | show: 34 | @printf "UNAME : $(UNAME)\n" 35 | @printf "NAME : $(NAME)\n" 36 | @printf "CC : $(CC)\n" 37 | @printf "CFLAGS : $(CFLAGS)\n" 38 | @printf "LFLAGS : $(LFLAGS)\n" 39 | @printf "SRC :\n $(SRC)\n" 40 | @printf "OBJ :\n $(OBJ)\n" 41 | 42 | clean: 43 | rm -f $(NAME) $(OBJ) *~ core *.core 44 | 45 | re: clean all 46 | -------------------------------------------------------------------------------- /mlx/mlx_get_color_value.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_get_color_value.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 19:01:33 2000 Charlie Root 8 | ** Last update Thu Oct 4 15:04:13 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_get_color_value(t_xvar *xvar,int color) 16 | { 17 | return(mlx_int_get_good_color(xvar,color)); 18 | } 19 | 20 | int mlx_int_get_good_color(t_xvar *xvar,int color) 21 | { 22 | XColor xc; 23 | 24 | if (xvar->depth>=24) 25 | return (color); 26 | xc.red = (color>>8)&0xFF00; 27 | xc.green = color&0xFF00; 28 | xc.blue = (color<<8)&0xFF00; 29 | xc.pixel = ((xc.red>>(16-xvar->decrgb[1]))<decrgb[0])+ 30 | ((xc.green>>(16-xvar->decrgb[3]))<decrgb[2])+ 31 | ((xc.blue>>(16-xvar->decrgb[5]))<decrgb[4]); 32 | return (xc.pixel); 33 | } 34 | -------------------------------------------------------------------------------- /srcs/draw_2_lenght_wall.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_2_lenght_wall.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 20:04:27 by esafar #+# #+# */ 9 | /* Updated: 2021/12/07 20:04:37 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | -------------------------------------------------------------------------------- /mlx/mlx_int_get_visual.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_get_visual.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Oct 3 17:01:51 2001 Charlie Root 8 | ** Last update Thu Oct 4 15:00:45 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | /* 17 | ** We need a private colormap for non-default Visual. 18 | */ 19 | 20 | 21 | int mlx_int_get_visual(t_xvar *xvar) 22 | { 23 | XVisualInfo *vi; 24 | XVisualInfo template; 25 | int nb_item; 26 | 27 | xvar->private_cmap = 0; 28 | xvar->visual = DefaultVisual(xvar->display,xvar->screen); 29 | if (xvar->visual->class == TrueColor) 30 | return (0); 31 | template.class = TrueColor; 32 | template.depth = xvar->depth; 33 | if (!(vi = XGetVisualInfo(xvar->display,VisualDepthMask|VisualClassMask, 34 | &template,&nb_item)) ) 35 | return (-1); 36 | xvar->visual = vi->visual; 37 | xvar->private_cmap = 1; 38 | return (0); 39 | } 40 | -------------------------------------------------------------------------------- /mlx/rgb2c.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | ## rgb2c.pl for MiniLibX in /home/boulon/work/c/raytraceur/minilibx 4 | ## 5 | ## Made by Olivier Crouzet 6 | ## Login 7 | ## 8 | ## Started on Tue Oct 5 16:33:46 2004 Olivier Crouzet 9 | ## Last update Tue Oct 5 16:36:11 2004 Olivier Crouzet 10 | ## 11 | 12 | 13 | # 14 | # Generate a .c file with encoded colors, from the XFree86 rgb.txt file. 15 | # 16 | 17 | open(RGB, "/usr/X11/lib/X11/rgb.txt"); 18 | 19 | 20 | printf("/*\n** This is a generated file with rgb2c.pl and rgb.txt from\n"); 21 | printf("** the XFree86 distribution.\n*/\n\n"); 22 | printf("struct s_col_name mlx_col_name[] =\n{\n"); 23 | 24 | while () 25 | { 26 | @tab = split; 27 | if ($tab[0] ne "!") 28 | { 29 | $color = $tab[3]; 30 | if ("$tab[4]" ne "") 31 | { 32 | $color = "$tab[3] $tab[4]"; 33 | } 34 | printf(" { \"%s\" , 0x%x },\n", $color, $tab[0]*65536+$tab[1]*256+$tab[2]); 35 | } 36 | } 37 | 38 | printf(" { 0, 0 }\n};\n"); 39 | -------------------------------------------------------------------------------- /libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 11:01:24 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:33:24 by esafar ### ########.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 | -------------------------------------------------------------------------------- /mlx/mlx_put_image_to_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_put_image_to_window.c for MiniLibX in raytraceur 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Aug 14 15:55:49 2000 Charlie Root 8 | ** Last update Sun Oct 2 09:53:00 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | int mlx_put_image_to_window(t_xvar *xvar,t_win_list *win,t_img *img, 17 | int x,int y) 18 | { 19 | GC gc; 20 | 21 | gc = win->gc; 22 | if (img->gc) 23 | { 24 | gc = img->gc; 25 | XSetClipOrigin(xvar->display, gc, x, y); 26 | } 27 | if (img->type==MLX_TYPE_SHM) 28 | XShmPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0, 29 | img->width,img->height,False); 30 | if (img->type==MLX_TYPE_XIMAGE) 31 | XPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0, 32 | img->width,img->height); 33 | XCopyArea(xvar->display,img->pix,win->window, gc, 34 | 0,0,img->width,img->height,x,y); 35 | if (xvar->do_flush) 36 | XFlush(xvar->display); 37 | } 38 | -------------------------------------------------------------------------------- /mlx/mlx_destroy_display.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* mlx_destroy_display.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mg +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/03 18:56:35 by mg #+# #+# */ 9 | /* Updated: 2020/10/04 01:55:35 by mg ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "mlx_int.h" 14 | 15 | int mlx_destroy_display(t_xvar *xvar) 16 | { 17 | XCloseDisplay(xvar->display); 18 | } 19 | -------------------------------------------------------------------------------- /libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 13:07:11 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:28:51 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isprint(int c) 16 | { 17 | if (c > 31 && c < 127) 18 | return (1); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 14:40:04 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:28:20 by esafar ### ########.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 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 13:00:09 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:27:41 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isdigit(int c) 16 | { 17 | if (c >= 48 && c <= 57) 18 | return (1); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 14:39:30 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:29:46 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_tolower(int c) 16 | { 17 | if (c >= 65 && c <= 90) 18 | c = c + 32; 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 13:20:39 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:29:13 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (c >= 97 && c <= 122) 18 | c = c - 32; 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 14:32:51 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:35:36 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void*)) 16 | { 17 | (*del)(lst->content); 18 | free(lst); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 11:05:27 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:33:47 by esafar ### ########.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_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 13:02:41 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:28:01 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalnum(int c) 16 | { 17 | if (ft_isalpha(c) == 1 || ft_isdigit(c) == 1) 18 | return (1); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 12:38:32 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:27:17 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalpha(int c) 16 | { 17 | if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) 18 | return (1); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 12:12:57 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:26:47 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlen(char const *str) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | i++; 22 | return (i); 23 | } 24 | -------------------------------------------------------------------------------- /libft/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 16:09:58 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:35:53 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | while (lst) 18 | { 19 | (*f)(lst->content); 20 | lst = lst->next; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 08:42:58 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:35:11 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **alst, t_list *new) 16 | { 17 | if (alst && new) 18 | { 19 | new->next = *alst; 20 | *alst = new; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 08:23:31 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:34:45 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (lst) 21 | { 22 | lst = lst->next; 23 | i++; 24 | } 25 | return (i); 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 10:59:22 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:35:45 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | if (lst) 18 | { 19 | while (lst->next) 20 | { 21 | lst = lst->next; 22 | } 23 | } 24 | return (lst); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 14:44:58 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:30:04 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | while (*s != (char)c) 18 | { 19 | if (*s == '\0') 20 | return (NULL); 21 | s++; 22 | } 23 | return ((char *)s); 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 08:10:36 by esafar #+# #+# */ 9 | /* Updated: 2021/09/24 10:39:06 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | size_t i; 18 | char *tab; 19 | 20 | i = 0; 21 | tab = (char *)s; 22 | while (i < n) 23 | { 24 | tab[i] = '\0'; 25 | i++; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libft/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 11:20:54 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:33:35 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_putstr_fd(char *s, int fd) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | if (!s) 21 | return (-1); 22 | while (s[i] != '\0') 23 | { 24 | write(fd, &s[i], 1); 25 | i++; 26 | } 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 08:20:25 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:34:22 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstnew(void *content) 16 | { 17 | t_list *list; 18 | 19 | list = malloc(sizeof(t_list)); 20 | if (list) 21 | { 22 | list->content = content; 23 | list->next = NULL; 24 | } 25 | return (list); 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 15:02:18 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:24:42 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_calloc(size_t nmemb, size_t size) 16 | { 17 | char *tab; 18 | 19 | tab = (char *)malloc(nmemb * size); 20 | if (tab == NULL) 21 | return (NULL); 22 | ft_bzero((void *)tab, nmemb * size); 23 | return (tab); 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 15:25:50 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:20:10 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memset(void *s, int c, size_t n) 16 | { 17 | size_t i; 18 | char *tab; 19 | 20 | i = 0; 21 | tab = (char *)s; 22 | while (i < n) 23 | { 24 | tab[i] = (char)c; 25 | i++; 26 | } 27 | return ((void *)s); 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 11:13:50 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:35:24 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **alst, t_list *new) 16 | { 17 | t_list *end; 18 | 19 | if (alst) 20 | { 21 | if (*alst == NULL) 22 | *alst = new; 23 | else 24 | { 25 | end = ft_lstlast(*alst); 26 | end->next = new; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /libft/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 14:02:01 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:25:53 by esafar ### ########.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 | char *tab; 19 | 20 | i = 0; 21 | tab = (char *)s; 22 | while (i < n) 23 | { 24 | if (*tab == (char)c) 25 | return (tab); 26 | i++; 27 | tab++; 28 | } 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /get_next_line/get_next_line.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/06/06 09:05:29 by esafar #+# #+# */ 9 | /* Updated: 2021/12/13 16:38:48 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_H 14 | # define GET_NEXT_LINE_H 15 | 16 | # define BUFFER_SIZE 1 17 | # include 18 | # include 19 | # include "../libft/libft.h" 20 | 21 | int get_next_line(int fd, char **line, int key); 22 | 23 | int ft_isnewline(char *s); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /libft/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 08:44:26 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:21:51 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memcpy(void *dest, const void *src, size_t n) 16 | { 17 | size_t i; 18 | char *d2; 19 | 20 | i = 0; 21 | d2 = (char *)dest; 22 | if (dest == NULL && src == NULL) 23 | return (NULL); 24 | while (i++ < n) 25 | *d2++ = *(char *)src++; 26 | return (dest); 27 | } 28 | -------------------------------------------------------------------------------- /libft/ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/28 14:45:52 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:34:59 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void*)) 16 | { 17 | t_list *temp; 18 | t_list *current; 19 | 20 | current = *lst; 21 | if (lst) 22 | { 23 | while (current) 24 | { 25 | temp = current->next; 26 | ft_lstdelone(current, (*del)); 27 | current = temp; 28 | } 29 | *lst = NULL; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 10:41:11 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:25:04 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strdup(char *src) 16 | { 17 | size_t i; 18 | char *dest; 19 | 20 | i = 0; 21 | dest = (char *)malloc(sizeof(char) * (ft_strlen(src) + 1)); 22 | if (!dest) 23 | return (NULL); 24 | while (src[i] != '\0') 25 | { 26 | dest[i] = src[i]; 27 | i++; 28 | } 29 | dest[i] = '\0'; 30 | return (dest); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 10:30:32 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:23:05 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memmove(void *dest, const void *src, size_t n) 16 | { 17 | char *d2; 18 | char *s2; 19 | 20 | d2 = (char *)dest; 21 | s2 = (char *)src; 22 | if (src < dest) 23 | { 24 | while (n > 0) 25 | { 26 | n--; 27 | d2[n] = s2[n]; 28 | } 29 | } 30 | else if (src > dest) 31 | ft_memcpy(d2, s2, n); 32 | return (dest); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 11:28:32 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:34:11 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | long long int nb; 18 | 19 | nb = n; 20 | if (nb < 0) 21 | { 22 | ft_putchar_fd('-', fd); 23 | nb = nb * -1; 24 | } 25 | if (nb >= 0 && nb < 10) 26 | ft_putchar_fd((nb + '0'), fd); 27 | else 28 | { 29 | ft_putnbr_fd((nb / 10), fd); 30 | ft_putnbr_fd((nb % 10), fd); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 14:47:42 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:30:12 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | size_t i; 18 | char *res; 19 | char *str; 20 | 21 | i = 0; 22 | res = NULL; 23 | str = (char *)s; 24 | while (s[i] != '\0') 25 | { 26 | if (s[i] == (char)c) 27 | res = (char *)&s[i]; 28 | i++; 29 | } 30 | if (s[i] == (char)c) 31 | res = (char *)&s[i]; 32 | return (res); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 14:27:29 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:25:22 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | size_t i; 18 | unsigned char *t1; 19 | unsigned char *t2; 20 | 21 | i = 0; 22 | t1 = (unsigned char *)s1; 23 | t2 = (unsigned char *)s2; 24 | while (i < n) 25 | { 26 | if (t1[i] != t2[i]) 27 | return (t1[i] - t2[i]); 28 | else 29 | i++; 30 | } 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 08:32:11 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:30:51 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcat(char *dest, const char *src, size_t size) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | i = 0; 21 | j = 0; 22 | while (dest[i] != '\0' && i < size) 23 | i++; 24 | while (src[j] != '\0' && i + j + 1 < size) 25 | { 26 | dest[i + j] = src[j]; 27 | j++; 28 | } 29 | if (i < size) 30 | dest[i + j] = '\0'; 31 | return ((size_t)ft_strlen((char *)src) + i); 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 09:31:51 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:22:49 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void *ft_memccpy(void *dest, const void *src, int c, size_t n) 16 | { 17 | size_t i; 18 | char *d2; 19 | char *s2; 20 | 21 | i = 0; 22 | d2 = (char *)dest; 23 | s2 = (char *)src; 24 | while (i < n) 25 | { 26 | *d2 = *s2; 27 | if (*s2 == (char)c) 28 | { 29 | *d2 = *s2; 30 | return ((void *)dest + i + 1); 31 | } 32 | i++; 33 | d2++; 34 | s2++; 35 | } 36 | return (NULL); 37 | } 38 | -------------------------------------------------------------------------------- /libft/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 14:29:43 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:30:37 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | size_t ft_strlcpy(char *dest, const char *src, size_t size) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | if (!dest || !src) 21 | return (0); 22 | if (size > 0) 23 | { 24 | size = size - 1; 25 | while (src[i] != '\0' && size > 0) 26 | { 27 | dest[i] = src[i]; 28 | i++; 29 | size--; 30 | } 31 | dest[i] = '\0'; 32 | } 33 | while (src[i] != '\0') 34 | i++; 35 | return (i); 36 | } 37 | -------------------------------------------------------------------------------- /libft/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/20 15:03:22 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:30:22 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | unsigned char *t1; 19 | unsigned char *t2; 20 | 21 | i = 0; 22 | t1 = (unsigned char *)s1; 23 | t2 = (unsigned char *)s2; 24 | while (n > 0 && (t1[i] != '\0' || t2[i] != '\0')) 25 | { 26 | if (t1[i] != t2[i]) 27 | return (t1[i] - t2[i]); 28 | else 29 | i++; 30 | n--; 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /srcs/ft_putpixel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putpixel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/23 18:26:03 by esafar #+# #+# */ 9 | /* Updated: 2021/11/23 18:26:17 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | int get_pixel(t_data *img, int x, int y) 16 | { 17 | return (*(int *)(img->addr + (y * img->line_length 18 | + (x * (img->bits_per_pixel / 8))))); 19 | } 20 | 21 | void my_mlx_pixel_put(t_test *test, int x, int y, int color) 22 | { 23 | char *dest; 24 | 25 | dest = test->data.addr + (y * test->data.line_length + x 26 | * (test->data.bits_per_pixel / 8)); 27 | *(unsigned int *)dest = color; 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/25 08:52:51 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:33:11 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | int i; 18 | char *tableau; 19 | 20 | i = 0; 21 | if (!s) 22 | return (NULL); 23 | tableau = (char *)malloc(sizeof(char) * (ft_strlen((char *)s) + 1)); 24 | if (!tableau) 25 | return (NULL); 26 | while (s[i] != '\0') 27 | { 28 | tableau[i] = (f)(i, s[i]); 29 | i++; 30 | } 31 | tableau[i] = '\0'; 32 | return (tableau); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/31 08:55:01 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:36:02 by esafar ### ########.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 *alst; 18 | t_list *new; 19 | 20 | if (!lst || !f) 21 | return (NULL); 22 | alst = NULL; 23 | while (lst) 24 | { 25 | new = ft_lstnew(f(lst->content)); 26 | if (new == NULL) 27 | { 28 | ft_lstclear(&alst, del); 29 | return (NULL); 30 | } 31 | ft_lstadd_back(&alst, new); 32 | lst = lst->next; 33 | } 34 | return (alst); 35 | } 36 | -------------------------------------------------------------------------------- /mlx/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2021, Ecole 42 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /libft/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 08:11:50 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:30:59 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *str, const char *to_find, size_t n) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | i = 0; 21 | j = 0; 22 | if (!ft_strlen((char *)to_find) || str == to_find) 23 | return ((char *)str); 24 | while (str[i] && i + j <= n) 25 | { 26 | if (to_find[j] == '\0') 27 | return ((char *)&str[i]); 28 | if (str[i + j] == to_find[j]) 29 | j++; 30 | else 31 | { 32 | j = 0; 33 | i++; 34 | } 35 | } 36 | return (NULL); 37 | } 38 | -------------------------------------------------------------------------------- /mlx/mlx_set_font.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* mlx_set_font.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: amalliar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/09/30 13:30:47 by amalliar #+# #+# */ 9 | /* Updated: 2020/09/30 17:08:36 by amalliar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "mlx_int.h" 14 | 15 | /* 16 | ** Allows to specify the font that will be used by mlx_string_put. 17 | ** 18 | ** Note: only fixed-width bitmap fonts are supported by Xlib, refer to xfontsel 19 | ** utility to get valid font names for this function. 20 | */ 21 | 22 | void mlx_set_font(t_xvar *xvar, t_win_list *win, char *name) 23 | { 24 | static Font font = 0; 25 | 26 | if (font) 27 | XUnloadFont(xvar->display, font); 28 | font = XLoadFont(xvar->display, name); 29 | XSetFont(xvar->display, win->gc, font); 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 11:57:12 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:32:07 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strjoin(char *s1, char *s2) 16 | { 17 | int i; 18 | int j; 19 | char *dest; 20 | 21 | i = 0; 22 | j = 0; 23 | if (!s1 || !s2) 24 | return (NULL); 25 | dest = (char *)malloc(sizeof(char) 26 | * ft_strlen((char *)s1) + sizeof(char) * ft_strlen((char *)s2) + 1); 27 | if (!dest) 28 | return (NULL); 29 | while (s1[i] != '\0') 30 | { 31 | dest[i] = s1[i]; 32 | i++; 33 | } 34 | while (s2[j] != '\0') 35 | { 36 | dest[i + j] = s2[j]; 37 | j++; 38 | } 39 | dest[i + j] = '\0'; 40 | free(s1); 41 | return (dest); 42 | } 43 | -------------------------------------------------------------------------------- /mlx/mlx_mouse.c: -------------------------------------------------------------------------------- 1 | #include "mlx_int.h" 2 | 3 | int mlx_mouse_move(t_xvar *xvar, t_win_list *win, int x, int y) 4 | { 5 | XWarpPointer(xvar->display, None, win->window, 0, 0, 0, 0, x, y); 6 | return (0); 7 | } 8 | 9 | int mlx_mouse_hide(t_xvar *xvar, t_win_list *win) 10 | { 11 | static char data[1] = {0}; 12 | Cursor cursor; 13 | Pixmap blank; 14 | XColor dummy; 15 | 16 | blank = XCreateBitmapFromData(xvar->display, win->window, data, 1, 1); 17 | cursor = XCreatePixmapCursor(xvar->display, blank, blank, &dummy, &dummy, 0, 0); 18 | XDefineCursor(xvar->display, win->window, cursor); 19 | XFreePixmap(xvar->display, blank); 20 | XFreeCursor(xvar->display, cursor); 21 | } 22 | 23 | int mlx_mouse_show(t_xvar *xvar, t_win_list *win) 24 | { 25 | XUndefineCursor(xvar->display, win->window); 26 | } 27 | 28 | /* 29 | ** Queries the position of the mouse pointer relative to the origin of the 30 | ** specified window and saves it to the provided location. 31 | ** 32 | ** If the pointer is not on the same screen as the specified window, both 33 | ** win_x_return and win_y_return are set to zero and the function returns 0. 34 | */ 35 | 36 | int mlx_mouse_get_pos(t_xvar *xvar, t_win_list *win, \ 37 | int *win_x_return, int *win_y_return) 38 | { 39 | Window root_return; 40 | Window child_return; 41 | int root_x_return; 42 | int root_y_return; 43 | unsigned mask_return; 44 | 45 | return (XQueryPointer(xvar->display, win->window, \ 46 | &root_return, &child_return, &root_x_return, &root_y_return, \ 47 | win_x_return, win_y_return, &mask_return)); 48 | } 49 | -------------------------------------------------------------------------------- /mlx/mlx_loop.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_loop.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Aug 2 18:58:11 2000 Charlie Root 8 | ** Last update Fri Sep 30 14:47:41 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | extern int (*(mlx_int_param_event[]))(); 15 | 16 | static int win_count(t_xvar *xvar) 17 | { 18 | int i; 19 | t_win_list *win; 20 | 21 | i = 0; 22 | win = xvar->win_list; 23 | while (win) 24 | { 25 | win = win->next; 26 | ++i; 27 | } 28 | return (i); 29 | } 30 | 31 | int mlx_loop_end(t_xvar *xvar) 32 | { 33 | xvar->end_loop = 1; 34 | return (1); 35 | } 36 | 37 | int mlx_loop(t_xvar *xvar) 38 | { 39 | XEvent ev; 40 | t_win_list *win; 41 | 42 | mlx_int_set_win_event_mask(xvar); 43 | xvar->do_flush = 0; 44 | while (win_count(xvar) && !xvar->end_loop) 45 | { 46 | while (!xvar->end_loop && (!xvar->loop_hook || XPending(xvar->display))) 47 | { 48 | XNextEvent(xvar->display,&ev); 49 | win = xvar->win_list; 50 | while (win && (win->window!=ev.xany.window)) 51 | win = win->next; 52 | 53 | if (win && ev.type == ClientMessage && ev.xclient.message_type == xvar->wm_protocols && ev.xclient.data.l[0] == xvar->wm_delete_window && win->hooks[DestroyNotify].hook) 54 | win->hooks[DestroyNotify].hook(win->hooks[DestroyNotify].param); 55 | if (win && ev.type < MLX_MAX_EVENT && win->hooks[ev.type].hook) 56 | mlx_int_param_event[ev.type](xvar, &ev, win); 57 | } 58 | XSync(xvar->display, False); 59 | if (xvar->loop_hook) 60 | xvar->loop_hook(xvar->loop_param); 61 | } 62 | return (0); 63 | } 64 | -------------------------------------------------------------------------------- /libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/24 14:17:53 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:32:53 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int ft_intlen(int n) 16 | { 17 | int size; 18 | 19 | size = 0; 20 | if (n <= 0) 21 | size = 1; 22 | while (n != 0) 23 | { 24 | n = n / 10; 25 | size++; 26 | } 27 | return (size); 28 | } 29 | 30 | char *ft_itoa(int n) 31 | { 32 | int buffer_size; 33 | char *dest; 34 | long nbis; 35 | 36 | nbis = n; 37 | buffer_size = ft_intlen(n); 38 | dest = (char *)malloc(sizeof(char) * (buffer_size + 1)); 39 | if (!dest) 40 | return (NULL); 41 | if (nbis < 0) 42 | nbis = -nbis; 43 | dest[buffer_size--] = '\0'; 44 | while (buffer_size >= 0) 45 | { 46 | dest[buffer_size] = nbis % 10 + '0'; 47 | nbis = nbis / 10; 48 | buffer_size--; 49 | } 50 | if (n < 0) 51 | dest[0] = '-'; 52 | return (dest); 53 | } 54 | -------------------------------------------------------------------------------- /libft/ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 12:38:25 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:36:38 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static char *subsub(char const *s, unsigned int start, size_t len, size_t i) 16 | { 17 | char *str; 18 | 19 | if (ft_strlen(s) < start) 20 | { 21 | str = (char *)malloc(sizeof(char)); 22 | if (str == NULL) 23 | return (NULL); 24 | str[0] = '\0'; 25 | } 26 | else 27 | { 28 | if (start + len > ft_strlen(s)) 29 | len = ft_strlen(s) - start; 30 | str = (char *)malloc(sizeof(char) * (len + 1)); 31 | if (!str) 32 | return (NULL); 33 | i = 0; 34 | while (++i - 1 < len) 35 | str[i - 1] = s[start + i - 1]; 36 | str[i - 1] = '\0'; 37 | } 38 | return (str); 39 | } 40 | 41 | char *ft_substr(char const *s, unsigned int start, size_t len) 42 | { 43 | size_t i; 44 | 45 | i = 0; 46 | if (!s) 47 | return (NULL); 48 | return (subsub(s, start, len, i)); 49 | } 50 | -------------------------------------------------------------------------------- /libft/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/23 12:18:11 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:32:31 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int ft_is_char_from_set(const char *set, char c) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (set[i]) 21 | { 22 | if (set[i] == c) 23 | return (1); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | 29 | char *ft_strtrim(char const *s1, char const *set) 30 | { 31 | size_t i; 32 | size_t start; 33 | size_t end; 34 | char *lajoconde; 35 | 36 | start = 0; 37 | if (!s1 || !set) 38 | return (NULL); 39 | while (s1[start] && ft_is_char_from_set(set, s1[start])) 40 | start++; 41 | end = ft_strlen((char *)s1); 42 | while (start < end && ft_is_char_from_set(set, s1[end - 1])) 43 | end--; 44 | lajoconde = (char *)malloc(sizeof(char) * (end - start + 1)); 45 | if (!lajoconde) 46 | return (NULL); 47 | i = 0; 48 | while (start < end) 49 | lajoconde[i++] = s1[start++]; 50 | lajoconde[i] = '\0'; 51 | return (lajoconde); 52 | } 53 | -------------------------------------------------------------------------------- /srcs/draw_collectibles.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_collectibles.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 18:31:50 by esafar #+# #+# */ 9 | /* Updated: 2021/12/07 18:32:03 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void check_which_collectible(t_test *test, int i, int x, int y) 16 | { 17 | if (i % 2 == 0) 18 | draw_on_image(test, &test->collec.newspaper, x, y); 19 | else if (i % 2 == 1) 20 | draw_on_image(test, &test->collec.murder_article, x, y); 21 | } 22 | 23 | void draw_collectibles(t_test *test) 24 | { 25 | int i; 26 | int j; 27 | int x; 28 | int y; 29 | 30 | i = 1; 31 | while (test->param.map[i + 1]) 32 | { 33 | j = 1; 34 | while (test->param.map[i][j + 1]) 35 | { 36 | x = (64 + (test->param.height - 2 - i) * 64 + (j - 1) * 64); 37 | y = (192 + (i - 1) * 64); 38 | if (test->param.map[i][j] == 'C' && j % 2 == 0) 39 | check_which_collectible(test, i, x, y); 40 | else if (test->param.map[i][j] == 'C' && j % 2 == 1) 41 | draw_on_image(test, &test->collec.wanted, x, y); 42 | j++; 43 | } 44 | i++; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /mlx/man/man1/mlx_new_window.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Managing windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I void * 8 | .fi 9 | .B mlx_new_window 10 | ( 11 | .I void *mlx_ptr, int size_x, int size_y, char *title 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_clear_window 18 | ( 19 | .I void *mlx_ptr, void *win_ptr 20 | ); 21 | 22 | .nf 23 | .I int 24 | .fi 25 | .B mlx_destroy_window 26 | ( 27 | .I void *mlx_ptr, void *win_ptr 28 | ); 29 | 30 | 31 | .SH DESCRIPTION 32 | The 33 | .B mlx_new_window 34 | () function creates a new window on the screen, using the 35 | .I size_x 36 | and 37 | .I size_y 38 | parameters to determine its size, and 39 | .I title 40 | as the text that should be displayed in the window's title bar. 41 | The 42 | .I mlx_ptr 43 | parameter is the connection identifier returned by 44 | .B mlx_init 45 | () (see the 46 | .B mlx 47 | man page). 48 | .B mlx_new_window 49 | () returns a 50 | .I void * 51 | window identifier that can be used by other MiniLibX calls. 52 | Note that the MiniLibX 53 | can handle an arbitrary number of separate windows. 54 | 55 | .B mlx_clear_window 56 | () and 57 | .B mlx_destroy_window 58 | () respectively clear (in black) and destroy the given window. They both have 59 | the same parameters: 60 | .I mlx_ptr 61 | is the screen connection identifier, and 62 | .I win_ptr 63 | is a window identifier. 64 | 65 | .SH RETURN VALUES 66 | If 67 | .B mlx_new_window() 68 | fails to create a new window (for wathever reason), it will return NULL, 69 | otherwise a non-null pointer is returned as a window identifier. 70 | .B mlx_clear_window 71 | and 72 | .B mlx_destroy_window 73 | right now return nothing. 74 | 75 | .SH SEE ALSO 76 | mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 77 | 78 | .SH AUTHOR 79 | Copyright ol@ - 2002-2014 - Olivier Crouzet 80 | -------------------------------------------------------------------------------- /mlx/man/man3/mlx_new_window.3: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Managing windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I void * 8 | .fi 9 | .B mlx_new_window 10 | ( 11 | .I void *mlx_ptr, int size_x, int size_y, char *title 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_clear_window 18 | ( 19 | .I void *mlx_ptr, void *win_ptr 20 | ); 21 | 22 | .nf 23 | .I int 24 | .fi 25 | .B mlx_destroy_window 26 | ( 27 | .I void *mlx_ptr, void *win_ptr 28 | ); 29 | 30 | 31 | .SH DESCRIPTION 32 | The 33 | .B mlx_new_window 34 | () function creates a new window on the screen, using the 35 | .I size_x 36 | and 37 | .I size_y 38 | parameters to determine its size, and 39 | .I title 40 | as the text that should be displayed in the window's title bar. 41 | The 42 | .I mlx_ptr 43 | parameter is the connection identifier returned by 44 | .B mlx_init 45 | () (see the 46 | .B mlx 47 | man page). 48 | .B mlx_new_window 49 | () returns a 50 | .I void * 51 | window identifier that can be used by other MiniLibX calls. 52 | Note that the MiniLibX 53 | can handle an arbitrary number of separate windows. 54 | 55 | .B mlx_clear_window 56 | () and 57 | .B mlx_destroy_window 58 | () respectively clear (in black) and destroy the given window. They both have 59 | the same parameters: 60 | .I mlx_ptr 61 | is the screen connection identifier, and 62 | .I win_ptr 63 | is a window identifier. 64 | 65 | .SH RETURN VALUES 66 | If 67 | .B mlx_new_window() 68 | fails to create a new window (for wathever reason), it will return NULL, 69 | otherwise a non-null pointer is returned as a window identifier. 70 | .B mlx_clear_window 71 | and 72 | .B mlx_destroy_window 73 | right now return nothing. 74 | 75 | .SH SEE ALSO 76 | mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 77 | 78 | .SH AUTHOR 79 | Copyright ol@ - 2002-2014 - Olivier Crouzet 80 | -------------------------------------------------------------------------------- /srcs/draw_trap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_trap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 20:41:38 by esafar #+# #+# */ 9 | /* Updated: 2021/12/07 20:41:47 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void draw_spike(t_test *test) 16 | { 17 | draw_on_image(test, &test->all.spike, test->iter.x 18 | + 16, test->iter.y - 32 - 8); 19 | draw_on_image(test, &test->all.spike, test->iter.x + 8, test->iter.y - 32); 20 | draw_on_image(test, &test->all.spike, test->iter.x, test->iter.y - 16 - 8); 21 | draw_on_image(test, &test->all.spike, test->iter.x - 8, test->iter.y - 16); 22 | } 23 | 24 | void draw_trap(t_test *test) 25 | { 26 | test->iter.i = 1; 27 | while (test->param.map[test->iter.i + 1]) 28 | { 29 | test->iter.j = 1; 30 | while (test->param.map[test->iter.i][test->iter.j + 1]) 31 | { 32 | test->iter.x = (64 + (test->param.height - 2 33 | - test->iter.i) * 64 + (test->iter.j - 1) * 64); 34 | test->iter.y = (192 + (test->iter.i - 1) * 64); 35 | if (test->param.map[test->iter.i][test->iter.j] == 'T') 36 | draw_spike(test); 37 | test->iter.j++; 38 | } 39 | test->iter.i++; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mlx/Makefile.mk: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx 3 | ## 4 | ## Made by Olivier Crouzet 5 | ## Login 6 | ## 7 | ## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet 8 | ## Last update Tue May 15 15:41:20 2007 Olivier Crouzet 9 | ## 10 | 11 | ## Please use configure script 12 | 13 | 14 | INC =%%%% 15 | 16 | UNAME = $(shell uname) 17 | CC = gcc 18 | ifeq ($(UNAME),FreeBSD) 19 | CC = clang 20 | endif 21 | 22 | NAME = libmlx.a 23 | NAME_UNAME = libmlx_$(UNAME).a 24 | 25 | SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \ 26 | mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \ 27 | mlx_int_anti_resize_win.c mlx_int_do_nothing.c \ 28 | mlx_int_wait_first_expose.c mlx_int_get_visual.c \ 29 | mlx_flush_event.c mlx_string_put.c mlx_set_font.c \ 30 | mlx_new_image.c mlx_get_data_addr.c \ 31 | mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \ 32 | mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \ 33 | mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \ 34 | mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \ 35 | mlx_destroy_display.c 36 | 37 | OBJ_DIR = obj 38 | OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o)) 39 | CFLAGS = -O3 -I$(INC) 40 | 41 | all : $(NAME) 42 | 43 | $(OBJ_DIR)/%.o: %.c 44 | @mkdir -p $(OBJ_DIR) 45 | $(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@ 46 | 47 | $(NAME) : $(OBJ) 48 | ar -r $(NAME) $(OBJ) 49 | ranlib $(NAME) 50 | cp $(NAME) $(NAME_UNAME) 51 | 52 | check: all 53 | @test/run_tests.sh 54 | 55 | show: 56 | @printf "NAME : $(NAME)\n" 57 | @printf "NAME_UNAME : $(NAME_UNAME)\n" 58 | @printf "CC : $(CC)\n" 59 | @printf "CFLAGS : $(CFLAGS)\n" 60 | @printf "SRC :\n $(SRC)\n" 61 | @printf "OBJ :\n $(OBJ)\n" 62 | 63 | clean : 64 | rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core 65 | 66 | .PHONY: all check show clean 67 | -------------------------------------------------------------------------------- /libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 10:53:24 by esafar #+# #+# */ 9 | /* Updated: 2021/12/13 13:52:36 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int ft_isspace(char c) 16 | { 17 | if (c == ' ' || c == '\t' || c == '\v' || \ 18 | c == '\n' || c == '\f' || c == '\r') 19 | return (1); 20 | return (0); 21 | } 22 | 23 | static int ft_isnumber(char c) 24 | { 25 | if (c >= '0' && c <= '9') 26 | return (1); 27 | return (0); 28 | } 29 | 30 | static int ft_issymbol(char c) 31 | { 32 | if (c == '+' || c == '-') 33 | return (1); 34 | return (0); 35 | } 36 | 37 | int ft_atoi(const char *str) 38 | { 39 | int i; 40 | int sign; 41 | unsigned int res; 42 | 43 | i = 0; 44 | sign = 1; 45 | res = 0; 46 | while (ft_isspace(str[i])) 47 | i++; 48 | if (ft_issymbol(str[i])) 49 | { 50 | if (str[i] == '-') 51 | sign *= -1; 52 | i++; 53 | } 54 | while (ft_isnumber(str[i])) 55 | { 56 | res = res * 10 + (unsigned int)(str[i] - '0'); 57 | if (res > 2147483648 && sign < 0) 58 | return (0); 59 | else if (res > 2147483647 && sign > 0) 60 | return (-1); 61 | i++; 62 | } 63 | return ((unsigned)sign * res); 64 | } 65 | -------------------------------------------------------------------------------- /mlx/README.md: -------------------------------------------------------------------------------- 1 | [![Build](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml/badge.svg)](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml) 2 | 3 | This is the MinilibX, a simple X-Window (X11R6) programming API 4 | in C, designed for students, suitable for X-beginners. 5 | 6 | 7 | Contents 8 | 9 | - source code in C to create the mlx library 10 | - man pages (in man/ directory) 11 | - a test program (in test/ directory) is built 12 | with the library 13 | - a public include file mlx.h 14 | - a tiny configure script to generate an appropriate Makefile.gen 15 | 16 | Requirements for Linux 17 | 18 | - MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth) 19 | - gcc 20 | - make 21 | - X11 include files (package xorg) 22 | - XShm extension must be present (package libxext-dev) 23 | - Utility functions from BSD systems - development files (package libbsd-dev) 24 | - **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)** 25 | 26 | Requirements for MacOS 27 | - [Xquartz](https://www.xquartz.org/) 28 | 29 | ```bash 30 | ➜ ~ Brew install Xquartz 31 | ➜ ~ reboot 32 | ➜ ~ xeyes # run an hello world X11 app 33 | ``` 34 | 35 | MlX Color Opacity / Transparency / Alpha (32 bits depth) 36 | - 0xFF (fully transparent) or 0x00 (fully opaque) 37 | 38 | Compile MinilibX 39 | 40 | - run ./configure or make 41 | both will make a few tests, create Makefile.gen 42 | and then automatically run make on this generated Makefile.gen . 43 | libmlx.a and libmlx_$(HOSTTYPE).a are created. 44 | test/mlx-test binary is also created. 45 | 46 | 47 | Install MinilibX 48 | 49 | - no installation script is provided. You may want to install 50 | - libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib 51 | - mlx.h in /usr/X11/include or /usr/local/include 52 | - man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3 53 | 54 | 55 | Olivier CROUZET - 2014-01-06 - 56 | -------------------------------------------------------------------------------- /srcs/draw_dialogbox.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_dialogbox.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 19:35:07 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:50:39 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void print_box(t_test *test) 16 | { 17 | draw_on_image(test, &test->dialog_box.left, (test->param.width 18 | / 2 - 2) * 64, (test->param.height) * 64); 19 | draw_on_image(test, &test->dialog_box.mid, (test->param.width 20 | / 2 - 1) * 64, (test->param.height) * 64); 21 | draw_on_image(test, &test->dialog_box.mid, (test->param.width 22 | / 2) * 64, (test->param.height) * 64); 23 | draw_on_image(test, &test->dialog_box.mid, (test->param.width 24 | / 2 + 1) * 64, (test->param.height) * 64); 25 | draw_on_image(test, &test->dialog_box.right, (test->param.width 26 | / 2 + 2) * 64, (test->param.height) * 64); 27 | } 28 | 29 | void draw_dialog_box(t_test *test) 30 | { 31 | print_box(test); 32 | if (test->dialog_box.event == 1) 33 | { 34 | write_piano_event(test); 35 | test->player.lock_pos = 1; 36 | } 37 | else if (test->dialog_box.event == 2) 38 | { 39 | write_new_item_event(test); 40 | test->player.lock_pos = 1; 41 | } 42 | else if (test->dialog_box.event == 3) 43 | { 44 | write_newspaper_event(test); 45 | test->player.lock_pos = 1; 46 | } 47 | write_press_c_event(test); 48 | } 49 | -------------------------------------------------------------------------------- /mlx/mlx_new_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_new_window.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 17:29:02 2000 Charlie Root 8 | ** Last update Thu Oct 4 15:44:43 2001 Charlie Root 9 | */ 10 | 11 | 12 | /* 13 | ** We do not use White/BlackPixel macro, TrueColor Visual make sure 14 | ** 0 is black & -1 is white 15 | ** 16 | ** With mlx_int_wait_first_expose, no flush is needed. 17 | */ 18 | 19 | #include "mlx_int.h" 20 | 21 | 22 | void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title) 23 | { 24 | t_win_list *new_win; 25 | XSetWindowAttributes xswa; 26 | XGCValues xgcv; 27 | 28 | xswa.background_pixel = 0; 29 | xswa.border_pixel = -1; 30 | xswa.colormap = xvar->cmap; 31 | /* 32 | xswa.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask | 33 | KeyPressMask | KeyReleaseMask | StructureNotifyMask; 34 | */ 35 | /* xswa.event_mask = ExposureMask; */ 36 | xswa.event_mask = 0xFFFFFF; /* all events */ 37 | if (!(new_win = malloc(sizeof(*new_win)))) 38 | return ((void *)0); 39 | new_win->window = XCreateWindow(xvar->display,xvar->root,0,0,size_x,size_y, 40 | 0,CopyFromParent,InputOutput,xvar->visual, 41 | CWEventMask|CWBackPixel|CWBorderPixel| 42 | CWColormap,&xswa); 43 | mlx_int_anti_resize_win(xvar,new_win->window,size_x,size_y); 44 | XStoreName(xvar->display,new_win->window,title); 45 | XSetWMProtocols(xvar->display, new_win->window, &(xvar->wm_delete_window), 1); 46 | xgcv.foreground = -1; 47 | xgcv.function = GXcopy; 48 | xgcv.plane_mask = AllPlanes; 49 | new_win->gc = XCreateGC(xvar->display,new_win->window, 50 | GCFunction|GCPlaneMask|GCForeground,&xgcv); 51 | new_win->next = xvar->win_list; 52 | xvar->win_list = new_win; 53 | /* 54 | new_win->mouse_hook = mlx_int_do_nothing; 55 | new_win->key_hook = mlx_int_do_nothing; 56 | new_win->expose_hook = mlx_int_do_nothing; 57 | */ 58 | bzero(&(new_win->hooks), sizeof(new_win->hooks)); 59 | XMapRaised(xvar->display,new_win->window); 60 | mlx_int_wait_first_expose(xvar,new_win->window); 61 | return (new_win); 62 | } 63 | -------------------------------------------------------------------------------- /srcs/write_event.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* write_event.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/08 17:19:23 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:57:26 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void write_piano_event(t_test *test) 16 | { 17 | mlx_string_put(test->mlx, test->win, (test->param.width / 2 - 2) * 64 + 4, (test->param.height) * 64 + 16, 0xf4fefe, "Hmm strange... This piano seems to be perfectly"); 18 | mlx_string_put(test->mlx, test->win, (test->param.width / 2 - 2) * 64 + 4, (test->param.height) * 64 + 32, 0xf4fefe, "working..."); 19 | } 20 | 21 | void write_newspaper_event(t_test *test) 22 | { 23 | mlx_string_put(test->mlx, test->win, (test->param.width / 2 - 2) * 64 + 4, (test->param.height) * 64 + 16, 0xf4fefe, "I should take all the newspaper reports with me"); 24 | mlx_string_put(test->mlx, test->win, (test->param.width / 2 - 2) * 64 + 4, (test->param.height) * 64 + 32, 0xf4fefe, "before I go further.."); 25 | } 26 | 27 | void write_new_item_event(t_test *test) 28 | { 29 | mlx_string_put(test->mlx, test->win, (test->param.width / 2 - 2) * 64 + 4, (test->param.height) * 64 + 16, 0xf4fefe, "You have 1 new item in your inventory!"); 30 | } 31 | 32 | void write_press_c_event(t_test *test) 33 | { 34 | mlx_string_put(test->mlx, test->win, (test->param.width / 2 + 1) * 64 + 8, (test->param.height) * 64 + 32 + 16 + 5, 0xf4fefe, "Press C to continue"); 35 | } 36 | -------------------------------------------------------------------------------- /mlx/man/man3/mlx_pixel_put.3: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Drawing inside windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I int 8 | .fi 9 | .B mlx_pixel_put 10 | ( 11 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_string_put 18 | ( 19 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string 20 | ); 21 | 22 | 23 | .SH DESCRIPTION 24 | The 25 | .B mlx_pixel_put 26 | () function draws a defined pixel in the window 27 | .I win_ptr 28 | using the ( 29 | .I x 30 | , 31 | .I y 32 | ) coordinates, and the specified 33 | .I color 34 | \&. The origin (0,0) is the upper left corner of the window, the x and y axis 35 | respectively pointing right and down. The connection 36 | identifier, 37 | .I mlx_ptr 38 | , is needed (see the 39 | .B mlx 40 | man page). 41 | 42 | Parameters for 43 | .B mlx_string_put 44 | () have the same meaning. Instead of a simple pixel, the specified 45 | .I string 46 | will be displayed at ( 47 | .I x 48 | , 49 | .I y 50 | ). 51 | 52 | In both functions, it is impossible to display anything outside the 53 | specified window, nor display in another window in front of the selected one. 54 | 55 | .SH COLOR MANAGEMENT 56 | The 57 | .I color 58 | parameter has an integer type. The displayed color needs to be encoded 59 | in this integer, following a defined scheme. All displayable colors 60 | can be split in 3 basic colors: red, green and blue. Three associated 61 | values, in the 0-255 range, represent how much of each color is mixed up 62 | to create the original color. Theses three values must be set inside the 63 | integer to display the right color. The three least significant bytes of 64 | this integer are filled as shown in the picture below: 65 | 66 | .nf 67 | | 0 | R | G | B | color integer 68 | +---+---+---+---+ 69 | .fi 70 | 71 | 72 | While filling the integer, make sure you avoid endian problems. Remember 73 | that the "blue" byte should always be the least significant one. 74 | 75 | 76 | .SH SEE ALSO 77 | mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) 78 | 79 | 80 | .SH AUTHOR 81 | Copyright ol@ - 2002-2014 - Olivier Crouzet 82 | -------------------------------------------------------------------------------- /mlx/man/man1/mlx_pixel_put.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Drawing inside windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I int 8 | .fi 9 | .B mlx_pixel_put 10 | ( 11 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_string_put 18 | ( 19 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string 20 | ); 21 | 22 | 23 | .SH DESCRIPTION 24 | The 25 | .B mlx_pixel_put 26 | () function draws a defined pixel in the window 27 | .I win_ptr 28 | using the ( 29 | .I x 30 | , 31 | .I y 32 | ) coordinates, and the specified 33 | .I color 34 | \&. The origin (0,0) is the upper left corner of the window, the x and y axis 35 | respectively pointing right and down. The connection 36 | identifier, 37 | .I mlx_ptr 38 | , is needed (see the 39 | .B mlx 40 | man page). 41 | 42 | Parameters for 43 | .B mlx_string_put 44 | () have the same meaning. Instead of a simple pixel, the specified 45 | .I string 46 | will be displayed at ( 47 | .I x 48 | , 49 | .I y 50 | ). 51 | 52 | In both functions, it is impossible to display anything outside the 53 | specified window, nor display in another window in front of the selected one. 54 | 55 | .SH COLOR MANAGEMENT 56 | The 57 | .I color 58 | parameter has an integer type. The displayed color needs to be encoded 59 | in this integer, following a defined scheme. All displayable colors 60 | can be split in 3 basic colors: red, green and blue. Three associated 61 | values, in the 0-255 range, represent how much of each color is mixed up 62 | to create the original color. Theses three values must be set inside the 63 | integer to display the right color. The three least significant bytes of 64 | this integer are filled as shown in the picture below: 65 | 66 | .TS 67 | allbox; 68 | c s s s s 69 | r c c c c. 70 | Color Integer 71 | Interpretation \[*a] R G B 72 | Bit numbers 31..24 23..16 15..8 7..0 73 | .TE 74 | 75 | While filling the integer, make sure you avoid endian problems. Remember 76 | that the "blue" byte should always be the least significant one. 77 | 78 | 79 | .SH SEE ALSO 80 | mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) 81 | 82 | 83 | .SH AUTHOR 84 | Copyright ol@ - 2002-2014 - Olivier Crouzet 85 | -------------------------------------------------------------------------------- /get_next_line/get_next_line_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/06/06 09:05:13 by esafar #+# #+# */ 9 | /* Updated: 2021/06/25 12:32:32 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | /* 15 | size_t ft_strlen(char const *str) 16 | { 17 | size_t i; 18 | 19 | if (!str) 20 | return (0); 21 | i = 0; 22 | while (str[i]) 23 | i++; 24 | return (i); 25 | } 26 | 27 | char *ft_strdup(char *src) 28 | { 29 | size_t i; 30 | char *dest; 31 | 32 | dest = (char *)malloc(sizeof(char) * (ft_strlen(src) + 1)); 33 | if (!dest) 34 | return (NULL); 35 | i = 0; 36 | while (src[i] != '\0') 37 | { 38 | dest[i] = src[i]; 39 | i++; 40 | } 41 | dest[i] = '\0'; 42 | return (dest); 43 | }*/ 44 | 45 | int ft_isnewline(char *s) 46 | { 47 | size_t i; 48 | 49 | i = 0; 50 | if (!s) 51 | return (0); 52 | while (s[i] != '\0') 53 | { 54 | if (s[i] == '\n') 55 | return (1); 56 | i++; 57 | } 58 | return (0); 59 | } 60 | /* 61 | char *ft_strjoin(char const *s1, char const *s2) 62 | { 63 | size_t i; 64 | size_t j; 65 | size_t len; 66 | char *newstr; 67 | 68 | if (!save || !buff) 69 | return (NULL); 70 | len = ft_strlen((char *)save) + ft_strlen((char *)buff); 71 | newstr = (char *)malloc(sizeof(char) * (len + 1)); 72 | if (!newstr) 73 | return (NULL); 74 | i = -1; 75 | while (save[++i] != '\0') 76 | newstr[i] = save[i]; 77 | j = -1; 78 | while (buff[++j] != '\0') 79 | newstr[i + j] = buff[j]; 80 | newstr[i + j] = '\0'; 81 | free((char *)save); 82 | return (newstr); 83 | }*/ 84 | -------------------------------------------------------------------------------- /srcs/exit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* exit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/23 18:23:27 by esafar #+# #+# */ 9 | /* Updated: 2021/11/23 18:23:30 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void destroy_player_img(t_test *test) 16 | { 17 | mlx_destroy_image(test->mlx, test->player.frontside.img); 18 | mlx_destroy_image(test->mlx, test->player.backside.img); 19 | mlx_destroy_image(test->mlx, test->player.rightside.img); 20 | mlx_destroy_image(test->mlx, test->player.leftside.img); 21 | mlx_destroy_image(test->mlx, test->player.dmg_front.img); 22 | mlx_destroy_image(test->mlx, test->player.dmg_back.img); 23 | mlx_destroy_image(test->mlx, test->player.dmg_right.img); 24 | mlx_destroy_image(test->mlx, test->player.dmg_left.img); 25 | } 26 | 27 | int close_win_cross(t_test *test) 28 | { 29 | mlx_loop_end (test->mlx); 30 | clean_exit(test); 31 | return (0); 32 | } 33 | 34 | void free_map(t_test *test) 35 | { 36 | test->iter.i = 0; 37 | while (test->param.map[test->iter.i]) 38 | { 39 | free(test->param.map[test->iter.i]); 40 | test->iter.i++; 41 | } 42 | free(test->param.map); 43 | } 44 | 45 | void clean_exit(t_test *test) 46 | { 47 | mlx_destroy_image(test->mlx, test->data.img); 48 | destroy_event_img(test); 49 | destroy_obj_img(test); 50 | destroy_fire_img(test); 51 | destroy_player_img(test); 52 | destroy_collec_floor_wall(test); 53 | mlx_destroy_window(test->mlx, test->win); 54 | test->win = NULL; 55 | mlx_loop_end(test->mlx); 56 | mlx_destroy_display(test->mlx); 57 | free(test->mlx); 58 | free_map(test); 59 | exit(0); 60 | } 61 | -------------------------------------------------------------------------------- /mlx/mlx_int_str_to_wordtab.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_str_to_wordtab.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Sep 13 11:36:09 2000 Charlie Root 8 | ** Last update Fri Dec 14 11:02:09 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_int_str_str(char *str,char *find,int len) 16 | { 17 | int len_f; 18 | int pos; 19 | char *s; 20 | char *f; 21 | 22 | len_f = strlen(find); 23 | if (len_f>len) 24 | return (-1); 25 | pos = 0; 26 | while (*(str+len_f-1)) 27 | { 28 | s = str; 29 | f = find; 30 | while (*(f++) == *(s++)) 31 | if (!*f) 32 | return (pos); 33 | str ++; 34 | pos ++; 35 | } 36 | return (-1); 37 | } 38 | 39 | 40 | 41 | int mlx_int_str_str_cote(char *str,char *find,int len) 42 | { 43 | int len_f; 44 | int pos; 45 | char *s; 46 | char *f; 47 | int cote; 48 | 49 | len_f = strlen(find); 50 | if (len_f>len) 51 | return (-1); 52 | cote = 0; 53 | pos = 0; 54 | while (*(str+len_f-1)) 55 | { 56 | if (*str=='"') 57 | cote = 1-cote; 58 | if (!cote) 59 | { 60 | s = str; 61 | f = find; 62 | while (*(f++) == *(s++)) 63 | if (!*f) 64 | return (pos); 65 | } 66 | str ++; 67 | pos ++; 68 | } 69 | return (-1); 70 | } 71 | 72 | 73 | char **mlx_int_str_to_wordtab(char *str) 74 | { 75 | char **tab; 76 | int pos; 77 | int nb_word; 78 | int len; 79 | 80 | len = strlen(str); 81 | nb_word = 0; 82 | pos = 0; 83 | while (pos +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 11:03:46 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:45:52 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void draw_background(t_test *test) 16 | { 17 | int y; 18 | int x; 19 | 20 | y = 0; 21 | x = 0; 22 | while (y < (test->param.height - 2) * 64 + 3 * 64) 23 | { 24 | x = 0; 25 | while (x < test->param.width_with_x * 64 - (2 * 64)) 26 | { 27 | my_mlx_pixel_put(test, x, y, 0xFF000000); 28 | x++; 29 | } 30 | y++; 31 | } 32 | } 33 | 34 | void draw_walls(t_test *test) 35 | { 36 | int y; 37 | int x; 38 | 39 | y = 0; 40 | while (y < 3) 41 | { 42 | x = test->param.width_with_x - test->param.width - 1; 43 | while (x < test->param.width_with_x - 2) 44 | { 45 | draw_on_image(test, &test->all.wall, x * 64, y * 64); 46 | x++; 47 | } 48 | y++; 49 | } 50 | } 51 | 52 | void draw_floors(t_test *test) 53 | { 54 | int y; 55 | int x; 56 | int count; 57 | 58 | y = 0; 59 | count = 0; 60 | while (y < test->param.height - 2) 61 | { 62 | x = test->param.width_with_x - test->param.width - count - 1 - 1; 63 | while (x < test->param.width_with_x - 2 - count) 64 | { 65 | if (x == test->param.width_with_x - test->param.width - count - 1 - 1) 66 | draw_on_image(test, &test->all.floor_half_right, x * 64, 3 * 64 + y * 64); 67 | else if (x == test->param.width_with_x - 2 - count - 1) 68 | draw_on_image(test, &test->all.floor_half_left, x * 64, 3 * 64 + y * 64); 69 | else 70 | draw_on_image(test, &test->all.floor, x * 64, 3 * 64 + y * 64); 71 | x++; 72 | } 73 | count++; 74 | y++; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /srcs/handle_keypress.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* handle_keypress.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 20:26:58 by esafar #+# #+# */ 9 | /* Updated: 2021/12/07 20:27:11 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void check_game_keypress(t_test *test, int keysym) 16 | { 17 | if (keysym == ESC) 18 | clean_exit(test); 19 | else if (keysym == D) 20 | move_right(test); 21 | else if (keysym == A) 22 | move_left(test); 23 | else if (keysym == W) 24 | move_up(test); 25 | else if (keysym == S) 26 | move_down(test); 27 | else if (keysym == E) 28 | pick_up_coll(test); 29 | else if (keysym == P) 30 | play_piano(test); 31 | else if (keysym == C) 32 | clean_dialog(test); 33 | else if (keysym == O && test->collec.count == test->collec.amount) 34 | open_trapdoor(test); 35 | else if (keysym != ESC) 36 | write(1, &keysym, 1); 37 | } 38 | 39 | void check_intro_keypress(t_test *test, int keysym) 40 | { 41 | if (keysym == SPACE && test->intro_or_not == 1) 42 | test->intro_or_not++; 43 | else if (keysym == SPACE && test->intro_or_not == 2) 44 | test->intro_or_not++; 45 | else if (keysym == SPACE && test->intro_or_not == 3) 46 | test->intro_or_not++; 47 | else if (keysym == SPACE && test->intro_or_not == 4) 48 | test->intro_or_not++; 49 | else if (keysym == SPACE && test->intro_or_not == 5) 50 | test->intro_or_not = 0; 51 | else if (keysym == ESC) 52 | clean_exit(test); 53 | else 54 | write(1, &keysym, 1); 55 | } 56 | 57 | int handle_keypress(int keysym, t_test *test) 58 | { 59 | if (test->intro_or_not == 0) 60 | check_game_keypress(test, keysym); 61 | else 62 | check_intro_keypress(test, keysym); 63 | return (0); 64 | } 65 | -------------------------------------------------------------------------------- /libft/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: esafar +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/06/03 15:40:15 by esafar #+# #+# # 9 | # Updated: 2021/09/10 09:09:07 by esafar ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = libft.a 14 | 15 | SRCS = ft_strlen.c \ 16 | ft_isalpha.c \ 17 | ft_isdigit.c \ 18 | ft_isprint.c \ 19 | ft_isalnum.c \ 20 | ft_toupper.c \ 21 | ft_tolower.c \ 22 | ft_memcpy.c \ 23 | ft_memset.c \ 24 | ft_memccpy.c \ 25 | ft_bzero.c \ 26 | ft_atoi.c \ 27 | ft_strchr.c \ 28 | ft_strncmp.c \ 29 | ft_strrchr.c \ 30 | ft_strdup.c \ 31 | ft_memchr.c \ 32 | ft_memcmp.c \ 33 | ft_isascii.c \ 34 | ft_calloc.c \ 35 | ft_strnstr.c \ 36 | ft_strlcat.c \ 37 | ft_itoa.c \ 38 | ft_putchar_fd.c \ 39 | ft_putstr_fd.c \ 40 | ft_putendl_fd.c \ 41 | ft_putnbr_fd.c \ 42 | ft_strjoin.c \ 43 | ft_memmove.c \ 44 | ft_strlcpy.c \ 45 | ft_substr.c \ 46 | ft_strtrim.c \ 47 | ft_strmapi.c \ 48 | ft_split.c 49 | 50 | OBJS = $(SRCS:.c=.o) 51 | 52 | BONUS = ft_lstsize.c \ 53 | ft_lstadd_front.c \ 54 | ft_lstlast.c \ 55 | ft_lstadd_back.c \ 56 | ft_lstnew.c \ 57 | ft_lstdelone.c \ 58 | ft_lstclear.c \ 59 | ft_lstiter.c \ 60 | ft_lstmap.c 61 | 62 | OBJS_BONUS = $(BONUS:.c=.o) 63 | 64 | CFLAGS = -Wall -Wextra -Werror -I. 65 | RM = rm -f 66 | 67 | all: $(NAME) 68 | 69 | $(NAME): $(OBJS) 70 | ar rcs $(NAME) $(OBJS) 71 | 72 | clean: 73 | $(RM) $(OBJS) $(OBJS_BONUS) 74 | 75 | fclean: clean 76 | $(RM) $(NAME) bonus 77 | 78 | re: fclean $(NAME) 79 | 80 | bonus: $(OBJS) $(OBJS_BONUS) 81 | ar rcs $(NAME) $(OBJS) $(OBJS_BONUS) 82 | 83 | .PHONY: all clean fclean re bonus 84 | -------------------------------------------------------------------------------- /srcs/norme4.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* norme4.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/13 15:05:28 by esafar #+# #+# */ 9 | /* Updated: 2021/12/13 15:05:37 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void norme16(t_test *test) 16 | { 17 | test->all.floor_half_left.img = mlx_xpm_file_to_image \ 18 | (test->mlx, "textures/floor_half_left.xpm", &test->all.\ 19 | floor_half_left.x, &test->all.floor_half_left.y); 20 | test->all.floor_half_left.addr = mlx_get_data_addr \ 21 | (test->all.floor_half_left.img, &test->all.floor_half_left.\ 22 | bits_per_pixel, &test->all.floor_half_left.line_length, \ 23 | &test->all.floor_half_left.endian); 24 | test->all.box.img = mlx_xpm_file_to_image \ 25 | (test->mlx, "textures/box.xpm", &test->all.box.x, \ 26 | &test->all.box.y); 27 | test->all.box.addr = mlx_get_data_addr \ 28 | (test->all.box.img, &test->all.box.bits_per_pixel, &test->all.\ 29 | box.line_length, &test->all.box.endian); 30 | test->all.pot.img = mlx_xpm_file_to_image \ 31 | (test->mlx, "textures/pot.xpm", &test->all.pot.x, \ 32 | &test->all.pot.y); 33 | test->all.pot.addr = mlx_get_data_addr \ 34 | (test->all.pot.img, &test->all.pot.bits_per_pixel, &test->all.\ 35 | pot.line_length, &test->all.pot.endian); 36 | } 37 | 38 | void init_img1(t_test *test) 39 | { 40 | test->stats.full_heart.img = mlx_xpm_file_to_image(test->mlx, \ 41 | "textures/white_full_heart.xpm", &test->stats.full_heart.x, \ 42 | &test->stats.full_heart.y); 43 | test->stats.full_heart.addr = mlx_get_data_addr(test->stats.full_heart.img, \ 44 | &test->stats.full_heart.bits_per_pixel, \ 45 | &test->stats.full_heart.line_length, &test->stats.full_heart.endian); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/exec_moves.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* exec_moves.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/08 10:25:21 by esafar #+# #+# */ 9 | /* Updated: 2021/12/08 10:25:35 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void exec_right(t_test *test) 16 | { 17 | test->param.map[test->player.pos_i][test->player.pos_j] = '0'; 18 | test->param.map[test->player.pos_i][test->player.pos_j + 1] = 'P'; 19 | test->player.lastpos_j = test->player.pos_j; 20 | test->player.pos_j++; 21 | test->player.side = &test->player.rightside; 22 | test->player.pos_x += 64; 23 | test->player.pos_y += 0; 24 | } 25 | 26 | void exec_left(t_test *test) 27 | { 28 | test->param.map[test->player.pos_i][test->player.pos_j] = '0'; 29 | test->param.map[test->player.pos_i][test->player.pos_j - 1] = 'P'; 30 | test->player.lastpos_j = test->player.pos_j; 31 | test->player.pos_j--; 32 | test->player.side = &test->player.leftside; 33 | test->player.pos_x -= 64; 34 | test->player.pos_y += 0; 35 | } 36 | 37 | void exec_up(t_test *test) 38 | { 39 | test->param.map[test->player.pos_i][test->player.pos_j] = '0'; 40 | test->param.map[test->player.pos_i - 1][test->player.pos_j] = 'P'; 41 | test->player.lastpos_i = test->player.pos_i; 42 | test->player.pos_i--; 43 | test->player.side = &test->player.backside; 44 | test->player.pos_x += 64; 45 | test->player.pos_y -= 64; 46 | } 47 | 48 | void exec_down(t_test *test) 49 | { 50 | test->param.map[test->player.pos_i][test->player.pos_j] = '0'; 51 | test->param.map[test->player.pos_i + 1][test->player.pos_j] = 'P'; 52 | test->player.lastpos_i = test->player.pos_i; 53 | test->player.pos_i++; 54 | test->player.side = &test->player.frontside; 55 | test->player.pos_x -= 64; 56 | test->player.pos_y += 64; 57 | } 58 | -------------------------------------------------------------------------------- /mlx/test/run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # This very basic script simulate user inputs for the CI 4 | # Feel free to update, improve or remove it if proper 5 | # intergration tests and/or unit tests are added. 6 | 7 | set -e 8 | 9 | BOLD="\033[1m" 10 | RESET="\033[0m" 11 | LIGHT_RED="\033[91m" 12 | LIGHT_GREEN="\033[92m" 13 | LIGHT_CYAN="\033[96m" 14 | 15 | logging(){ 16 | local type=$1; shift 17 | printf "${LIGHT_CYAN}${BOLD}run_tests${RESET} [%b] : %b\n" "$type" "$*" 18 | } 19 | log_info(){ 20 | logging "${LIGHT_GREEN}info${RESET}" "$@" 21 | } 22 | log_error(){ 23 | logging "${LIGHT_RED}error${RESET}" "$@" >&2 24 | exit 1 25 | } 26 | 27 | 28 | PID="" 29 | 30 | # to properly kill child process executed in background on exit 31 | at_exit() { 32 | status=$? 33 | [ $status -eq 0 ] && log_info "Seem all went well" && exit 0 34 | # Code for non-zero exit: 35 | if ! kill -s TERM "$PID" 2>/dev/null || ! wait "$PID" ; then 36 | log_error "Pid [$PID] died with status $status " 37 | fi 38 | log_error "Something went wrong. Pid [$PID] has been killed. Status code $status" 39 | } 40 | # to properly quit from ctrl+c (SIGINT Signal) 41 | sigint_handler(){ 42 | kill -s TERM "$PID" 43 | wait 44 | log_info "Tests abort" 45 | exit 1 46 | } 47 | 48 | # look at test/main.c and run ./mlx-test to understand what this function does 49 | test_default_main(){ 50 | ${MAKE} -f Makefile.gen all 51 | ./mlx-test & 52 | PID="$!" 53 | log_info "./mlx-test running in background, pid:" $PID 54 | 55 | i=25 # waiting 25s mlx-test to be ready for inputs. 56 | while [ $i -gt 0 ]; do 57 | if ! ps -p $PID > /dev/null ; then 58 | wait $PID 59 | fi 60 | log_info "countdown" $i 61 | sleep 1 62 | i=$((i - 1)) 63 | done 64 | log_info "Ready to \"just play\" using xdotool" 65 | wid1=$(xdotool search --name Title1) 66 | wid2=$(xdotool search --name Title2) 67 | wid3=$(xdotool search --name Title3) 68 | 69 | xdotool windowfocus $wid3 70 | log_info "Focus Win3: Testing move mouse 100 100" 71 | xdotool mousemove 100 100 72 | log_info "Focus Win3: Testing move mouse 200 200" 73 | xdotool mousemove 200 200 74 | log_info "Focus Win3: Pressing escape to destroy window \"Win3\"" 75 | xdotool key Escape 76 | 77 | log_info "Focus Win2: Pressing escape to stop program" 78 | xdotool windowfocus $wid2 79 | xdotool key Escape 80 | } 81 | 82 | main(){ 83 | case $(uname) in 84 | FreeBSD) MAKE=gmake ;; 85 | *) MAKE=make ;; 86 | esac 87 | cd $(dirname $0) 88 | trap at_exit EXIT 89 | trap sigint_handler INT 90 | 91 | test_default_main 92 | } 93 | 94 | main "$@" 95 | -------------------------------------------------------------------------------- /libft/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/25 08:17:33 by esafar #+# #+# */ 9 | /* Updated: 2021/06/04 09:14:51 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | static int countword(char const *s, char c) 16 | { 17 | int i; 18 | int count; 19 | 20 | i = 0; 21 | count = 0; 22 | while (s[i] != '\0') 23 | { 24 | if ((s[i] == c || s[i] == '\0') == 0 25 | && (s[i + 1] == c || s[i + 1] == '\0') == 1) 26 | count++; 27 | i++; 28 | } 29 | return (count); 30 | } 31 | 32 | static char *mallocword(char const *s, char c) 33 | { 34 | int i; 35 | char *word; 36 | 37 | i = 0; 38 | while (s[i] && s[i] != c) 39 | i++; 40 | word = (char *)malloc(sizeof(char) * (i + 1)); 41 | if (!word) 42 | return (NULL); 43 | i = 0; 44 | while (s[i] && s[i] != c) 45 | { 46 | word[i] = s[i]; 47 | i++; 48 | } 49 | word[i] = '\0'; 50 | return (word); 51 | } 52 | 53 | static void **freeforyourlife(char **split, int i) 54 | { 55 | while (split[i]) 56 | { 57 | free(split[i]); 58 | i++; 59 | } 60 | free(split); 61 | return (NULL); 62 | } 63 | 64 | static char **splitception(char const *s, char **split, int i, char c) 65 | { 66 | while (*s) 67 | { 68 | while (*s && *s == c) 69 | s++; 70 | if (*s && *s != c) 71 | { 72 | split[i] = mallocword(s, c); 73 | if (split[i] == NULL) 74 | freeforyourlife(split, i); 75 | i++; 76 | while (*s && *s != c) 77 | s++; 78 | } 79 | } 80 | split[i] = NULL; 81 | return (split); 82 | } 83 | 84 | char **ft_split(char const *s, char c) 85 | { 86 | int i; 87 | char **split; 88 | 89 | i = 0; 90 | if (!s) 91 | return (NULL); 92 | split = (char **)malloc(sizeof(char *) * (countword(s, c) + 1)); 93 | if (!split) 94 | return (NULL); 95 | splitception(s, split, i, c); 96 | return (split); 97 | } 98 | -------------------------------------------------------------------------------- /srcs/initialize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* initialize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/08 11:00:41 by esafar #+# #+# */ 9 | /* Updated: 2021/12/08 11:00:43 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void init_player_pos(t_test *test) 16 | { 17 | test->player.pos_i = 0; 18 | test->player.lastpos_i = 0; 19 | test->player.hurt = 0; 20 | test->player.pos_j = 0; 21 | test->player.lastpos_j = 0; 22 | test->player.pos_x = 0; 23 | test->player.pos_y = 0; 24 | test->player.steps = 0; 25 | test->player.lock_pos = 0; 26 | } 27 | 28 | void init_player(t_test *test) 29 | { 30 | init_player_pos(test); 31 | test->player.frontside.img = NULL; 32 | test->player.frontside.addr = NULL; 33 | test->player.backside.img = NULL; 34 | test->player.backside.addr = NULL; 35 | test->player.rightside.img = NULL; 36 | test->player.rightside.addr = NULL; 37 | test->player.leftside.img = NULL; 38 | test->player.leftside.addr = NULL; 39 | test->player.dmg_front.img = NULL; 40 | test->player.dmg_front.addr = NULL; 41 | test->player.dmg_back.img = NULL; 42 | test->player.dmg_back.addr = NULL; 43 | test->player.dmg_right.img = NULL; 44 | test->player.dmg_right.addr = NULL; 45 | test->player.dmg_left.img = NULL; 46 | test->player.dmg_left.addr = NULL; 47 | } 48 | 49 | void initialize(t_test *test) 50 | { 51 | test->mlx = NULL; 52 | test->win = NULL; 53 | test->frame = 0; 54 | test->loop = 1; 55 | test->intro_or_not = 1; 56 | test->data.img = NULL; 57 | test->data.addr = NULL; 58 | init_stats(test); 59 | init_event(test); 60 | init_param(test); 61 | init_intro(test); 62 | init_player(test); 63 | init_fire(test); 64 | init_chimney_dresser(test); 65 | init_collec_exit(test); 66 | init_all_remain(test); 67 | test->tex.tex_x = 0; 68 | test->tex.tex_y = 0; 69 | test->tex.ratio_x = 1.0f; 70 | test->tex.ratio_y = 1.0f; 71 | } 72 | -------------------------------------------------------------------------------- /srcs/draw_on_images.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_on_images.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 10:59:23 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:46:10 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void draw_on_image(t_test *test, t_data *img, int startx, int starty) 16 | { 17 | int x; 18 | int y; 19 | 20 | y = 0; 21 | while (y < 64) 22 | { 23 | test->tex.tex_y = (int)((double)y * test->tex.ratio_y); 24 | x = 0; 25 | while (x < 64) 26 | { 27 | test->tex.tex_x = (int)((double)x * test->tex.ratio_x); 28 | if (get_pixel(img, test->tex.tex_x, test->tex.tex_y) != (int)0xFF000000) 29 | my_mlx_pixel_put(test, x + startx, y + starty, get_pixel(img, test->tex.tex_x, test->tex.tex_y)); 30 | x++; 31 | } 32 | y++; 33 | } 34 | } 35 | 36 | void draw_on_image_bis(t_test *test, t_data *img, int startx, int starty) 37 | { 38 | int x; 39 | int y; 40 | 41 | y = 0; 42 | while (y < 128) 43 | { 44 | test->tex.tex_y = (int)((double)y * test->tex.ratio_y); 45 | x = 0; 46 | while (x < 128) 47 | { 48 | test->tex.tex_x = (int)((double)x * test->tex.ratio_x); 49 | if (get_pixel(img, test->tex.tex_x, test->tex.tex_y) 50 | != (int)0xFF000000) 51 | my_mlx_pixel_put(test, x + startx, y + starty, \ 52 | get_pixel(img, test->tex.tex_x, test->tex.tex_y)); 53 | x++; 54 | } 55 | y++; 56 | } 57 | } 58 | 59 | void draw_on_image_intro(t_test *test, t_data *img, int startx, int starty) 60 | { 61 | int x; 62 | int y; 63 | 64 | y = 0; 65 | while (y < 448) 66 | { 67 | test->tex.tex_y = (int)((double)y * test->tex.ratio_y); 68 | x = 0; 69 | while (x < 960) 70 | { 71 | test->tex.tex_x = (int)((double)x * test->tex.ratio_x); 72 | my_mlx_pixel_put(test, x + startx, y + starty, \ 73 | get_pixel(img, test->tex.tex_x, test->tex.tex_y)); 74 | x++; 75 | } 76 | y++; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /srcs/exec_events.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* exec_events.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/08 10:29:27 by esafar #+# #+# */ 9 | /* Updated: 2021/12/08 10:29:36 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void exec_trap(t_test *test, int direction) 16 | { 17 | if (direction == 1) 18 | test->player.side = &test->player.rightside; 19 | if (direction == 2) 20 | test->player.side = &test->player.leftside; 21 | if (direction == 3) 22 | test->player.side = &test->player.backside; 23 | if (direction == 4) 24 | test->player.side = &test->player.frontside; 25 | test->player.hurt = 1; 26 | test->stats.lives--; 27 | ft_putstr_fd("This hurt....\nlives left : ", 1); 28 | ft_putnbr_fd(test->stats.lives, 1); 29 | ft_putstr_fd("\n", 1); 30 | if (test->stats.lives == 0) 31 | { 32 | ft_putstr_fd("GAME OVER :(\n", 1); 33 | clean_exit(test); 34 | } 35 | } 36 | 37 | void exec_exit(t_test *test, int direction) 38 | { 39 | if (direction == 1) 40 | test->player.side = &test->player.rightside; 41 | if (direction == 2) 42 | test->player.side = &test->player.leftside; 43 | if (direction == 3) 44 | test->player.side = &test->player.backside; 45 | if (direction == 4) 46 | test->player.side = &test->player.frontside; 47 | test->collec.exit = 1; 48 | if (test->all.exit.opened == 1) 49 | { 50 | ft_putstr_fd("Good job! You finished the game\n", 1); 51 | clean_exit(test); 52 | } 53 | } 54 | 55 | void exec_not_all_items(t_test *test, int direction) 56 | { 57 | if (direction == 1) 58 | test->player.side = &test->player.rightside; 59 | if (direction == 2) 60 | test->player.side = &test->player.leftside; 61 | if (direction == 3) 62 | test->player.side = &test->player.backside; 63 | if (direction == 4) 64 | test->player.side = &test->player.frontside; 65 | ft_putstr_fd("Not enought items to go out.\n", 1); 66 | test->dialog_box.event = 3; 67 | draw_dialog_box(test); 68 | test->dialog_box.keep = 1; 69 | } 70 | -------------------------------------------------------------------------------- /srcs/initialize_functionnalities.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* initialize_functionnalities.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/08 10:52:13 by esafar #+# #+# */ 9 | /* Updated: 2021/12/08 10:52:24 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void init_intro(t_test *test) 16 | { 17 | test->intro.one.img = NULL; 18 | test->intro.one.addr = NULL; 19 | test->intro.two.img = NULL; 20 | test->intro.two.addr = NULL; 21 | test->intro.three.img = NULL; 22 | test->intro.three.addr = NULL; 23 | test->intro.four.img = NULL; 24 | test->intro.four.addr = NULL; 25 | test->intro.five.img = NULL; 26 | test->intro.five.addr = NULL; 27 | } 28 | 29 | void init_stats(t_test *test) 30 | { 31 | test->stats.lives = 3; 32 | test->stats.damages = 0; 33 | test->stats.typeface_life.img = NULL; 34 | test->stats.typeface_life.addr = NULL; 35 | test->stats.full_heart.img = NULL; 36 | test->stats.full_heart.addr = NULL; 37 | test->stats.empty_heart.img = NULL; 38 | test->stats.empty_heart.addr = NULL; 39 | test->stats.glass.img = NULL; 40 | test->stats.glass.addr = NULL; 41 | test->stats.step.img = NULL; 42 | test->stats.step.addr = NULL; 43 | } 44 | 45 | void init_event(t_test *test) 46 | { 47 | test->button.time = 0; 48 | test->button.e_key.img = NULL; 49 | test->button.e_key.addr = NULL; 50 | test->button.p_key.img = NULL; 51 | test->button.p_key.addr = NULL; 52 | test->button.o_key.img = NULL; 53 | test->button.o_key.addr = NULL; 54 | test->dialog_box.keep = 0; 55 | test->dialog_box.right.img = NULL; 56 | test->dialog_box.right.addr = NULL; 57 | test->dialog_box.mid.img = NULL; 58 | test->dialog_box.mid.addr = NULL; 59 | test->dialog_box.left.img = NULL; 60 | test->dialog_box.left.addr = NULL; 61 | } 62 | 63 | void init_param(t_test *test) 64 | { 65 | test->param.map = NULL; 66 | test->param.height = 0; 67 | test->param.height_with_wall = 0; 68 | test->param.width = 0; 69 | test->param.width_with_x = 0; 70 | test->param.rendered = 0; 71 | } 72 | -------------------------------------------------------------------------------- /mlx/man/man1/mlx.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Simple X-Window Interface Library for students 4 | .SH SYNOPSYS 5 | #include 6 | 7 | .nf 8 | .I void * 9 | .fi 10 | .B mlx_init 11 | (); 12 | 13 | .SH DESCRIPTION 14 | MiniLibX is an easy way to create graphical software, 15 | without any X-Window programming knowledge. It provides 16 | simple window creation, a drawing tool, image and basic events 17 | management. 18 | 19 | .SH X-WINDOW CONCEPT 20 | 21 | X-Window is a network-oriented graphical system for Unix. 22 | It is based on two main parts: 23 | .br 24 | On one side, your software wants to draw something on the screen and/or 25 | get keyboard & mouse entries. 26 | .br 27 | On the other side, the X-Server manages the screen, keyboard and mouse 28 | (It is often refered to as a "display"). 29 | .br 30 | A network connection must be established between these two entities to send 31 | drawing orders (from the software to the X-Server), and keyboard/mouse 32 | events (from the X-Server to the software). 33 | 34 | .SH INCLUDE FILE 35 | .B mlx.h 36 | should be included for a correct use of the MiniLibX API. 37 | It only contains function prototypes, no structure is needed. 38 | 39 | .SH LIBRARY FUNCTIONS 40 | .P 41 | First of all, you need to initialize the connection 42 | between your software and the display. 43 | Once this connection is established, you'll be able to 44 | use other MiniLibX functions to send the X-Server messages, 45 | like "I want to draw a yellow pixel in this window" or "did the 46 | user hit a key?". 47 | .P 48 | The 49 | .B mlx_init 50 | function will create this connection. No parameters are needed, ant it will 51 | return a 52 | .I "void *" 53 | identifier, used for further calls to the library routines. 54 | .P 55 | All other MiniLibX functions are described in the following man pages: 56 | 57 | .TP 20 58 | .B mlx_new_window 59 | : manage windows 60 | .TP 20 61 | .B mlx_pixel_put 62 | : draw inside window 63 | .TP 20 64 | .B mlx_new_image 65 | : manipulate images 66 | .TP 20 67 | .B mlx_loop 68 | : handle keyboard or mouse events 69 | 70 | .SH LINKING MiniLibX 71 | To use MiniLibX functions, you'll need to link 72 | your software with several libraries, including the MiniLibX library itself. 73 | To do this, simply add the following arguments at linking time: 74 | 75 | .B -lmlx -lXext -lX11 76 | 77 | You may also need to specify the path to these libraries, using 78 | the 79 | .B -L 80 | flag. 81 | 82 | 83 | .SH RETURN VALUES 84 | If 85 | .B mlx_init() 86 | fails to set up the connection to the X server, it will return NULL, otherwise 87 | a non-null pointer is returned as a connection identifier. 88 | 89 | .SH SEE ALSO 90 | mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 91 | 92 | .SH AUTHOR 93 | Copyright ol@ - 2002-2014 - Olivier Crouzet 94 | -------------------------------------------------------------------------------- /mlx/man/man3/mlx.3: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Simple X-Window Interface Library for students 4 | .SH SYNOPSYS 5 | #include 6 | 7 | .nf 8 | .I void * 9 | .fi 10 | .B mlx_init 11 | (); 12 | 13 | .SH DESCRIPTION 14 | MiniLibX is an easy way to create graphical software, 15 | without any X-Window programming knowledge. It provides 16 | simple window creation, a drawing tool, image and basic events 17 | management. 18 | 19 | .SH X-WINDOW CONCEPT 20 | 21 | X-Window is a network-oriented graphical system for Unix. 22 | It is based on two main parts: 23 | .br 24 | On one side, your software wants to draw something on the screen and/or 25 | get keyboard & mouse entries. 26 | .br 27 | On the other side, the X-Server manages the screen, keyboard and mouse 28 | (It is often refered to as a "display"). 29 | .br 30 | A network connection must be established between these two entities to send 31 | drawing orders (from the software to the X-Server), and keyboard/mouse 32 | events (from the X-Server to the software). 33 | 34 | .SH INCLUDE FILE 35 | .B mlx.h 36 | should be included for a correct use of the MiniLibX API. 37 | It only contains function prototypes, no structure is needed. 38 | 39 | .SH LIBRARY FUNCTIONS 40 | .P 41 | First of all, you need to initialize the connection 42 | between your software and the display. 43 | Once this connection is established, you'll be able to 44 | use other MiniLibX functions to send the X-Server messages, 45 | like "I want to draw a yellow pixel in this window" or "did the 46 | user hit a key?". 47 | .P 48 | The 49 | .B mlx_init 50 | function will create this connection. No parameters are needed, ant it will 51 | return a 52 | .I "void *" 53 | identifier, used for further calls to the library routines. 54 | .P 55 | All other MiniLibX functions are described in the following man pages: 56 | 57 | .TP 20 58 | .B mlx_new_window 59 | : manage windows 60 | .TP 20 61 | .B mlx_pixel_put 62 | : draw inside window 63 | .TP 20 64 | .B mlx_new_image 65 | : manipulate images 66 | .TP 20 67 | .B mlx_loop 68 | : handle keyboard or mouse events 69 | 70 | .SH LINKING MiniLibX 71 | To use MiniLibX functions, you'll need to link 72 | your software with several libraries, including the MiniLibX library itself. 73 | To do this, simply add the following arguments at linking time: 74 | 75 | .B -lmlx -lXext -lX11 76 | 77 | You may also need to specify the path to these libraries, using 78 | the 79 | .B -L 80 | flag. 81 | 82 | 83 | .SH RETURN VALUES 84 | If 85 | .B mlx_init() 86 | fails to set up the connection to the X server, it will return NULL, otherwise 87 | a non-null pointer is returned as a connection identifier. 88 | 89 | .SH SEE ALSO 90 | mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 91 | 92 | .SH AUTHOR 93 | Copyright ol@ - 2002-2014 - Olivier Crouzet 94 | -------------------------------------------------------------------------------- /srcs/draw_exit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_exit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 20:38:06 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:50:13 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void draw_ladder(t_test *test) 16 | { 17 | draw_on_image(test, &test->all.exit.exit_half_right, test->iter.x + 23, test->iter.y); 18 | draw_on_image(test, &test->all.exit.exit_half_left, test->iter.x - 64 + 27, test->iter.y); 19 | } 20 | 21 | void draw_trapdoor_closed(t_test *test) 22 | { 23 | draw_on_image(test, &test->all.exit.trapdoor_right, test->iter.x + 23, test->iter.y); 24 | draw_on_image(test, &test->all.exit.trapdoor_left, test->iter.x - 64 + 23, test->iter.y); 25 | } 26 | 27 | void draw_trapdoor_opened(t_test *test, int x, int y) 28 | { 29 | draw_on_image(test, &test->all.exit.open_to_right, x, y); 30 | draw_on_image(test, &test->all.exit.open_to_left, x - 64, y); 31 | } 32 | 33 | void check_how_to_draw_exit(t_test *test) 34 | { 35 | if (test->param.map[test->iter.i][test->iter.j] == 'E') 36 | { 37 | draw_ladder(test); 38 | if (test->all.exit.opened == 0) 39 | draw_trapdoor_closed(test); 40 | else if (test->all.exit.opened == 1 41 | && test->param.map[test->iter.i - 1][test->iter.j] != '1') 42 | draw_trapdoor_opened(test, test->iter.x + 23 + 64 - 16, test->iter.y - 64 + 12); 43 | else if (test->all.exit.opened == 1 && test->param.map[test->iter.i - 1][test->iter.j] == '1') 44 | { 45 | if (test->param.map[test->iter.i][test->iter.j + 1] == '0' || test->param.map[test->iter.i][test->iter.j + 1] == 'P') 46 | draw_trapdoor_opened(test, test->iter.x + 23 + 64 - 8, test->iter.y + 12); 47 | } 48 | } 49 | } 50 | 51 | void draw_exit(t_test *test) 52 | { 53 | test->iter.i = 0; 54 | while (test->param.map[++test->iter.i + 1]) 55 | { 56 | test->iter.j = 0; 57 | while (test->param.map[test->iter.i][++test->iter.j + 1]) 58 | { 59 | test->iter.x = (64 + (test->param.height - 2 - test->iter.i) * 64 + (test->iter.j - 1) * 64); 60 | test->iter.y = (192 + (test->iter.i - 1) * 64); 61 | check_how_to_draw_exit(test); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /srcs/draw_furnitures2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_furnitures2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 20:11:24 by esafar #+# #+# */ 9 | /* Updated: 2021/12/07 20:11:37 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | int draw_piano(t_test *test, int piano, int x, int y) 16 | { 17 | if (piano == 0) 18 | { 19 | draw_on_image(test, &test->all.piano.downleft, x, y - 26); 20 | draw_on_image(test, &test->all.piano.midleft, x, y - 64 - 26); 21 | draw_on_image(test, &test->all.piano.topleft, x + 9, y - 128 - 26); 22 | draw_on_image(test, &test->all.piano.downmid, x + 64, y - 26); 23 | draw_on_image(test, &test->all.piano.midmid, x + 64, y - 64 - 26); 24 | draw_on_image(test, &test->all.piano.topmid, x + 64, y - 128 - 26); 25 | draw_on_image(test, &test->all.piano.downright, x + 128, y - 26); 26 | draw_on_image(test, &test->all.piano.midright, x + 128, y - 64 - 26); 27 | draw_on_image(test, &test->all.piano.topright, x + 128, y - 128 - 26); 28 | piano++; 29 | } 30 | else 31 | { 32 | draw_on_image(test, &test->all.pot, x, y - 32); 33 | draw_on_image(test, &test->all.pot, x + 64, y - 32); 34 | draw_on_image(test, &test->all.pot, x + 128, y - 32); 35 | } 36 | return (piano); 37 | } 38 | 39 | void draw_dresser(t_test *test, int x, int y) 40 | { 41 | draw_on_image(test, &test->all.dresser_downleft, x, y - 24); 42 | draw_on_image(test, &test->all.dresser_downright, x + 64, y - 24); 43 | draw_on_image(test, &test->all.dresser_topleft, x, y - 64 - 24); 44 | draw_on_image(test, &test->all.dresser_topright, x + 64, y - 64 - 24); 45 | } 46 | 47 | void draw_pot(t_test *test, int random_obj, int x, int y) 48 | { 49 | if (random_obj == 0) 50 | { 51 | draw_on_image(test, &test->all.pot, x, y - 32); 52 | if (test->all.babo == 0) 53 | { 54 | draw_on_image(test, &test->all.babolex_painting, 55 | x + 32, y - 128); 56 | test->all.babo = 1; 57 | } 58 | } 59 | } 60 | 61 | void four_pot_line(t_test *test, int x, int y) 62 | { 63 | draw_on_image(test, &test->all.pot, x, y - 32); 64 | draw_on_image(test, &test->all.pot, x + 64, y - 32); 65 | draw_on_image(test, &test->all.pot, x + 128, y - 32); 66 | draw_on_image(test, &test->all.pot, x + 192, y - 32); 67 | } 68 | -------------------------------------------------------------------------------- /srcs/draw_stats.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_stats.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 11:51:57 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:45:23 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void free_string(char *steps, char *collec, char *amount) 16 | { 17 | if (steps) 18 | { 19 | free(steps); 20 | steps = NULL; 21 | } 22 | if (collec) 23 | { 24 | free(collec); 25 | collec = NULL; 26 | } 27 | if (amount) 28 | { 29 | free(amount); 30 | amount = NULL; 31 | } 32 | } 33 | 34 | void draw_score(t_test *test) 35 | { 36 | char *steps; 37 | char *collec; 38 | char *amount; 39 | 40 | steps = ft_itoa(test->player.steps); 41 | if (!steps) 42 | clean_exit(test); 43 | mlx_string_put(test->mlx, test->win, 25 - 3 - ft_strlen(steps), 20 44 | + 10, 0xf4fefe, steps); 45 | draw_on_image(test, &test->stats.step, 40 - 8, -10); 46 | collec = ft_itoa(test->collec.count); 47 | if (!collec) 48 | clean_exit(test); 49 | amount = ft_itoa(test->collec.amount); 50 | if (!amount) 51 | clean_exit(test); 52 | mlx_string_put(test->mlx, test->win, 158 - 100 - 32 - 10, 25 53 | + 32 - 7 + 20, 0xfefefe, collec); 54 | mlx_string_put(test->mlx, test->win, 166 - 100 - 32 - 10 55 | + (ft_strlen(collec) - 1) * 6, 25 + 32 - 7 + 20, 0xfefefe, "/"); 56 | mlx_string_put(test->mlx, test->win, 173 - 100 - 32 - 10 57 | + (ft_strlen(collec) - 1) * 7, 25 + 32 - 7 + 20, 0xfefefe, amount); 58 | draw_on_image(test, &test->stats.glass, 173 - 100 - 32 - 10 59 | + (ft_strlen(collec) - 1) * 7, 15 + 20); 60 | free_string(steps, collec, amount); 61 | } 62 | 63 | void draw_life(t_test *test) 64 | { 65 | int i; 66 | int j; 67 | 68 | draw_on_image(test, &test->stats.typeface_life, 7, 28 + 64); 69 | i = test->stats.lives; 70 | test->stats.damages = 3 - test->stats.lives; 71 | while (i > 0) 72 | { 73 | j = 0; 74 | while (j < i) 75 | { 76 | draw_on_image(test, &test->stats.full_heart, 7 + j * 24, -5 + 64); 77 | j++; 78 | } 79 | while (test->stats.damages > 0) 80 | { 81 | draw_on_image(test, &test->stats.empty_heart, 7 + ((test->stats.damages - 1) + test->stats.lives) * 24, -5 + 64); 82 | test->stats.damages--; 83 | } 84 | i--; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /srcs/handle_event.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* handle_event.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 19:25:30 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:40:50 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void clean_dialog(t_test *test) 16 | { 17 | test->dialog_box.keep = 0; 18 | test->player.lock_pos = 0; 19 | } 20 | 21 | void open_trapdoor(t_test *test) 22 | { 23 | test->all.exit.opened = 1; 24 | test->player.lock_pos = 0; 25 | } 26 | 27 | void play_piano(t_test *test) 28 | { 29 | if (test->player.pos_i != 1 && test->param.map[test->player.pos_i - 1][test->player.pos_j] == '1' && test->param.map[test->player.pos_i - 1][test->player.pos_j + 1] == '1' && test->param.map[test->player.pos_i - 1][test->player.pos_j + 2] == '0' && test->player.pos_j + 1 < test->param.width - 1 && test->param.map[test->player.pos_i - 1][test->player.pos_j - 1] == '1' && test->param.map[test->player.pos_i - 1][test->player.pos_j - 2] == '0') 30 | { 31 | test->dialog_box.event = 1; 32 | draw_dialog_box(test); 33 | test->dialog_box.keep = 1; 34 | } 35 | } 36 | 37 | void pick_up_coll_event(t_test *test) 38 | { 39 | test->dialog_box.event = 2; 40 | draw_dialog_box(test); 41 | test->dialog_box.keep = 1; 42 | test->collec.count++; 43 | ft_putnbr_fd(test->collec.count, 1); 44 | ft_putstr_fd(" object in your inventory\n", 1); 45 | } 46 | 47 | void pick_up_coll(t_test *test) 48 | { 49 | if (test->param.map[test->player.pos_i][test->player.pos_j + 1] == 'C') 50 | { 51 | pick_up_coll_event(test); 52 | test->param.map[test->player.pos_i][test->player.pos_j + 1] = '0'; 53 | } 54 | else if (test->param.map[test->player.pos_i][test->player.pos_j - 1] == 'C') 55 | { 56 | pick_up_coll_event(test); 57 | test->param.map[test->player.pos_i][test->player.pos_j - 1] = '0'; 58 | } 59 | else if (test->param.map[test->player.pos_i + 1][test->player.pos_j] == 'C') 60 | { 61 | pick_up_coll_event(test); 62 | test->param.map[test->player.pos_i + 1][test->player.pos_j] = '0'; 63 | } 64 | else if (test->param.map[test->player.pos_i - 1][test->player.pos_j] == 'C') 65 | { 66 | pick_up_coll_event(test); 67 | test->param.map[test->player.pos_i - 1][test->player.pos_j] = '0'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /mlx/mlx_lib_xpm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_xpm.c for minilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Fri Dec 8 11:07:24 2000 Charlie Root 8 | ** Last update Thu Oct 4 16:00:22 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | void *mlx_int_xpm_f_image(t_xvar *xvar,int *width,int *height, 18 | int (*xpm_func)(),void *param) 19 | { 20 | XImage *img1; 21 | XImage *img2; 22 | t_img *im2; 23 | XpmAttributes xpm_att; 24 | 25 | xpm_att.visual = xvar->visual; 26 | xpm_att.colormap = xvar->cmap; 27 | xpm_att.depth = xvar->depth; 28 | xpm_att.bitmap_format = ZPixmap; 29 | xpm_att.valuemask = XpmDepth|XpmBitmapFormat|XpmVisual|XpmColormap; 30 | if (xpm_func(xvar->display,param,&img1,&img2,&xpm_att)) 31 | return ((void *)0); 32 | if (img2) 33 | XDestroyImage(img2); 34 | 35 | if (!(im2 = (void *)mlx_new_image(xvar,img1->width,img1->height))) 36 | { 37 | XDestroyImage(img1); 38 | return ((void *)0); 39 | } 40 | *width = img1->width; 41 | *height = img1->height; 42 | if (mlx_int_egal_img(im2->image,img1)) 43 | { 44 | bcopy(img1->data,im2->data,img1->height*img1->bytes_per_line); 45 | XDestroyImage(img1); 46 | return (im2); 47 | } 48 | if (im2->type==MLX_TYPE_SHM_PIXMAP) 49 | { 50 | XFreePixmap(xvar->display,im2->pix); 51 | im2->pix = XCreatePixmap(xvar->display,xvar->root, 52 | *width,*height,xvar->depth); 53 | } 54 | if (im2->type>MLX_TYPE_XIMAGE) 55 | { 56 | XShmDetach(xvar->display,&(im2->shm)); 57 | shmdt(im2->data); 58 | } 59 | XDestroyImage(im2->image); 60 | im2->image = img1; 61 | im2->data = img1->data; 62 | im2->type = MLX_TYPE_XIMAGE; 63 | im2->size_line = img1->bytes_per_line; 64 | im2->bpp = img1->bits_per_pixel; 65 | return (im2); 66 | } 67 | 68 | 69 | int mlx_int_egal_img(XImage *img1,XImage *img2) 70 | { 71 | if (img1->width!=img2->width || img1->height!=img2->height || 72 | img1->xoffset!=img2->xoffset || img1->format!=img2->format || 73 | img1->byte_order!=img2->byte_order || 74 | img1->bitmap_unit!=img2->bitmap_unit || 75 | img1->bitmap_bit_order!=img2->bitmap_bit_order || 76 | img1->bitmap_pad!=img2->bitmap_pad || img1->depth!=img2->depth || 77 | img1->bytes_per_line!=img2->bytes_per_line || 78 | img1->bits_per_pixel!=img2->bits_per_pixel || 79 | img1->red_mask!=img2->red_mask || img1->green_mask!=img2->green_mask || 80 | img1->blue_mask!=img2->blue_mask ) 81 | return (0); 82 | return (1); 83 | } 84 | 85 | 86 | void *mlx_xpm_file_to_image(t_xvar *xvar,char *filename, 87 | int *width,int *height) 88 | { 89 | return (mlx_int_xpm_f_image(xvar,width,height,XpmReadFileToImage,filename)); 90 | } 91 | 92 | 93 | void *mlx_xpm_to_image(t_xvar *xvar,char **data,int *width,int *height) 94 | { 95 | return (mlx_int_xpm_f_image(xvar,width,height,XpmCreateImageFromData,(void *)data)); 96 | } 97 | -------------------------------------------------------------------------------- /mlx/mlx_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_init.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 16:52:42 2000 Charlie Root 8 | ** Last update Fri Jan 28 17:05:09 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | void *mlx_init() 17 | { 18 | t_xvar *xvar; 19 | 20 | if (!(xvar = malloc(sizeof(*xvar)))) 21 | return ((void*)0); 22 | if ((xvar->display = XOpenDisplay("")) == 0) 23 | { 24 | free(xvar); 25 | return ((void*)0); 26 | } 27 | xvar->screen = DefaultScreen(xvar->display); 28 | xvar->root = DefaultRootWindow(xvar->display); 29 | xvar->cmap = DefaultColormap(xvar->display,xvar->screen); 30 | xvar->depth = DefaultDepth(xvar->display,xvar->screen); 31 | if (mlx_int_get_visual(xvar)==-1) 32 | { 33 | printf(ERR_NO_TRUECOLOR); 34 | exit(1); 35 | } 36 | xvar->win_list = 0; 37 | xvar->loop_hook = 0; 38 | xvar->loop_param = (void *)0; 39 | xvar->do_flush = 1; 40 | xvar->wm_delete_window = XInternAtom (xvar->display, "WM_DELETE_WINDOW", False); 41 | xvar->wm_protocols = XInternAtom (xvar->display, "WM_PROTOCOLS", False); 42 | mlx_int_deal_shm(xvar); 43 | if (xvar->private_cmap) 44 | xvar->cmap = XCreateColormap(xvar->display,xvar->root, 45 | xvar->visual,AllocNone); 46 | mlx_int_rgb_conversion(xvar); 47 | xvar->end_loop = 0; 48 | return (xvar); 49 | } 50 | 51 | 52 | /* 53 | ** pshm_format of -1 : Not XYBitmap|XYPixmap|ZPixmap 54 | ** alpha libX need a check of the DISPLAY env var, or shm is allowed 55 | ** in remote Xserver connections. 56 | */ 57 | 58 | int mlx_int_deal_shm(t_xvar *xvar) 59 | { 60 | int use_pshm; 61 | int bidon; 62 | char *dpy; 63 | char buff[33]; 64 | 65 | xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm)); 66 | if (xvar->use_xshm && use_pshm) 67 | xvar->pshm_format = XShmPixmapFormat(xvar->display); 68 | else 69 | xvar->pshm_format = -1; 70 | gethostname(buff,32); 71 | dpy = getenv(ENV_DISPLAY); 72 | if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) && 73 | strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) ) 74 | { 75 | xvar->pshm_format = -1; 76 | xvar->use_xshm = 0; 77 | } 78 | } 79 | 80 | /* 81 | ** TrueColor Visual is needed to have *_mask correctly set 82 | */ 83 | 84 | int mlx_int_rgb_conversion(t_xvar *xvar) 85 | { 86 | bzero(xvar->decrgb,sizeof(int)*6); 87 | while (!(xvar->visual->red_mask&1)) 88 | { xvar->visual->red_mask >>= 1; xvar->decrgb[0] ++; } 89 | while (xvar->visual->red_mask&1) 90 | { xvar->visual->red_mask >>= 1; xvar->decrgb[1] ++; } 91 | while (!(xvar->visual->green_mask&1)) 92 | { xvar->visual->green_mask >>= 1; xvar->decrgb[2] ++; } 93 | while (xvar->visual->green_mask&1) 94 | { xvar->visual->green_mask >>= 1; xvar->decrgb[3] ++; } 95 | while (!(xvar->visual->blue_mask&1)) 96 | { xvar->visual->blue_mask >>= 1; xvar->decrgb[4] ++; } 97 | while (xvar->visual->blue_mask&1) 98 | { xvar->visual->blue_mask >>= 1; xvar->decrgb[5] ++; } 99 | } 100 | -------------------------------------------------------------------------------- /mlx/mlx_int_param_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_param_event.c 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 Wed Oct 6 13:14:52 2004 Olivier Crouzet 9 | */ 10 | 11 | #include "mlx_int.h" 12 | 13 | int mlx_int_param_undef() 14 | { 15 | } 16 | 17 | int mlx_int_param_KeyPress(t_xvar *xvar, XEvent *ev, t_win_list *win) 18 | { 19 | win->hooks[KeyPress].hook(XkbKeycodeToKeysym(xvar->display, 20 | ev->xkey.keycode, 0, 0), 21 | win->hooks[KeyPress].param); 22 | } 23 | 24 | int mlx_int_param_KeyRelease(t_xvar *xvar, XEvent *ev, t_win_list *win) 25 | { 26 | win->hooks[KeyRelease].hook(XkbKeycodeToKeysym(xvar->display, 27 | ev->xkey.keycode, 0, 0), 28 | win->hooks[KeyRelease].param); 29 | } 30 | 31 | int mlx_int_param_ButtonPress(t_xvar *xvar, XEvent *ev, t_win_list *win) 32 | { 33 | win->hooks[ButtonPress].hook(ev->xbutton.button,ev->xbutton.x,ev->xbutton.y, 34 | win->hooks[ButtonPress].param); 35 | } 36 | 37 | int mlx_int_param_ButtonRelease(t_xvar *xvar, XEvent *ev, t_win_list *win) 38 | { 39 | win->hooks[ButtonRelease].hook(ev->xbutton.button, 40 | ev->xbutton.x, ev->xbutton.y, 41 | win->hooks[ButtonRelease].param); 42 | } 43 | 44 | int mlx_int_param_MotionNotify(t_xvar *xvar, XEvent *ev, t_win_list *win) 45 | { 46 | win->hooks[MotionNotify].hook(ev->xbutton.x,ev->xbutton.y, 47 | win->hooks[MotionNotify].param); 48 | } 49 | 50 | int mlx_int_param_Expose(t_xvar *xvar, XEvent *ev, t_win_list *win) 51 | { 52 | if (!ev->xexpose.count) 53 | win->hooks[Expose].hook(win->hooks[Expose].param); 54 | } 55 | 56 | 57 | int mlx_int_param_generic(t_xvar *xvar, XEvent *ev, t_win_list *win) 58 | { 59 | win->hooks[ev->type].hook(win->hooks[ev->type].param); 60 | } 61 | 62 | int (*(mlx_int_param_event[]))() = 63 | { 64 | mlx_int_param_undef, /* 0 */ 65 | mlx_int_param_undef, 66 | mlx_int_param_KeyPress, 67 | mlx_int_param_KeyRelease, /* 3 */ 68 | mlx_int_param_ButtonPress, 69 | mlx_int_param_ButtonRelease, 70 | mlx_int_param_MotionNotify, /* 6 */ 71 | mlx_int_param_generic, 72 | mlx_int_param_generic, 73 | mlx_int_param_generic, 74 | mlx_int_param_generic, 75 | mlx_int_param_generic, 76 | mlx_int_param_Expose, /* 12 */ 77 | mlx_int_param_generic, 78 | mlx_int_param_generic, 79 | mlx_int_param_generic, 80 | mlx_int_param_generic, 81 | mlx_int_param_generic, 82 | mlx_int_param_generic, 83 | mlx_int_param_generic, 84 | mlx_int_param_generic, 85 | mlx_int_param_generic, 86 | mlx_int_param_generic, 87 | mlx_int_param_generic, 88 | mlx_int_param_generic, 89 | mlx_int_param_generic, 90 | mlx_int_param_generic, 91 | mlx_int_param_generic, 92 | mlx_int_param_generic, 93 | mlx_int_param_generic, 94 | mlx_int_param_generic, 95 | mlx_int_param_generic, 96 | mlx_int_param_generic, 97 | mlx_int_param_generic, 98 | mlx_int_param_generic, 99 | mlx_int_param_generic 100 | }; 101 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: user42 +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/04/07 22:58:48 by mahautlat #+# #+# # 9 | # Updated: 2021/12/14 12:14:15 by esafar ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.c \ 14 | ./get_next_line/get_next_line.c \ 15 | ./get_next_line/get_next_line_utils.c \ 16 | ./libft/ft_strdup.c \ 17 | ./libft/ft_putchar_fd.c \ 18 | ./libft/ft_putstr_fd.c \ 19 | ./libft/ft_putnbr_fd.c \ 20 | ./libft/ft_strlen.c \ 21 | ./libft/ft_strjoin.c \ 22 | ./libft/ft_itoa.c \ 23 | ./srcs/check_errors.c \ 24 | ./srcs/check_map_elem.c \ 25 | ./srcs/exit.c \ 26 | ./srcs/clean_images.c \ 27 | ./srcs/ft_putpixel.c \ 28 | ./srcs/get_map.c \ 29 | ./srcs/move.c \ 30 | ./srcs/exec_moves.c \ 31 | ./srcs/exec_events.c \ 32 | ./srcs/draw_on_images.c \ 33 | ./srcs/draw_map.c \ 34 | ./srcs/draw_stats.c \ 35 | ./srcs/draw_dialogbox.c \ 36 | ./srcs/write_event.c \ 37 | ./srcs/draw_button.c \ 38 | ./srcs/draw_collectibles.c \ 39 | ./srcs/draw_furnitures.c \ 40 | ./srcs/draw_furnitures2.c \ 41 | ./srcs/draw_furnitures_cond.c \ 42 | ./srcs/draw_player.c \ 43 | ./srcs/draw_exit.c \ 44 | ./srcs/draw_trap.c \ 45 | ./srcs/get_images.c \ 46 | ./srcs/get_images2.c \ 47 | ./srcs/norme1.c \ 48 | ./srcs/norme2.c \ 49 | ./srcs/norme3.c \ 50 | ./srcs/norme4.c \ 51 | ./srcs/handle_event.c \ 52 | ./srcs/handle_keypress.c \ 53 | ./srcs/initialize.c \ 54 | ./srcs/initialize_functionnalities.c \ 55 | ./srcs/initialize_objects.c 56 | 57 | 58 | OBJS = ${SRCS:.c=.o} 59 | 60 | UNAME := $(shell uname) 61 | 62 | PATH_MLX = mlx 63 | CC = gcc 64 | CFLAGS = -g3 -Wall -Wextra -Werror -D BUFFER_SIZE=1 65 | RM = rm -f 66 | NAME = so_long 67 | FLAGS = -ldl -Imlx -Lmlx -lmlx -lm -lbsd -lXext -lX11 -Wl,-rpath=./bass/,-rpath=./mlx/,-rpath=./delay/ 68 | #FLAGS = -ldl -Imlx -Lmlx -lmlx -lm -lz -lXext -lX11 -Wl,-rpath=./bass/,-rpath=./mlx/,-rpath=./delay/ 69 | 70 | all: ${NAME} 71 | 72 | .c.o: 73 | ${CC} ${CFLAGS} -Imlx -Ibass -c $< -o ${<:.c=.o} 74 | 75 | $(NAME): $(OBJS) 76 | make -C $(PATH_MLX) 77 | ${CC} $(CFLAGS) -o $(NAME) $(OBJS) $(FLAGS) 78 | 79 | bonus: ${OBJS} ${OBJS_B} 80 | make -C $(PATH_MLX) 81 | ${CC} ${CFLAGS} -o ${NAME} ${OBJS} $(FLAGS) 82 | 83 | clean: 84 | make -C $(PATH_MLX) clean 85 | ${RM} ${OBJS} 86 | fclean: clean 87 | make -C $(PATH_MLX) clean 88 | ${RM} ${NAME} 89 | 90 | re: fclean all 91 | 92 | .PHONY: bonus all clean fclean re 93 | -------------------------------------------------------------------------------- /srcs/check_errors.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* check_errors.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/14 12:06:40 by esafar #+# #+# */ 9 | /* Updated: 2021/12/14 12:06:54 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | int ft_check_extension(char *map_name) 16 | { 17 | int i; 18 | int j; 19 | char *ext; 20 | 21 | ext = ".ber\0"; 22 | i = 0; 23 | while (map_name[i] && map_name[i] != '.') 24 | i++; 25 | j = 0; 26 | while (map_name[i + j] && ext[j] && map_name[i + j] == ext[j]) 27 | j++; 28 | if (j == 4 && map_name[i + j] == '\0' && ext[j] == '\0') 29 | return (1); 30 | return (-1); 31 | } 32 | 33 | int check_map_size(t_test *test) 34 | { 35 | if (test->param.width_with_x * 64 > 42 * 64) 36 | return (-1); 37 | if (test->param.height_with_wall * 64 > 23 * 64) 38 | return (-1); 39 | return (1); 40 | } 41 | 42 | void which_error_msg_to_print(t_test *test, int event) 43 | { 44 | if (event == 1) 45 | ft_putstr_fd("Error. Wrong map extension.\n", 2); 46 | else if (event == 2) 47 | ft_putstr_fd("Error. Map is not surrounded by walls.\n", 2); 48 | else if (event == 3) 49 | ft_putstr_fd("Error. Map is not rectangular.\n", 2); 50 | else if (event == 4) 51 | ft_putstr_fd("Error. Not enough collectibles.\n", 2); 52 | else if (event == 5) 53 | ft_putstr_fd("Error. There is no (or too much) exit(s).\n", 2); 54 | else if (event == 6) 55 | ft_putstr_fd("Error. There is no (or too much) player(s).\n", 2); 56 | else if (event == 7) 57 | ft_putstr_fd \ 58 | ("Error. Valid map can contain only [1][0][C][E][P][T].\n", 2); 59 | else if (event == 8) 60 | ft_putstr_fd("Error. Wrong map size.\n", 2); 61 | free_map(test); 62 | exit(-1); 63 | } 64 | 65 | int check_error(t_test *test, char **av) 66 | { 67 | if (ft_check_extension(av[1]) == -1) 68 | which_error_msg_to_print(test, 1); 69 | else if (map_surounded_by_walls(test, test->param.map) == -1) 70 | which_error_msg_to_print(test, 2); 71 | else if (map_is_rectangular(test) == -1) 72 | which_error_msg_to_print(test, 3); 73 | else if (min_one_collectible(test) == -1) 74 | which_error_msg_to_print(test, 4); 75 | else if (only_one(test, 'E') == -1) 76 | which_error_msg_to_print(test, 5); 77 | else if (only_one(test, 'P') == -1) 78 | which_error_msg_to_print(test, 6); 79 | else if (check_chars(test) == -1) 80 | which_error_msg_to_print(test, 7); 81 | else if (check_map_size(test) == -1) 82 | which_error_msg_to_print(test, 8); 83 | return (1); 84 | } 85 | -------------------------------------------------------------------------------- /libft/libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/05/21 11:43:47 by esafar #+# #+# */ 9 | /* Updated: 2021/09/20 11:31:05 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | 21 | typedef struct s_list 22 | { 23 | void *content; 24 | struct s_list *next; 25 | } t_list; 26 | 27 | int ft_atoi(const char *str); 28 | void ft_bzero(void *s, size_t n); 29 | int ft_isalnum(int c); 30 | int ft_isalpha(int c); 31 | int ft_isdigit(int c); 32 | int ft_isprint(int c); 33 | void *ft_memccpy(void *dest, const void *src, int c, size_t n); 34 | void *ft_memcpy(void *dest, const void *src, size_t n); 35 | void *ft_memset(void *s, int c, size_t n); 36 | char *ft_strchr(const char *s, int c); 37 | char *ft_strdup(char *src); 38 | size_t ft_strlen(char const *str); 39 | int ft_strncmp(const char *s1, const char *s2, size_t n); 40 | char *ft_strrchr(const char *s, int c); 41 | int ft_tolower(int c); 42 | int ft_toupper(int c); 43 | void *ft_memchr(const void *s, int c, size_t n); 44 | int ft_memcmp(const void *s1, const void *s2, size_t n); 45 | int ft_isascii(int c); 46 | void *ft_calloc(size_t nmemb, size_t size); 47 | char *ft_strnstr(const char *str, const char *to_find, size_t n); 48 | size_t ft_strlcat(char *dest, const char *src, size_t size); 49 | char *ft_itoa(int num); 50 | void ft_putchar_fd(char c, int fd); 51 | int ft_putstr_fd(char *s, int fd); 52 | void ft_putendl_fd(char *s, int fd); 53 | void ft_putnbr_fd(int n, int fd); 54 | char *ft_strjoin(char *s1, char *s2); 55 | void *ft_memmove(void *dest, const void *src, size_t n); 56 | size_t ft_strlcpy(char *dest, const char *src, size_t size); 57 | char *ft_substr(char const *s, unsigned int start, size_t len); 58 | char *ft_strtrim(char const *s1, char const *set); 59 | char **ft_split(char const *s, char c); 60 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 61 | 62 | int ft_lstsize(t_list *lst); 63 | void ft_lstadd_front(t_list **alst, t_list *new); 64 | t_list *ft_lstlast(t_list *lst); 65 | void ft_lstadd_back(t_list **alst, t_list *new); 66 | t_list *ft_lstnew(void *content); 67 | void ft_lstdelone(t_list *lst, void (*del)(void*)); 68 | void ft_lstclear(t_list **lst, void (*del)(void*)); 69 | void ft_lstiter(t_list *lst, void (*f)(void *)); 70 | t_list *ft_lstmap(t_list *lst, void *(*f)(void*), void (*del)(void*)); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /mlx/mlx_ext_randr.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "mlx_int.h" 5 | 6 | #include 7 | #include 8 | 9 | /* global for independant extension */ 10 | 11 | RRMode saved_mode = 0; 12 | 13 | 14 | int mlx_ext_fullscreen(t_xvar *xvar, t_win_list *win, int fullscreen) 15 | { 16 | XWindowAttributes watt; 17 | int i; 18 | int j; 19 | XRRScreenResources *res; 20 | XRROutputInfo *o_info; 21 | XRRCrtcInfo *crtc; 22 | RRMode mode_candidate; 23 | int idx_output; 24 | int idx_candidate; 25 | 26 | if (!XGetWindowAttributes(xvar->display, win->window, &watt)) 27 | return (0); 28 | 29 | res = XRRGetScreenResources(xvar->display, xvar->root); 30 | o_info = NULL; 31 | idx_output = -1; 32 | i = res->noutput; 33 | while (i--) 34 | { 35 | o_info = XRRGetOutputInfo(xvar->display, res, res->outputs[i]); 36 | if (o_info->connection == RR_Connected) 37 | { 38 | idx_output = i; 39 | i = 0; 40 | } 41 | else 42 | XRRFreeOutputInfo(o_info); 43 | } 44 | if (!o_info) 45 | { 46 | XRRFreeScreenResources(res); 47 | return (0); 48 | } 49 | 50 | idx_candidate = -1; 51 | i = o_info->nmode; 52 | while (i--) 53 | { 54 | j = res->nmode; 55 | while (j--) 56 | if (res->modes[j].id == o_info->modes[i]) 57 | if (res->modes[j].width >= watt.width && res->modes[j].height >= watt.height && 58 | (idx_candidate == -1 || res->modes[idx_candidate].width > res->modes[j].width || 59 | res->modes[idx_candidate].height > res->modes[j].height) ) 60 | idx_candidate = i; 61 | } 62 | if (idx_candidate < 0) 63 | { 64 | XRRFreeOutputInfo(o_info); 65 | XRRFreeScreenResources(res); 66 | return (0); 67 | } 68 | if (!fullscreen && saved_mode == -1) 69 | idx_candidate = 0; /* if no clue, uses first mode, usually part of npreferred */ 70 | mode_candidate = o_info->modes[idx_candidate]; 71 | if (!fullscreen) 72 | mode_candidate = saved_mode; 73 | 74 | crtc = XRRGetCrtcInfo(xvar->display, res, o_info->crtc); 75 | saved_mode = crtc->mode; 76 | 77 | i = XRRSetCrtcConfig(xvar->display, res, o_info->crtc, CurrentTime, 0, 0, mode_candidate, 78 | crtc->rotation, &res->outputs[idx_output], 1); 79 | if (fullscreen) 80 | printf("found mode : %d x %d\n Status %d\n", res->modes[idx_candidate].width, res->modes[idx_candidate].height, i); 81 | else 82 | printf("back previous mode\n"); 83 | 84 | XMoveWindow(xvar->display, win->window, 0, 0); 85 | XMapRaised(xvar->display, win->window); 86 | 87 | if (fullscreen) 88 | { 89 | // XGrabPointer(xvar->display, win->window, True, 0, GrabModeAsync, GrabModeAsync, win->window, 0L, CurrentTime); 90 | XGrabKeyboard(xvar->display, win->window, False, GrabModeAsync, GrabModeAsync, CurrentTime); 91 | } 92 | else 93 | { 94 | XUngrabPointer(xvar->display, CurrentTime); 95 | XUngrabKeyboard(xvar->display, CurrentTime); 96 | } 97 | 98 | XSync(xvar->display, False); 99 | sleep(1); 100 | 101 | XRRFreeCrtcInfo(crtc); 102 | XRRFreeOutputInfo(o_info); 103 | XRRFreeScreenResources(res); 104 | } 105 | -------------------------------------------------------------------------------- /srcs/draw_furnitures_cond.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_furnitures_cond.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/08 16:50:04 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:49:01 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | int isvpcte(t_test *test, int i, int j) 16 | { 17 | if (test->param.map[i][j] == '0') 18 | return (1); 19 | else if (test->param.map[i][j] == 'P') 20 | return (1); 21 | else if (test->param.map[i][j] == 'C') 22 | return (1); 23 | else if (test->param.map[i][j] == 'T') 24 | return (1); 25 | else if (test->param.map[i][j] == 'E') 26 | return (1); 27 | return (0); 28 | } 29 | 30 | int cond1(t_test *test) 31 | { 32 | if (test->param.map[test->iter.i][test->iter.j] == '1' && ((isvpcte(test, test->iter.i, test->iter.j - 1) == 1) || (test->param.map[test->iter.i][test->iter.j - 1] == '1' && test->iter.j - 1 == 0)) && (isvpcte(test, test->iter.i, test->iter.j + 1) == 1 || (test->param.map[test->iter.i][test->iter.j + 1] == '1' && test->iter.j + 1 == test->param.width - 1)) && test->iter.i == 1) 33 | return (1); 34 | return (0); 35 | } 36 | 37 | int cond2(t_test *test) 38 | { 39 | if (test->param.map[test->iter.i][test->iter.j] == '1' && test->param.map[test->iter.i][test->iter.j + 1] == '1' && test->iter.j + 1 != test->param.width - 1 && (isvpcte(test, test->iter.i, test->iter.j - 1) == 1 || (test->param.map[test->iter.i][test->iter.j - 1] == '1' && test->iter.j - 1 == 0)) && (isvpcte(test, test->iter.i, test->iter.j + 2) == 1 || (test->param.map[test->iter.i][test->iter.j + 2] == '1' && test->iter.j + 2 == test->param.width - 1))) 40 | return (1); 41 | return (0); 42 | } 43 | 44 | int cond3(t_test *test) 45 | { 46 | if (test->param.map[test->iter.i][test->iter.j] == '1' && test->param.map[test->iter.i][test->iter.j + 1] == '1' && test->param.map[test->iter.i][test->iter.j + 2] == '1' && test->iter.j + 1 != test->param.width - 1 && (isvpcte(test, test->iter.i, test->iter.j - 1) == 1 || (test->param.map[test->iter.i][test->iter.j - 1] == '1' && test->iter.j - 1 == 0)) && (isvpcte(test, test->iter.i, test->iter.j + 3) == 1 || (test->param.map[test->iter.i][test->iter.j + 3] == '1' && test->iter.j + 3 == test->param.width - 1))) 47 | return (1); 48 | return (0); 49 | } 50 | 51 | int cond4(t_test *test) 52 | { 53 | if (test->iter.i == 1 && test->iter.j != test->param.width - 4 && test->param.map[test->iter.i][test->iter.j] == '1' && test->param.map[test->iter.i][test->iter.j + 1] == '1' && test->param.map[test->iter.i][test->iter.j + 2] == '1' && test->param.map[test->iter.i][test->iter.j + 3] == '1') 54 | return (1); 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /mlx/mlx_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int.h for mlx in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 16:45:48 2000 Charlie Root 8 | ** Last update Wed May 25 16:44:16 2011 Olivier Crouzet 9 | */ 10 | 11 | 12 | 13 | /* 14 | ** Internal settings for MiniLibX 15 | */ 16 | 17 | #ifndef MLX_INT_H 18 | 19 | # define MLX_INT_H 20 | 21 | # include 22 | # include 23 | # include 24 | # include 25 | # include 26 | # include 27 | # include 28 | # include 29 | # include 30 | # include 31 | # include 32 | # include 33 | /* #include */ 34 | 35 | 36 | # define MLX_TYPE_SHM_PIXMAP 3 37 | # define MLX_TYPE_SHM 2 38 | # define MLX_TYPE_XIMAGE 1 39 | 40 | # define MLX_MAX_EVENT LASTEvent 41 | 42 | 43 | # define ENV_DISPLAY "DISPLAY" 44 | # define LOCALHOST "localhost" 45 | # define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n" 46 | # define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n" 47 | 48 | 49 | typedef struct s_xpm_col 50 | { 51 | int name; 52 | int col; 53 | } t_xpm_col; 54 | 55 | 56 | struct s_col_name 57 | { 58 | char *name; 59 | int color; 60 | }; 61 | 62 | typedef struct s_event_list 63 | { 64 | int mask; 65 | int (*hook)(); 66 | void *param; 67 | } t_event_list; 68 | 69 | 70 | typedef struct s_win_list 71 | { 72 | Window window; 73 | GC gc; 74 | struct s_win_list *next; 75 | int (*mouse_hook)(); 76 | int (*key_hook)(); 77 | int (*expose_hook)(); 78 | void *mouse_param; 79 | void *key_param; 80 | void *expose_param; 81 | t_event_list hooks[MLX_MAX_EVENT]; 82 | } t_win_list; 83 | 84 | 85 | typedef struct s_img 86 | { 87 | XImage *image; 88 | Pixmap pix; 89 | GC gc; 90 | int size_line; 91 | int bpp; 92 | int width; 93 | int height; 94 | int type; 95 | int format; 96 | char *data; 97 | XShmSegmentInfo shm; 98 | } t_img; 99 | 100 | typedef struct s_xvar 101 | { 102 | Display *display; 103 | Window root; 104 | int screen; 105 | int depth; 106 | Visual *visual; 107 | Colormap cmap; 108 | int private_cmap; 109 | t_win_list *win_list; 110 | int (*loop_hook)(); 111 | void *loop_param; 112 | int use_xshm; 113 | int pshm_format; 114 | int do_flush; 115 | int decrgb[6]; 116 | Atom wm_delete_window; 117 | Atom wm_protocols; 118 | int end_loop; 119 | } t_xvar; 120 | 121 | 122 | int mlx_int_do_nothing(); 123 | int mlx_get_color_value(); 124 | int mlx_int_get_good_color(); 125 | int mlx_int_find_in_pcm(); 126 | int mlx_int_anti_resize_win(); 127 | int mlx_int_wait_first_expose(); 128 | int mlx_int_rgb_conversion(); 129 | int mlx_int_deal_shm(); 130 | void *mlx_int_new_xshm_image(); 131 | char **mlx_int_str_to_wordtab(); 132 | void *mlx_new_image(); 133 | int shm_att_pb(); 134 | int mlx_int_get_visual(t_xvar *xvar); 135 | int mlx_int_set_win_event_mask(t_xvar *xvar); 136 | int mlx_int_str_str_cote(char *str,char *find,int len); 137 | int mlx_int_str_str(char *str,char *find,int len); 138 | 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /mlx/configure: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -e 4 | 5 | BOLD="\033[1m" 6 | RESET="\033[0m" 7 | LIGHT_RED="\033[91m" 8 | LIGHT_GREEN="\033[92m" 9 | LIGHT_CYAN="\033[96m" 10 | 11 | logging(){ 12 | local type=$1; shift 13 | printf "${LIGHT_CYAN}${BOLD}configure${RESET} [%b] : %b\n" "$type" "$*" 14 | } 15 | log_info(){ 16 | logging "${LIGHT_GREEN}info${RESET}" "$@" 17 | } 18 | log_error(){ 19 | logging "${LIGHT_RED}error${RESET}" "$@" >&2 20 | } 21 | 22 | # find and print x11 header path 23 | get_xlib_include_path(){ 24 | local result="" 25 | 26 | for inc in \ 27 | /usr/X11/include \ 28 | /usr/X11R6/include \ 29 | /usr/X11R5/include \ 30 | /usr/X11R4/include \ 31 | \ 32 | /usr/include \ 33 | /usr/include/X11 \ 34 | /usr/include/X11R6 \ 35 | /usr/include/X11R5 \ 36 | /usr/include/X11R4 \ 37 | \ 38 | /usr/local/X11/include \ 39 | /usr/local/X11R6/include \ 40 | /usr/local/X11R5/include \ 41 | /usr/local/X11R4/include \ 42 | \ 43 | /usr/local/include/X11 \ 44 | /usr/local/include/X11R6 \ 45 | /usr/local/include/X11R5 \ 46 | /usr/local/include/X11R4 \ 47 | \ 48 | /usr/X386/include \ 49 | /usr/x386/include \ 50 | /usr/XFree86/include/X11 \ 51 | \ 52 | /usr/local/include \ 53 | /usr/athena/include \ 54 | /usr/local/x11r5/include \ 55 | /usr/lpp/Xamples/include \ 56 | \ 57 | /usr/openwin/include \ 58 | /usr/openwin/share/include 59 | do 60 | if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then 61 | result=$inc 62 | break 63 | fi 64 | done 65 | echo $result 66 | } 67 | 68 | show_help(){ 69 | cat < Makefile.gen 115 | cat Makefile.mk | grep -v %%%% >> Makefile.gen 116 | log_info 'Generate "test/makefile.gen" from template "test/makefile.mk"' 117 | echo "INC=$xlib_inc" > test/Makefile.gen 118 | cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen 119 | 120 | log_info 'Execute "make all" from file "makefile.gen"' 121 | ${MAKE} -f Makefile.gen all 122 | log_info 'Execute "make all" from file "test/makefile.gen"' 123 | (cd test ; ${MAKE} -f Makefile.gen all ) 124 | } 125 | 126 | main "$@" 127 | -------------------------------------------------------------------------------- /srcs/draw_furnitures.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_furnitures.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 20:07:14 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:47:14 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void draw_flames(t_test *test, int x, int y) 16 | { 17 | draw_on_image(test, test->all.fire.frame, x, y); 18 | } 19 | 20 | void check_which_fire_frame(t_test *test) 21 | { 22 | if (test->frame < 8) 23 | test->all.fire.frame = &test->all.fire.frame_one; 24 | else if (test->frame < 16 && test->frame >= 8) 25 | test->all.fire.frame = &test->all.fire.frame_three; 26 | else if (test->frame < 24 && test->frame >= 16) 27 | test->all.fire.frame = &test->all.fire.frame_five; 28 | else if (test->frame >= 24) 29 | test->all.fire.frame = &test->all.fire.frame_seven; 30 | } 31 | 32 | int draw_chimney(t_test *test, int random_obj, int x, int y) 33 | { 34 | if (random_obj == 0) 35 | { 36 | draw_on_image(test, &test->all.chimney.bottom_left, x, y - 32 - 16 + 8); 37 | draw_on_image(test, &test->all.chimney.bottom_right, x + 64, y - 32 - 16 + 8); 38 | draw_on_image(test, &test->all.chimney.mid_left, x, y - 32 - 16 - 64 + 8); 39 | draw_on_image(test, &test->all.chimney.mid_right, x + 64, y - 32 - 16 - 64 + 8); 40 | draw_on_image(test, &test->all.chimney.top_left, x, y - 32 - 16 - 128 + 8); 41 | draw_on_image(test, &test->all.chimney.top_right, x + 64, y - 32 - 16 - 128 + 8); 42 | check_which_fire_frame(test); 43 | draw_flames(test, x + 16, y - 51); 44 | random_obj = 1; 45 | } 46 | else if (random_obj == 1) 47 | draw_dresser(test, x, y); 48 | return (random_obj); 49 | } 50 | 51 | void check_which_furnitures(t_test *test) 52 | { 53 | if (test->param.map[test->iter.i][test->iter.j] == '1' && test->iter.i != 1) 54 | draw_on_image(test, &test->all.box, test->iter.x, test->iter.y); 55 | else if (cond1(test) == 1) 56 | draw_pot(test, test->all.random_obj, test->iter.x, test->iter.y); 57 | else if (cond2(test) == 1) 58 | test->all.random_obj = draw_chimney(test, test->all.random_obj, test->iter.x, test->iter.y); 59 | else if (cond3(test) == 1) 60 | test->all.ispiano = draw_piano(test, test->all.ispiano, test->iter.x, test->iter.y); 61 | else if (cond4(test) == 1) 62 | four_pot_line(test, test->iter.x, test->iter.y); 63 | } 64 | 65 | void draw_furnitures(t_test *test) 66 | { 67 | test->iter.i = 0; 68 | while (test->param.map[++test->iter.i + 1]) 69 | { 70 | test->iter.j = 0; 71 | while (test->param.map[test->iter.i][++test->iter.j + 1]) 72 | { 73 | test->iter.x = (64 + (test->param.height - 2 - test->iter.i) * 64 + (test->iter.j - 1) * 64); 74 | test->iter.y = (192 + (test->iter.i - 1) * 64); 75 | check_which_furnitures(test); 76 | } 77 | } 78 | test->all.babo = 0; 79 | test->all.ispiano = 0; 80 | test->all.random_obj = 0; 81 | } 82 | -------------------------------------------------------------------------------- /srcs/check_map_elem.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* check_map_elem.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/14 12:12:05 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:52:45 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | int map_surounded_by_walls(t_test *test, char **map) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (map[0][i] != '\0' && map[0][i] == '1') 21 | i++; 22 | if (i != test->param.width) 23 | return (-1); 24 | i = 0; 25 | while (map[test->param.height - 1][i] != '\0' && \ 26 | map[test->param.height - 1][i] == '1') 27 | i++; 28 | if (i != test->param.width) 29 | return (-1); 30 | i = 0; 31 | while (i < test->param.height && map[i][0] != '\0' && map[i][0] == '1') 32 | i++; 33 | if (i != test->param.height) 34 | return (-1); 35 | i = 0; 36 | while (i < test->param.height && map[i][test->param.width - 1] != '\0' && map[i][test->param.width - 1] == '1') 37 | i++; 38 | if (i != test->param.height) 39 | return (-1); 40 | return (1); 41 | } 42 | 43 | int min_one_collectible(t_test *test) 44 | { 45 | int i; 46 | int j; 47 | int coll; 48 | 49 | i = 0; 50 | coll = 0; 51 | while (test->param.map[i]) 52 | { 53 | j = 0; 54 | while (test->param.map[i][j]) 55 | { 56 | if (test->param.map[i][j] == 'C') 57 | coll++; 58 | j++; 59 | } 60 | i++; 61 | } 62 | if (coll == 0) 63 | return (-1); 64 | return (1); 65 | } 66 | 67 | int only_one(t_test *test, char to_check) 68 | { 69 | int i; 70 | int j; 71 | int one; 72 | 73 | i = 0; 74 | one = 0; 75 | while (test->param.map[i]) 76 | { 77 | j = 0; 78 | while (test->param.map[i][j]) 79 | { 80 | if (test->param.map[i][j] == to_check) 81 | one++; 82 | if (one > 1) 83 | return (-1); 84 | j++; 85 | } 86 | i++; 87 | } 88 | if (one == 0) 89 | return (-1); 90 | return (1); 91 | } 92 | 93 | int map_is_rectangular(t_test *test) 94 | { 95 | int i; 96 | size_t tmp; 97 | 98 | i = 1; 99 | tmp = ft_strlen(test->param.map[0]); 100 | while (test->param.map[i]) 101 | { 102 | if (ft_strlen(test->param.map[i]) != tmp) 103 | return (-1); 104 | i++; 105 | } 106 | return (1); 107 | } 108 | 109 | int check_chars(t_test *test) 110 | { 111 | int i; 112 | int j; 113 | int count; 114 | 115 | i = 0; 116 | count = 0; 117 | while (test->param.map[i]) 118 | { 119 | j = 0; 120 | while (test->param.map[i][j]) 121 | { 122 | if (test->param.map[i][j] == '1' || test->param.map[i][j] == '0' || test->param.map[i][j] == 'E' || test->param.map[i][j] == 'C' || test->param.map[i][j] == 'P' || test->param.map[i][j] == 'T') 123 | count++; 124 | j++; 125 | } 126 | i++; 127 | } 128 | if (count == test->param.width * test->param.height) 129 | return (1); 130 | return (-1); 131 | } 132 | -------------------------------------------------------------------------------- /get_next_line/get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/06/06 09:04:02 by esafar #+# #+# */ 9 | /* Updated: 2021/11/17 20:12:43 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | 15 | int fml(char *str) 16 | { 17 | free(str); 18 | return (-1); 19 | } 20 | 21 | char *after_newline(char *save) 22 | { 23 | size_t i; 24 | size_t j; 25 | char *after_newline; 26 | 27 | i = 0; 28 | while (save[i] != '\0' && save[i] != '\n') 29 | i++; 30 | if (save[i] == '\0') 31 | { 32 | free(save); 33 | return (NULL); 34 | } 35 | after_newline = (char *)malloc(sizeof(char) * (ft_strlen(save) - i + 1)); 36 | if (!after_newline) 37 | return (NULL); 38 | i++; 39 | j = 0; 40 | while (save[i] != '\0') 41 | after_newline[j++] = save[i++]; 42 | after_newline[j] = '\0'; 43 | free(save); 44 | save = NULL; 45 | return (after_newline); 46 | } 47 | 48 | char *get_line(char *save) 49 | { 50 | size_t i; 51 | char *line; 52 | 53 | i = 0; 54 | while (save[i] != '\0' && save[i] != '\n') 55 | i++; 56 | line = (char *)malloc(sizeof(char) * (i + 1)); 57 | i = 0; 58 | while (save[i] != '\0' && save[i] != '\n') 59 | { 60 | line[i] = save[i]; 61 | i++; 62 | } 63 | line[i] = '\0'; 64 | return (line); 65 | } 66 | 67 | int end_gnl(char *save, int key, int ret) 68 | { 69 | if (key == 1) 70 | free(save); 71 | if (ret == 0) 72 | return (0); 73 | return (1); 74 | } 75 | 76 | int get_next_line(int fd, char **line, int key) 77 | { 78 | int ret; 79 | char *buff; 80 | static char *save; 81 | 82 | if (fd < 0 || BUFFER_SIZE < 0 || !line || read(fd, "", 0) == -1) 83 | return (-1); 84 | if (!save) 85 | save = ft_strdup(""); 86 | buff = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1)); 87 | ret = 1; 88 | while (ft_isnewline(save) == 0 && ret != 0) 89 | { 90 | ret = read(fd, buff, BUFFER_SIZE); 91 | if (ret == -1) 92 | return (fml(buff)); 93 | buff[ret] = '\0'; 94 | save = ft_strjoin(save, buff); 95 | } 96 | free(buff); 97 | *line = get_line(save); 98 | save = after_newline(save); 99 | if (end_gnl(save, key, ret) == 0) 100 | return (0); 101 | return (1); 102 | } 103 | 104 | /* 105 | #include 106 | #include 107 | #include 108 | #include 109 | 110 | int main() 111 | { 112 | int fd1; 113 | int fd2; 114 | char *line; 115 | 116 | fd1 = open("test1", O_RDONLY); 117 | fd2 = open("test2", O_RDONLY); 118 | get_next_line(fd1, &line); 119 | printf("line : %s\n", line); 120 | free(line); 121 | get_next_line(fd2, &line); 122 | printf("line : %s\n", line); 123 | free(line); 124 | get_next_line(fd1, &line); 125 | printf("line : %s\n", line); 126 | free(line); 127 | get_next_line(fd2, &line); 128 | printf("line : %s\n", line); 129 | free(line); 130 | return (0); 131 | } 132 | 133 | */ 134 | -------------------------------------------------------------------------------- /srcs/draw_player.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* draw_player.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/12/07 19:21:10 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:44:51 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../so_long.h" 14 | 15 | void get_pos_player(t_test *test) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = 0; 21 | while (test->param.map[i]) 22 | { 23 | j = 0; 24 | while (test->param.map[i][j]) 25 | { 26 | if (test->param.map[i][j] == 'P') 27 | { 28 | test->player.pos_i = i; 29 | test->player.pos_j = j; 30 | test->player.pos_x = (j - 1) * 64 + 30 + (test->param.height - 3) * 64 - (i - 1) * 64; 31 | test->player.pos_y = 3 * 64 + (i - 1) * 64 - 64 - 25 + 10; 32 | } 33 | else if (test->param.map[i][j] == 'C' && test->param.rendered == 0) 34 | test->collec.amount++; 35 | j++; 36 | } 37 | i++; 38 | } 39 | } 40 | 41 | void choose_which_damage_side(t_test *test) 42 | { 43 | if (test->param.map[test->player.pos_i + 1][test->player.pos_j] == 'T') 44 | test->player.side = &test->player.dmg_front; 45 | else if (test->param.map[test->player.pos_i - 1][test->player.pos_j] 46 | == 'T') 47 | test->player.side = &test->player.dmg_back; 48 | else if (test->param.map[test->player.pos_i][test->player.pos_j - 1] 49 | == 'T') 50 | test->player.side = &test->player.dmg_left; 51 | else if (test->param.map[test->player.pos_i][test->player.pos_j + 1] 52 | == 'T') 53 | test->player.side = &test->player.dmg_right; 54 | } 55 | 56 | void choose_which_normal_side(t_test *test) 57 | { 58 | if (test->param.map[test->player.pos_i + 1][test->player.pos_j] == 'T') 59 | test->player.side = &test->player.frontside; 60 | else if (test->param.map[test->player.pos_i - 1][test->player.pos_j] 61 | == 'T') 62 | test->player.side = &test->player.backside; 63 | else if (test->param.map[test->player.pos_i][test->player.pos_j - 1] 64 | == 'T') 65 | test->player.side = &test->player.leftside; 66 | else if (test->param.map[test->player.pos_i][test->player.pos_j + 1] 67 | == 'T') 68 | test->player.side = &test->player.rightside; 69 | } 70 | 71 | void choose_player_image(t_test *test) 72 | { 73 | if (test->frame < 17) 74 | choose_which_damage_side(test); 75 | else if (test->frame >= 17) 76 | choose_which_normal_side(test); 77 | } 78 | 79 | void draw_player(t_test *test) 80 | { 81 | get_pos_player(test); 82 | if (test->player.hurt == 1) 83 | { 84 | test->player.lock_pos = 1; 85 | choose_player_image(test); 86 | if (test->frame == 31) 87 | test->loop++; 88 | if (test->loop == 4) 89 | { 90 | test->player.hurt = 0; 91 | test->loop = 0; 92 | test->player.lock_pos = 0; 93 | test->player.side = &test->player.frontside; 94 | } 95 | draw_on_image_bis(test, test->player.side, test->player.pos_x, test->player.pos_y); 96 | } 97 | else if (test->player.hurt == 0) 98 | draw_on_image_bis(test, test->player.side, test->player.pos_x, test->player.pos_y); 99 | } 100 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: esafar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2021/11/23 16:32:28 by esafar #+# #+# */ 9 | /* Updated: 2022/12/14 14:39:00 by esafar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "so_long.h" 14 | 15 | void make_intro(t_test *test) 16 | { 17 | if (test->intro_or_not == 1) 18 | draw_on_image_intro(test, &test->intro.one, 0, 0); 19 | else if (test->intro_or_not == 2) 20 | draw_on_image_intro(test, &test->intro.two, 0, 0); 21 | else if (test->intro_or_not == 3) 22 | draw_on_image_intro(test, &test->intro.three, 0, 0); 23 | else if (test->intro_or_not == 4) 24 | draw_on_image_intro(test, &test->intro.four, 0, 0); 25 | else if (test->intro_or_not == 5) 26 | draw_on_image_intro(test, &test->intro.five, 0, 0); 27 | mlx_put_image_to_window(test->mlx, test->win, test->data.img, 0, 0); 28 | } 29 | 30 | void draw_all_together(t_test *test) 31 | { 32 | draw_background(test); 33 | draw_walls(test); 34 | draw_floors(test); 35 | draw_trap(test); 36 | draw_exit(test); 37 | draw_furnitures(test); 38 | draw_collectibles(test); 39 | if (test->param.rendered == 0) 40 | test->player.side = &test->player.frontside; 41 | draw_player(test); 42 | mlx_put_image_to_window(test->mlx, test->win, test->data.img, 0, 0); 43 | draw_score(test); 44 | draw_button(test); 45 | test->param.rendered = 1; 46 | if (test->dialog_box.keep == 1) 47 | draw_dialog_box(test); 48 | draw_life(test); 49 | } 50 | 51 | int render(t_test *test) 52 | { 53 | if ((test->intro_or_not == 1 || test->intro_or_not == 2 || test->intro_or_not == 3 || test->intro_or_not == 4 || test->intro_or_not == 5) && test->param.width_with_x * 64 - (2 * 64) == 960 && (test->param.height - 2) * 64 + 3 * 64 == 448) 54 | make_intro(test); 55 | else if ((test->param.rendered == 0 || test->param.rendered == 1) && test->stats.lives != 0) 56 | { 57 | draw_all_together(test); 58 | test->intro_or_not = 0; 59 | } 60 | test->frame++; 61 | if (test->frame % 40 / 32 == 1) 62 | test->frame = 0; 63 | return (0); 64 | } 65 | 66 | void get_all_images_and_addresses(t_test *test) 67 | { 68 | get_event(test); 69 | get_piano(test); 70 | get_chimney_and_dresser(test); 71 | get_fire(test); 72 | get_collec(test); 73 | get_remain(test); 74 | get_player(test); 75 | get_stats(test); 76 | get_exit(test); 77 | } 78 | 79 | int main(int ac, char **av) 80 | { 81 | t_test test; 82 | 83 | get_map(&test, ac, av); 84 | check_error(&test, av); 85 | print_map(&test); 86 | 87 | test.mlx = mlx_init(); 88 | test.win = mlx_new_window(test.mlx, test.param.width_with_x * 64 - (2 * 64), (test.param.height - 2) * 64 + 3 * 64, "so_short on time!"); 89 | test.data.img = mlx_new_image(test.mlx, test.param.width_with_x * 64 - (2 * 64), (test.param.height - 2) * 64 + 3 * 64); 90 | test.data.addr = mlx_get_data_addr(test.data.img, &test.data.bits_per_pixel, &test.data.line_length, &test.data.endian); 91 | get_all_images_and_addresses(&test); 92 | 93 | mlx_hook(test.win, 2, 1L << 0, &handle_keypress, &test); 94 | mlx_loop_hook(test.mlx, render, &test); 95 | mlx_hook(test.win, 17, 1L << 0, &close_win_cross, &test); 96 | mlx_loop(test.mlx); 97 | 98 | return (0); 99 | } 100 | -------------------------------------------------------------------------------- /mlx/man/man1/mlx_loop.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Handle events 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I int 8 | .fi 9 | .B mlx_loop 10 | ( 11 | .I void *mlx_ptr 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_key_hook 18 | ( 19 | .I void *win_ptr, int (*funct_ptr)(), void *param 20 | ); 21 | 22 | .nf 23 | .I int 24 | .fi 25 | .B mlx_mouse_hook 26 | ( 27 | .I void *win_ptr, int (*funct_ptr)(), void *param 28 | ); 29 | 30 | .nf 31 | .I int 32 | .fi 33 | .B mlx_expose_hook 34 | ( 35 | .I void *win_ptr, int (*funct_ptr)(), void *param 36 | ); 37 | 38 | .nf 39 | .I int 40 | .fi 41 | .B mlx_loop_hook 42 | ( 43 | .I void *mlx_ptr, int (*funct_ptr)(), void *param 44 | ); 45 | 46 | .SH X-WINDOW EVENTS 47 | 48 | The X-Window system is bi-directionnal. On one hand, the program sends orders to 49 | the screen to display pixels, images, and so on. On the other hand, 50 | it can get information from the keyboard and mouse associated to 51 | the screen. To do so, the program receives "events" from the keyboard or the 52 | mouse. 53 | 54 | .SH DESCRIPTION 55 | 56 | To receive events, you must use 57 | .B mlx_loop 58 | (). This function never returns. It is an infinite loop that waits for 59 | an event, and then calls a user-defined function associated with this event. 60 | A single parameter is needed, the connection identifier 61 | .I mlx_ptr 62 | (see the 63 | .B mlx manual). 64 | 65 | You can assign different functions to the three following events: 66 | .br 67 | - A key is pressed 68 | .br 69 | - The mouse button is pressed 70 | .br 71 | - A part of the window should be re-drawn 72 | (this is called an "expose" event, and it is your program's job to handle it). 73 | .br 74 | 75 | Each window can define a different function for the same event. 76 | 77 | The three functions 78 | .B mlx_key_hook 79 | (), 80 | .B mlx_mouse_hook 81 | () and 82 | .B mlx_expose_hook 83 | () work exactly the same way. 84 | .I funct_ptr 85 | is a pointer to the function you want to be called 86 | when an event occurs. This assignment is specific to the window defined by the 87 | .I win_ptr 88 | identifier. The 89 | .I param 90 | adress will be passed to the function everytime it is called, and should be 91 | used to store the parameters it might need. 92 | 93 | The syntax for the 94 | .B mlx_loop_hook 95 | () function is identical to the previous ones, but the given function will be 96 | called when no event occurs. 97 | 98 | When it catches an event, the MiniLibX calls the corresponding function 99 | with fixed parameters: 100 | .nf 101 | 102 | expose_hook(void *param); 103 | key_hook(int keycode,void *param); 104 | mouse_hook(int button,int x,int y,void *param); 105 | loop_hook(void *param); 106 | 107 | .fi 108 | These function names are arbitrary. They here are used to distinguish 109 | parameters according to the event. These functions are NOT part of the 110 | MiniLibX. 111 | 112 | .I param 113 | is the address specified in the mlx_*_hook calls. This address is never 114 | used nor modified by the MiniLibX. On key and mouse events, additional 115 | information is passed: 116 | .I keycode 117 | tells you which key is pressed (look for the X11 include file "keysymdef.h"), 118 | ( 119 | .I x 120 | , 121 | .I y 122 | ) are the coordinates of the mouse click in the window, and 123 | .I button 124 | tells you which mouse button was pressed. 125 | 126 | .SH GOING FURTHER WITH EVENTS 127 | The MiniLibX provides a much generic access to all X-Window events. The 128 | .I mlx.h 129 | include define 130 | .B mlx_hook() 131 | in the same manner mlx_*_hook functions work. The event and mask values 132 | will be taken from the X11 include file "X.h". 133 | 134 | See source code of mlx_int_param_event.c to find out how the MiniLibX will 135 | call your own function for a specific event. 136 | 137 | .SH SEE ALSO 138 | mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3) 139 | 140 | .SH AUTHOR 141 | Copyright ol@ - 2002-2014 - Olivier Crouzet 142 | --------------------------------------------------------------------------------