This commit is contained in:
Etienne Rey-bethbeder 2023-06-13 14:19:45 +02:00
parent fe699a3cb4
commit 4bd265e213
8 changed files with 119 additions and 65 deletions

8
MLX42/.gitattributes vendored Normal file
View File

@ -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

65
MLX42/.gitignore vendored Normal file
View File

@ -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

View File

@ -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 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 := 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)) SRCS_MAP := $(addprefix map/, $(SRCS_MAP))

View File

@ -6,13 +6,13 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 12:59:53 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" #include "game.h"
int destroy(t_game *game) static int destroy(t_game *game)
{ {
if (game->textures[0]) if (game->textures[0])
{ {
@ -35,6 +35,18 @@ int destroy(t_game *game)
return (1); return (1);
} }
#include <stdio.h>
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) int start_game(t_map map)
{ {
t_game game; t_game game;
@ -53,7 +65,7 @@ int start_game(t_map map)
return (destroy(&game)); return (destroy(&game));
} }
raycasting(&game); raycasting(&game);
mlx_key_hook(game.mlx, manage, &game); mlx_loop_hook(game.mlx, &hook, &game);
mlx_loop(game.mlx); mlx_loop(game.mlx);
destroy(&game); destroy(&game);
return (0); return (0);

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 15:29:34 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 */ /* INIT */
int init(t_map map, t_game *game); int init(t_map map, t_game *game);
/* MANAGE */
void manage(mlx_key_data_t keydata, void *param);
/* KEYS */ /* KEYS */
int manage_keys(mlx_key_data_t keydata, t_game *game); int manage_keys(t_game *game);
/* RAYCASTING */ /* RAYCASTING */
int raycasting(t_game *game); int raycasting(t_game *game);

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/27 14:50:22 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)) if (init_textures(map, game->textures))
return (2); return (2);
game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true); game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", false);
if (!game->mlx) if (!game->mlx)
return (1); return (1);
game->map = map; game->map = map;

View File

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* manage.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/27 14:14:51 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; ply->pos_y += y;
} }
int manage_movement(t_game *game, int key) int manage_movement(t_game *game)
{ {
t_ply *ply; 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; int is_moving;
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; is_moving = 0;
if (keys.key == MLX_KEY_Q) return (is_moving);
}
int manage_keys(t_game *game)
{
if (mlx_is_key_down(game->mlx, MLX_KEY_ESCAPE))
mlx_close_window(game->mlx); mlx_close_window(game->mlx);
else if (keys.key == MLX_KEY_W if (manage_movement(game))
|| 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)
return (1); return (1);
return (0); return (0);
} }