1
0

🏗️」 wip: DDA setup finished and loop started

This commit is contained in:
2024-10-07 11:25:31 +02:00
parent e11c60b808
commit c7fd02590a
14 changed files with 258 additions and 56 deletions

18
includes/game/constant.h Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* constant.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 16:39:48 by adjoly #+# #+# */
/* Updated: 2024/10/04 16:40:10 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CONSTANT_H
# define CONSTANT_H
# define WHITE 0xFFFFFFFF
#endif

26
includes/game/dda.h Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dda.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 14:04:10 by adjoly #+# #+# */
/* Updated: 2024/10/06 18:48:38 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DDA_H
# define DDA_H
# include "typedef.h"
/**
* @brief Function used to get all the ray angle
*
* @param player The address of the t_player struct
* @param dda The address of the t_dda struct
*/
void get_ray_angle(t_player *player, t_dda (*dda)[800]);
#endif

View File

@ -6,55 +6,24 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 16:38:40 by adjoly #+# #+# */
/* Updated: 2024/09/29 16:47:32 by adjoly ### ########.fr */
/* Updated: 2024/10/06 18:48:33 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GAME_H
# define GAME_H
# include "dda.h"
# include "settings.h"
# include "parsing.h"
# include "typedef.h"
# include <stdint.h>
# include <stdlib.h>
# include <math.h>
# include <stdbool.h>
# include <unistd.h>
# 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
# define PLAYER_ROT_SPEED (2 * M_PI) / 8
# define PLAYER_SPEED 3
# define MAP_CHUNK_SIZE 64
# define RAY_SIZE 2
# define FOV 60 * (M_PI / 180)
typedef struct s_ray_dir
{
float x;
float y;
} t_ray_dir;
typedef struct s_player
{
t_coord coords;
double direction;
t_ray_dir ray_dir[WINDOW_X / RAY_SIZE];
} t_player;
typedef struct s_cub
{
void *mlx;
void *win;
void *sprites;
void *img;
char **map;
t_player player;
} t_cub;
/**
* @brief This function is used to handle keypress
@ -105,4 +74,5 @@ void draw_square(t_cub *cub, t_coord coord, uint16_t size, int color);
* @param cub The address of the t_cub struct
*/
void print_map(t_cub *cub);
#endif

32
includes/game/settings.h Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* settings.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 14:06:39 by adjoly #+# #+# */
/* Updated: 2024/10/04 16:38:10 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SETTINGS_H
# define SETTINGS_H
// Key code
# 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
# define PLAYER_ROT_SPEED (2 * M_PI) / 8
# define PLAYER_SPEED 3
# define MAP_CHUNK_SIZE 64
# define RAY_SIZE 2
# define FOV 60 * (M_PI / 180)
#endif

64
includes/game/typedef.h Normal file
View File

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* typedef.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 14:28:24 by adjoly #+# #+# */
/* Updated: 2024/10/06 19:03:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STRUCT_H
# define STRUCT_H
# include "parsing.h"
# include <stdbool.h>
typedef struct s_coord_f
{
float x;
float y;
} t_coord_f;
typedef struct s_step
{
char x;
char y;
} t_step;
typedef struct s_player
{
t_coord coords;
double direction;
} t_player;
typedef struct s_cub
{
void *mlx;
void *win;
void *sprites;
void *img;
char **map;
t_player player;
} t_cub;
typedef enum s_wall_side
{
HORIZONTAL,
VERTICAL
} t_wall_side;
typedef struct s_dda
{
t_coord_f ray_dir;
t_coord_f side_dist;
t_coord_f delta_dist;
t_step step;
t_wall_side wall_side;
bool wall_hit;
} t_dda;
#endif