diff --git a/.gitignore b/.gitignore index b9b324b..3324dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,3 @@ libft/**/*.o libft/**/*.a src/main.c vgcore.* -Makefile -src/cub3d.c diff --git a/Makefile b/Makefile index 5676f07..b6a727a 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,7 @@ MACRO_DIR = MacroLibX/ INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) -I $(MACRO_DIR)/$(I_DIR) -SRCS = src/utils/mess_error.c \ - src/utils/parse_utils.c \ - src/parsing/check_map.c \ - src/parsing/check_arg.c \ - src/parsing/principal_pars.c \ - src/cub3d.c +SRCS = $(shell find src -name *.c) OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o)) diff --git a/includes/game.h b/includes/game.h index 8d6fc5b..1aefb1e 100644 --- a/includes/game.h +++ b/includes/game.h @@ -6,27 +6,33 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/11 16:38:40 by adjoly #+# #+# */ -/* Updated: 2024/09/12 17:04:59 by adjoly ### ########.fr */ +/* Updated: 2024/09/16 13:36:04 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef GAME_H # define GAME_H +# include "parsing.h" +# include + typedef struct s_cub { void *mlx; void *win; void *images; char **map; + t_coord p_coord; } t_cub; -#define ESCAPE_KEY 41 -#define W_KEY 26 -#define S_KEY 22 -#define A_KEY 4 -#define D_KEY 7 -#define WHITE 0xFFFFFFFF +# define ESCAPE_KEY 41 +# define W_KEY 26 +# define S_KEY 22 +# define A_KEY 4 +# define D_KEY 7 +# define WHITE 0xFFFFFFFF +# define WINDOW_Y 900 +# define WINDOW_X 1600 /** * @brief This function is used to handle keypress @@ -36,6 +42,14 @@ typedef struct s_cub * * @return Minilibx go brrrr(useless always 0) */ -int key_hook(int key, void *mlx); +int key_hook(int key, void *param); + +/** + * @brief This function is used to create an image with the player position + * + * @param cub The address of a t_cub struct filled with mlx data and other thing + * + */ +void *get_player_image(t_cub *cub, uint8_t key_pressed); #endif diff --git a/src/cub3d.c b/src/cub3d.c new file mode 100644 index 0000000..452b687 --- /dev/null +++ b/src/cub3d.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cub3d.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */ +/* Updated: 2024/09/16 18:39:38 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" +#include "game.h" +#include "mlx.h" + +int main(int ac, char **av) +{ + t_cub cub; + + (void)ac; + (void)av; + cub.mlx = mlx_init(); + cub.win = mlx_new_window(cub.mlx, 400, 400, "WTF"); + cub.p_coord.x = 100; + cub.p_coord.y = 100; + + mlx_put_image_to_window(cub.mlx, cub.win, get_player_image(&cub, 0), 0, 0); + + mlx_on_event(cub.mlx, cub.win, MLX_KEYDOWN, key_hook, &cub); + + mlx_loop(cub.mlx); + + mlx_destroy_window(cub.mlx, cub.win); + mlx_destroy_display(cub.mlx); + return (0); +} diff --git a/src/parsing/principal_pars.c b/src/parsing/principal_pars.c index 52a38eb..4359e9f 100644 --- a/src/parsing/principal_pars.c +++ b/src/parsing/principal_pars.c @@ -6,29 +6,29 @@ /* By: madumerg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */ -/* Updated: 2024/09/12 16:49:20 by madumerg ### ########.fr */ +/* Updated: 2024/09/13 10:43:50 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" -int check_info(char **l) -{ - -} +//int check_info(char **l) +//{ +// +//} -int verif_info_map(char *av) -{ - char **map; - char **f_part; - - map = parse_map(av); - f_part = info_map(map); - if (check_info(f_part) == 1) - return (1); - if (verif_all_map(map) == 1) - return (1); -} +//int verif_info_map(char *av) +//{ +// char **map; +// char **f_part; +// +// map = parse_map(av); +// f_part = info_map(map); +// if (check_info(f_part) == 1) +// return (1); +// if (verif_all_map(map) == 1) +// return (1); +//} int verif_all_map(char **map) { diff --git a/src/event_handler.c b/src/raycasting/event_handler.c similarity index 62% rename from src/event_handler.c rename to src/raycasting/event_handler.c index 5bb53a7..78533c1 100644 --- a/src/event_handler.c +++ b/src/raycasting/event_handler.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/11 16:37:56 by adjoly #+# #+# */ -/* Updated: 2024/09/12 14:40:22 by adjoly ### ########.fr */ +/* Updated: 2024/09/16 18:47:09 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,37 @@ #include "mlx.h" #include "game.h" -int key_hook(int key, t_cub *cub) +int key_hook(int key, void *param) { - (void)mlx; + t_cub *cub; + + cub = (t_cub *)param; + (void)cub; if (key == ESCAPE_KEY) mlx_loop_end(cub->mlx); if (key == W_KEY) + { printf("UP\n"); + mlx_clear_window(cub->mlx, cub->win); + mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0); + } if (key == S_KEY) + { printf("DOWN\n"); + mlx_clear_window(cub->mlx, cub->win); + mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0); + } if (key == D_KEY) + { printf("RIGHT\n"); + mlx_clear_window(cub->mlx, cub->win); + mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0); + } if (key == A_KEY) + { printf("LEFT\n"); + mlx_clear_window(cub->mlx, cub->win); + mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0); + } return (0); } diff --git a/src/raycasting/player_print.c b/src/raycasting/player_print.c new file mode 100644 index 0000000..bcbe6e6 --- /dev/null +++ b/src/raycasting/player_print.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* player_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/13 11:05:02 by adjoly #+# #+# */ +/* Updated: 2024/09/16 18:49:37 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "game.h" +#include +#include "mlx.h" + +void *get_player_image(t_cub *cub, uint8_t key_pressed) +{ + void *img; + + img = mlx_new_image(cub->mlx, WINDOW_X, WINDOW_Y); + + if (key_pressed == W_KEY) + cub->p_coord.y--; + else if (key_pressed == S_KEY) + cub->p_coord.y++; + else if (key_pressed == D_KEY) + cub->p_coord.x++; + else if (key_pressed == A_KEY) + cub->p_coord.x--; + mlx_set_image_pixel(cub->mlx, img, cub->p_coord.x, cub->p_coord.y, WHITE); + return (img); +}