diff --git a/MLX42/.gitattributes b/MLX42/.gitattributes new file mode 100644 index 0000000..ccbbc0d --- /dev/null +++ b/MLX42/.gitattributes @@ -0,0 +1,8 @@ +# See https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings + +# Set the default behavior, in case people don't have core.autocrlf set +* text=auto + +# Declare files that will always have a certain EOL +*.sh text eol=lf +shaders/** text eol=lf diff --git a/MLX42/.gitignore b/MLX42/.gitignore new file mode 100644 index 0000000..9af1634 --- /dev/null +++ b/MLX42/.gitignore @@ -0,0 +1,65 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# Misc +main.c +temp/ +.vscode/ +lib/glfw/ +.DS_Store + +# Special shader files +mlx_*_shader.c +build/ +main.c +test \ No newline at end of file diff --git a/Makefile b/Makefile index f003526..bf0c21c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SRCS_GAME := main.c game/game.c game/init.c game/manage.c \ +SRCS_GAME := main.c game/game.c game/init.c \ game/manage_keys.c game/raycasting.c game/dda.c game/draw.c game/utils.c SRCS_MAP := parsing.c parsing_header.c parsing_header2.c parsing_meta.c parsing_body.c map.c parsing_body2.c parsing_header3.c SRCS_MAP := $(addprefix map/, $(SRCS_MAP)) diff --git a/game/game.c b/game/game.c index e488adf..34fc845 100644 --- a/game/game.c +++ b/game/game.c @@ -6,13 +6,13 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */ -/* Updated: 2023/05/19 17:49:02 by erey-bet ### ########.fr */ +/* Updated: 2023/06/13 14:19:08 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "game.h" -int destroy(t_game *game) +static int destroy(t_game *game) { if (game->textures[0]) { @@ -35,6 +35,18 @@ int destroy(t_game *game) return (1); } +#include + +static void hook(void *param) +{ + t_game *game; + + game = param; + //printf("%d\n", mlx_is_key_down(game->mlx, MLX_KEY_ESCAPE)); + if (manage_keys(game)) + raycasting(game); +} + int start_game(t_map map) { t_game game; @@ -53,7 +65,7 @@ int start_game(t_map map) return (destroy(&game)); } raycasting(&game); - mlx_key_hook(game.mlx, manage, &game); + mlx_loop_hook(game.mlx, &hook, &game); mlx_loop(game.mlx); destroy(&game); return (0); diff --git a/game/game.h b/game/game.h index e44a1eb..67d5cdb 100644 --- a/game/game.h +++ b/game/game.h @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/26 15:29:34 by erey-bet #+# #+# */ -/* Updated: 2023/05/11 15:28:26 by erey-bet ### ########.fr */ +/* Updated: 2023/06/13 14:19:18 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,11 +79,8 @@ typedef struct s_game /* INIT */ int init(t_map map, t_game *game); -/* MANAGE */ -void manage(mlx_key_data_t keydata, void *param); - /* KEYS */ -int manage_keys(mlx_key_data_t keydata, t_game *game); +int manage_keys(t_game *game); /* RAYCASTING */ int raycasting(t_game *game); diff --git a/game/init.c b/game/init.c index 1512815..3f267f1 100644 --- a/game/init.c +++ b/game/init.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */ -/* Updated: 2023/06/01 13:28:15 by erey-bet ### ########.fr */ +/* Updated: 2023/06/13 13:13:00 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,7 +57,7 @@ int init(t_map map, t_game *game) { if (init_textures(map, game->textures)) return (2); - game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true); + game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", false); if (!game->mlx) return (1); game->map = map; diff --git a/game/manage.c b/game/manage.c deleted file mode 100644 index 21c4bed..0000000 --- a/game/manage.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* manage.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: erey-bet +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/04/27 12:52:14 by erey-bet #+# #+# */ -/* Updated: 2023/05/03 14:53:14 by erey-bet ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "game.h" - -void manage(mlx_key_data_t keydata, void *param) -{ - t_game *game; - - game = param; - if (manage_keys(keydata, game)) - raycasting(game); -} diff --git a/game/manage_keys.c b/game/manage_keys.c index 8dc44ca..9ad817e 100644 --- a/game/manage_keys.c +++ b/game/manage_keys.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/27 14:14:51 by erey-bet #+# #+# */ -/* Updated: 2023/05/05 15:00:40 by erey-bet ### ########.fr */ +/* Updated: 2023/06/13 13:28:58 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,42 +39,36 @@ void movement(t_ply *ply, double x, double y) ply->pos_y += y; } -int manage_movement(t_game *game, int key) +int manage_movement(t_game *game) { t_ply *ply; - - ply = &game->ply; - if (key == MLX_KEY_W) - movement(ply, (ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED)); - else if (key == MLX_KEY_S) - movement(ply, -(ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED)); - else if (key == MLX_KEY_D) - movement(ply, (ply->pla_x * MOVESPEED), (ply->pla_y * MOVESPEED)); - else if (key == MLX_KEY_A) - movement(ply, -(ply->pla_x * MOVESPEED), -(ply->pla_y * MOVESPEED)); - else if (key == MLX_KEY_L) - rotate(ply, true); - else if (key == MLX_KEY_J) - rotate(ply, false); - return (1); -} - -int manage_keys(mlx_key_data_t keys, t_game *game) -{ int is_moving; - is_moving = 0; - if (keys.key == MLX_KEY_Q) + ply = &game->ply; + is_moving = 1; + if (mlx_is_key_down(game->mlx, MLX_KEY_W)) + movement(ply, (ply->dir_x * MOVESPEED), (ply->dir_y * MOVESPEED)); + else if (mlx_is_key_down(game->mlx, MLX_KEY_S)) + movement(ply, -(ply->dir_x * MOVESPEED), -(ply->dir_y * MOVESPEED)); + else if (mlx_is_key_down(game->mlx, MLX_KEY_D)) + movement(ply, (ply->pla_x * MOVESPEED), (ply->pla_y * MOVESPEED)); + else if (mlx_is_key_down(game->mlx, MLX_KEY_A)) + movement(ply, -(ply->pla_x * MOVESPEED), -(ply->pla_y * MOVESPEED)); + else if (mlx_is_key_down(game->mlx, MLX_KEY_RIGHT)) + rotate(ply, true); + else if (mlx_is_key_down(game->mlx, MLX_KEY_LEFT)) + rotate(ply, false); + else + is_moving = 0; + return (is_moving); +} + +int manage_keys(t_game *game) +{ + + if (mlx_is_key_down(game->mlx, MLX_KEY_ESCAPE)) mlx_close_window(game->mlx); - else if (keys.key == MLX_KEY_W - || keys.key == MLX_KEY_S - || keys.key == MLX_KEY_D - || keys.key == MLX_KEY_A - || keys.key == MLX_KEY_ESCAPE - || keys.key == MLX_KEY_L - || keys.key == MLX_KEY_J) - is_moving = manage_movement(game, keys.key); - if (is_moving) + if (manage_movement(game)) return (1); return (0); }