diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | inc/cub3d.h | 18 | ||||
| -rw-r--r-- | src/ft_drawsquare.c | 22 | ||||
| -rw-r--r-- | src/ft_exit.c | 12 | ||||
| -rw-r--r-- | src/ft_init_lists.c | 16 | ||||
| -rw-r--r-- | src/ft_key_events.c | 17 | ||||
| -rw-r--r-- | src/ft_parse_map.c | 2 | ||||
| -rw-r--r-- | src/main.c | 12 | 
8 files changed, 69 insertions, 32 deletions
| @@ -19,6 +19,8 @@ INCS		= cub3d.h  SRCS_NAME	= main.c  SRCS_NAME	+= ft_init_lists.c  SRCS_NAME	+= ft_key_events.c +SRCS_NAME	+= ft_exit.c +SRCS_NAME	+= ft_drawsquare.c  # SRCS_NAME	+= ft_parse_map.c  #------------------------------------------------------------------------------#  SRCS		= $(addprefix ${SRCS_DIR},${SRCS_NAME}) diff --git a/inc/cub3d.h b/inc/cub3d.h index ca12f8a..fa6a08f 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -1,22 +1,26 @@  #ifndef CUB3D_H  #define CUB3D_H -typedef struct	s_winlist +#include <inttypes.h> + +typedef struct	s_win  {  	void		*wlx;  	void		*winptr;  	int			x_size;  	int			y_size; -}				t_winlist; +}				t_win; -typedef struct	s_cublist +typedef struct	s_cub  {  	char		coolcub; -}				t_cublist; +}				t_cub; -t_cublist		*ft_init_cublist(void); -t_winlist		*ft_init_winlist(void); -void			ft_parse_map(t_cublist *clist); +t_cub			*ft_init_cub(void); +t_win			*ft_init_win(void); +void			ft_parse_map(t_cub *clist);  int				ft_key_event(int keycode, void *param); +void			ft_exit(uint8_t exit_code); +void			ft_drawsquare(t_win *wlist, int a, int b);  #endif diff --git a/src/ft_drawsquare.c b/src/ft_drawsquare.c new file mode 100644 index 0000000..d720f44 --- /dev/null +++ b/src/ft_drawsquare.c @@ -0,0 +1,22 @@ +#include <mlx.h> +#include <cub3d.h> + +void +ft_drawsquare(t_win *wlist, int a, int b) +{ +	int	x; +	int	y; + +	x = a; +	y = b; +	while (x > a - 40) +	{ +		while (y > b - 40) +		{ +			mlx_pixel_put(wlist->wlx, wlist->winptr, x, y, 255); +			y--; +		} +		y = b; +		x--; +	} +} diff --git a/src/ft_exit.c b/src/ft_exit.c new file mode 100644 index 0000000..a5b7276 --- /dev/null +++ b/src/ft_exit.c @@ -0,0 +1,12 @@ +#include <libft.h> +#include <stdlib.h> +#include <inttypes.h> + +void +ft_exit(uint8_t exit_code) +{ +	ft_printf("Exiting program\n"); +	if (exit_code < 0 || exit_code > 0) +		ft_printf("Exit code: %hhu\n", exit_code); +	exit(exit_code); +} diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index b6f2932..7a6eb79 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -3,12 +3,12 @@  #include <cub3d.h>  #include <stdlib.h> -t_winlist -*ft_init_winlist(void) +t_win +*ft_init_win(void)  { -	t_winlist	*wlist; +	t_win	*wlist; -	wlist = (t_winlist*)malloc(sizeof(t_winlist)); +	wlist = (t_win*)malloc(sizeof(t_win));  	wlist->x_size = 800;  	wlist->y_size = 600;  	wlist->wlx = mlx_init(); @@ -18,11 +18,11 @@ t_winlist  	return (wlist);  } -t_cublist -*ft_init_cublist(void) +t_cub +*ft_init_cub(void)  { -	t_cublist	*clist; +	t_cub	*clist; -	clist = (t_cublist*)malloc(sizeof(t_cublist)); +	clist = (t_cub*)malloc(sizeof(t_cub));  	return (clist);  } diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 82235fc..6702988 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -5,28 +5,28 @@  static int  ft_w_key(void)  { -	ft_printf("w\n"); +	ft_printf("[W]\n");  	return (0);  }  static int  ft_a_key(void)  { -	ft_printf("a\n"); +	ft_printf("[A]\n");  	return (0);  }  static int  ft_s_key(void)  { -	ft_printf("s\n"); +	ft_printf("[S]\n");  	return (0);  }  static int  ft_d_key(void)  { -	ft_printf("d\n"); +	ft_printf("[D]\n");  	return (0);  } @@ -44,11 +44,10 @@ ft_key_event(int keycode, void *param)  	(keycode <= 3) ? ((*fun_ptr[keycode])()) : 0;  	if (keycode == 53)  	{ -		ft_memdel(((t_winlist*)param)->wlx); -		ft_memdel(((t_winlist*)param)->winptr); -		ft_memdel((t_winlist*)param); -		ft_printf("Exiting program\n"); -		exit(0); +		ft_memdel(((t_win*)param)->wlx); +		ft_memdel(((t_win*)param)->winptr); +		ft_memdel((t_win*)param); +		ft_exit(0);  	}  	return (0);  } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index b600849..baf3b5f 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -3,6 +3,6 @@  #include <stdlib.h>  void -ft_parse_map(t_cublist *clist) +ft_parse_map(t_cub *clist)  {  } @@ -6,16 +6,14 @@  int  	main(void)  { -	t_winlist	*wlist; -	t_cublist	*clist; +	t_win	*wlist; +	t_cub	*clist; -	wlist = ft_init_winlist(); -	clist = ft_init_cublist(); +	wlist = ft_init_win(); +	clist = ft_init_cub();  	mlx_key_hook(wlist->winptr, ft_key_event, wlist); +	ft_drawsquare(wlist, 80, 80);  	mlx_loop(wlist->wlx); -	ft_memdel(wlist->wlx); -	ft_memdel(wlist->winptr); -	ft_memdel(wlist);  	ft_memdel(clist);  	return (0);  } | 
