mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2025-12-15 13:46:57 +01:00
manquecorrigetouchesetparsing
This commit is contained in:
parent
05f1323377
commit
6d8196504c
7
versionmod/.vscode/settings.json
vendored
7
versionmod/.vscode/settings.json
vendored
@ -4,7 +4,7 @@
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
@ -55,5 +55,8 @@
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||
"files.associations": {
|
||||
"math.h": "c"
|
||||
}
|
||||
}
|
||||
BIN
versionmod/cub3d
BIN
versionmod/cub3d
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/16 16:50:38 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 21:40:53 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
# define P2 PI/2
|
||||
# define P3 3*PI/2
|
||||
# define COLBUF 2
|
||||
# define NUMRAY 1280
|
||||
# define NUMRAY 10
|
||||
# define FOVIEW 60
|
||||
# define DISRAY 1000000
|
||||
# define DOF 120
|
||||
@ -39,6 +39,7 @@
|
||||
# define HEIGHT 720
|
||||
# define BOV 500
|
||||
# define MAX_LINE_LENGTH 100000
|
||||
|
||||
typedef enum {
|
||||
NORTH,
|
||||
SOUTH,
|
||||
@ -59,17 +60,29 @@ typedef struct s_img
|
||||
int endian;
|
||||
} t_img;
|
||||
|
||||
typedef struct s_struture_windows
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
int height;
|
||||
int width;
|
||||
} t_structure_windows;
|
||||
|
||||
typedef struct s_struture_map
|
||||
{
|
||||
char *map;
|
||||
char *buff;
|
||||
char **temp_list;
|
||||
int i;
|
||||
int j;
|
||||
int temp;
|
||||
int mapX;
|
||||
int mapY;
|
||||
int mapS;
|
||||
char *map;
|
||||
char *buff;
|
||||
char **temp_list;
|
||||
int i;
|
||||
int j;
|
||||
int temp;
|
||||
int mapX;
|
||||
int mapY;
|
||||
int mapS;
|
||||
float player_x;
|
||||
float player_y;
|
||||
char player_direction;
|
||||
t_structure_windows wd;
|
||||
} t_structure_map;
|
||||
|
||||
typedef struct s_struture_player
|
||||
@ -108,14 +121,6 @@ typedef struct s_struture_img
|
||||
int texture_height;
|
||||
} t_structure_img;
|
||||
|
||||
typedef struct s_struture_windows
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
int height;
|
||||
int width;
|
||||
} t_structure_windows;
|
||||
|
||||
typedef struct s_texture
|
||||
{
|
||||
char *north;
|
||||
@ -125,6 +130,17 @@ typedef struct s_texture
|
||||
unsigned int floor_color;
|
||||
unsigned int ceil_color;
|
||||
} t_texture;
|
||||
|
||||
typedef struct s_map_params {
|
||||
t_structure_map *map_info;
|
||||
const char *buffer;
|
||||
int length;
|
||||
int *maxWidth;
|
||||
int *height;
|
||||
int *currentWidth;
|
||||
int *isNewLine;
|
||||
} t_map_params;
|
||||
|
||||
typedef struct s_structure_main
|
||||
{
|
||||
int fd;
|
||||
@ -173,17 +189,6 @@ typedef struct s_position_params {
|
||||
char direction;
|
||||
} t_position_params;
|
||||
|
||||
|
||||
typedef struct s_map_params {
|
||||
t_structure_map *map_info;
|
||||
const char *buffer;
|
||||
int length;
|
||||
int *maxWidth;
|
||||
int *height;
|
||||
int *currentWidth;
|
||||
int *isNewLine;
|
||||
} t_map_params;
|
||||
|
||||
typedef struct s_square_params {
|
||||
t_structure_main *w;
|
||||
int x;
|
||||
@ -339,7 +344,7 @@ char **ft_split(char const *s, char c);
|
||||
char *get_next_line(int fd);
|
||||
/*ft_key.c 3/5*/
|
||||
int *kill_prog(t_structure_main *w);
|
||||
void move(int key, t_structure_main *w);
|
||||
void move(t_structure_main *w, int key);
|
||||
int deal_key(int key, t_structure_main *w);
|
||||
size_t ft_strlen(const char *s);
|
||||
char *ft_strdup(const char *src);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:47:17 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 21:17:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -31,6 +31,7 @@ void init_base_params(t_base_params *params, t_structure_main *w)
|
||||
params->FOV = FOVIEW * (PI / 180);
|
||||
params->DR = params->FOV / params->numrays;
|
||||
params->ra = w->s_player.pa - (params->FOV / 2);
|
||||
//printf("initbaseparams: %d , %f\n", params->tilesize, params->ra);
|
||||
draw_background(w);
|
||||
}
|
||||
|
||||
@ -62,27 +63,37 @@ void calculate_ray(t_base_params *base, t_ray_state *state,
|
||||
rayparams->color = calc->color;
|
||||
}
|
||||
|
||||
void drawrays2d(t_structure_main *w)
|
||||
{
|
||||
t_drawrays2d_params params;
|
||||
void drawrays2d(t_structure_main *w) {
|
||||
t_drawrays2d_params params;
|
||||
|
||||
init_base_params(¶ms.base_params, w);
|
||||
params.ray_calc.w = w;
|
||||
params.ray_calc.r = 0;
|
||||
while (params.ray_calc.r++ < params.base_params.numrays)
|
||||
{
|
||||
params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI);
|
||||
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disH, ¶ms.ray_state.hx,
|
||||
¶ms.ray_state.hy, ¶ms.ray_state.hwalldir};
|
||||
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disV, ¶ms.ray_state.vx,
|
||||
¶ms.ray_state.vy, ¶ms.ray_state.vwalldir};
|
||||
calculatehorizontalray(¶ms.hrayparams);
|
||||
calculateverticalray(¶ms.vrayparams);
|
||||
calculate_ray(¶ms.base_params, ¶ms.ray_state,
|
||||
¶ms.ray_calc, ¶ms.rayparams);
|
||||
drawray(¶ms.rayparams);
|
||||
params.base_params.ra += params.base_params.DR;
|
||||
}
|
||||
init_base_params(¶ms.base_params, w);
|
||||
params.ray_calc.w = w;
|
||||
params.ray_calc.r = 0;
|
||||
while (params.ray_calc.r++ < params.base_params.numrays) {
|
||||
params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI);
|
||||
|
||||
// Ajout de logs pour les paramètres du rayon
|
||||
printf("drawrays2d BEFORE: Ray #%d, Angle (ra) = %f\n", params.ray_calc.r, params.base_params.ra);
|
||||
|
||||
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disH, ¶ms.ray_state.hx,
|
||||
¶ms.ray_state.hy, ¶ms.ray_state.hwalldir};
|
||||
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||
¶ms.ray_state.disV, ¶ms.ray_state.vx,
|
||||
¶ms.ray_state.vy, ¶ms.ray_state.vwalldir};
|
||||
calculatehorizontalray(¶ms.hrayparams);
|
||||
calculateverticalray(¶ms.vrayparams);
|
||||
calculate_ray(¶ms.base_params, ¶ms.ray_state,
|
||||
¶ms.ray_calc, ¶ms.rayparams);
|
||||
printf("drawrays2d AFTER : Ray #%d, ra: %f\n", params.ray_calc.r, params.base_params.ra);
|
||||
|
||||
//Plus de logs après les calculs des rayons
|
||||
//printf("drawrays2d: Ray #%d, Player Position: x = %f, y = %f, Angle (ra) = %f\n",
|
||||
// params.ray_calc.r, w->s_player.px, w->s_player.py, params.base_params.ra);
|
||||
//printf("Horizontal Ray: Distance = %f, x = %f, y = %f\n", params.ray_state.disH, params.ray_state.hx, params.ray_state.hy);
|
||||
//printf("Vertical Ray: Distance = %f, x = %f, y = %f\n", params.ray_state.disV, params.ray_state.vx, params.ray_state.vy);
|
||||
|
||||
drawray(¶ms.rayparams);
|
||||
params.base_params.ra += params.base_params.DR;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/14 17:19:42 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 19:55:50 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,6 +20,8 @@ void init_line_params(t_line_params *lineparams, t_ray_params *rayParams)
|
||||
lineparams->x1 = (int)rayParams->rx;
|
||||
lineparams->y1 = (int)rayParams->ry;
|
||||
lineparams->color = rayParams->color;
|
||||
//printf("init_line_params: Player Position: x0 = %d, y0 = %d\n", lineparams->x0, lineparams->y0);
|
||||
//printf("init_line_params: Ray End Position: x1 = %d, y1 = %d\n", lineparams->x1, lineparams->y1);
|
||||
}
|
||||
|
||||
void init_texture_params(t_texture_params *textureparams,
|
||||
@ -54,6 +56,10 @@ void drawray(t_ray_params *rayparams)
|
||||
textureparams.startX = rayparams->r * rayparams->raywidth
|
||||
+ rayparams->backgroundOffsetX;
|
||||
textureparams.endX = textureparams.startX + rayparams->raywidth;
|
||||
//printf("drawray: Player Position: x = %f, y = %f\n", rayparams->w->s_player.px, rayparams->w->s_player.py);
|
||||
//printf("drawray: Ray Angle: pa = %f\n", rayparams->w->s_player.pa);
|
||||
//printf("drawray: Ray Distance: disT = %f\n", rayparams->disT);
|
||||
//printf("drawray: Ray Height: lineH = %f\n", rayparams->lineH);
|
||||
init_line_params(&lineparams, rayparams);
|
||||
draw_line(&lineparams);
|
||||
init_texture_params(&textureparams, rayparams);
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/14 17:37:52 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 13:23:24 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -32,16 +32,21 @@ void draw_background(t_structure_main *w)
|
||||
t_sky_ground_params ground_params;
|
||||
|
||||
backgroundoffsetx = BOV;
|
||||
if (!w || !w->t)
|
||||
{
|
||||
fprintf(stderr, "Structure w or w->t not properly initialized.\n");
|
||||
exit_error(w);
|
||||
}
|
||||
sky_params.w = w;
|
||||
sky_params.startHeight = 0;
|
||||
sky_params.endHeight = w->s_win.height / 2;
|
||||
sky_params.color = 0xB2FFFF;
|
||||
sky_params.color = w->t->ceil_color;
|
||||
sky_params.backgroundOffsetX = backgroundoffsetx;
|
||||
draw_sky_ground(&sky_params);
|
||||
ground_params.w = w;
|
||||
ground_params.startHeight = w->s_win.height / 2;
|
||||
ground_params.endHeight = w->s_win.height;
|
||||
ground_params.color = 0x280000;
|
||||
ground_params.color = w->t->floor_color;
|
||||
ground_params.backgroundOffsetX = backgroundoffsetx;
|
||||
draw_sky_ground(&ground_params);
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:45:36 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 14:06:26 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,8 +16,7 @@ void load_texture(t_structure_main *w, char *file_path, void **texture_ptr)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
//w->s_win.mlx = mlx_init();
|
||||
printf("file path %s\n", file_path);
|
||||
|
||||
width = 0;
|
||||
height = 0;
|
||||
*texture_ptr = mlx_xpm_file_to_image(w->s_win.mlx,
|
||||
@ -29,24 +28,26 @@ void load_texture(t_structure_main *w, char *file_path, void **texture_ptr)
|
||||
}
|
||||
w->s_img.texture_width = width;
|
||||
w->s_img.texture_height = height;
|
||||
printf("height %d\n", height);
|
||||
printf("width %d\n", width);
|
||||
printf("Loaded texture from %s: width = %d, height = %d\n", file_path, width, height);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void load_wall_textures(t_structure_main *w)
|
||||
{
|
||||
printf("load wall texture %s\n", w->t->north);
|
||||
printf("load wall texture %s\n", w->t->south);
|
||||
printf("load wall texture %s\n", w->t->east);
|
||||
printf("load wall texture %s\n", w->t->west);
|
||||
if (!w || !w->t)
|
||||
{
|
||||
fprintf(stderr, "Structures not properly initialized.\n");
|
||||
exit_error(w);
|
||||
}
|
||||
if (!w->t->north || !w->t->south || !w->t->west || !w->t->east)
|
||||
{
|
||||
fprintf(stderr, "One or more texture paths are not set.\n");
|
||||
exit_error(w);
|
||||
}
|
||||
load_texture(w, w->t->north, (void **)&w->s_img.north_texture);
|
||||
load_texture(w, w->t->south, (void **)&w->s_img.south_texture);
|
||||
load_texture(w, w->t->west, (void **)&w->s_img.west_texture);
|
||||
load_texture(w, w->t->east, (void **)&w->s_img.east_texture);
|
||||
printf("load wall texture %s\n", w->t->north);
|
||||
printf("load wall texture %s\n", w->t->south);
|
||||
printf("load wall texture %s\n", w->t->east);
|
||||
printf("load wall texture %s\n", w->t->west);
|
||||
}
|
||||
|
||||
void exit_error(t_structure_main *w)
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:38:40 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 13:27:19 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -36,7 +36,6 @@ void draw_texture_line(t_texture_params *params, float y, int textureY)
|
||||
put_pixel_img(params->w, x, y, color);
|
||||
x++;
|
||||
}
|
||||
printf("draw_texture_line: texturex = %d, textureY = %d, color = %d\n", texturex, textureY, color);
|
||||
}
|
||||
|
||||
void draw_texture(t_texture_params *params)
|
||||
@ -56,32 +55,30 @@ void draw_texture(t_texture_params *params)
|
||||
texturey = textureheight - 1;
|
||||
draw_texture_line(params, y, texturey);
|
||||
y++;
|
||||
}printf("draw_texture: y = %f, texturey = %d\n", y, texturey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
||||
{
|
||||
void *texture = NULL;
|
||||
if (wallDir == NORTH)
|
||||
return (w->t->north);
|
||||
return (w->s_img.north_texture);
|
||||
else if (wallDir == SOUTH)
|
||||
return (w->t->south);
|
||||
return (w->s_img.south_texture);
|
||||
else if (wallDir == WEST)
|
||||
return (w->t->west);
|
||||
return (w->s_img.west_texture);
|
||||
else if (wallDir == EAST)
|
||||
return (w->t->east);
|
||||
return (w->s_img.east_texture);
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Invalid wall direction.\n");
|
||||
exit_error(w);
|
||||
return (NULL);
|
||||
}
|
||||
if (texture == NULL) {
|
||||
fprintf(stderr, "get_selected_texture: selected texture is NULL\n");
|
||||
} else {
|
||||
printf("get_selected_texture: selected texture = %p\n", texture);
|
||||
}
|
||||
if (texture == NULL)
|
||||
fprintf(stderr, "get_selected_texture: selected texture is NULL\n");
|
||||
else
|
||||
printf("get_selected_texture: selected texture = %p\n", texture);
|
||||
}
|
||||
|
||||
t_texture_data get_texture_data(void *texture)
|
||||
@ -90,7 +87,6 @@ t_texture_data get_texture_data(void *texture)
|
||||
|
||||
texture_data.data = mlx_get_data_addr(texture, &texture_data.bpp,
|
||||
&texture_data.size_line, &texture_data.endian);
|
||||
printf("get_texture_data: bpp = %d, size_line = %d, endian = %d\n", texture_data.bpp, texture_data.size_line, texture_data.endian);
|
||||
return (texture_data);
|
||||
}
|
||||
|
||||
@ -103,13 +99,12 @@ int get_texture_color(t_structure_main *w, WallDirection wallDir,
|
||||
|
||||
selected_texture = get_selected_texture(w, wallDir);
|
||||
if (selected_texture == NULL)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
texture_data = get_texture_data(selected_texture);
|
||||
pixel_pos = (textureX + textureY * w->s_img.texture_width)
|
||||
* (texture_data.bpp / 8);
|
||||
printf("get_texture_color: textureX = %d, textureY = %d, pixel_pos = %d\n", textureX, textureY, pixel_pos);
|
||||
if (textureX < 0 || textureX >= w->s_img.texture_width || textureY < 0)
|
||||
return (0);
|
||||
pixel_pos = textureX * (texture_data.bpp / 8) + textureY * texture_data.size_line;
|
||||
if (pixel_pos < 0)
|
||||
return (0);
|
||||
return (*(int *)(texture_data.data + pixel_pos));
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/15 18:45:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:22:18 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 19:40:29 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,33 +29,37 @@ int setup_and_load_map(int argc, char **argv, t_structure_main *w, t_texture *te
|
||||
printf("Failed to load the map.\n");
|
||||
return (0);
|
||||
}
|
||||
printf("set_up_andloadmap %s\n", textures->north);
|
||||
printf("set_up_andloadmap %s\n", textures->south);
|
||||
printf("set_up_andloadmap %s\n", textures->east);
|
||||
printf("set_up_andloadmap %s\n", textures->west);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void init_structure_main(t_structure_main *w)
|
||||
{
|
||||
if (w == NULL)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
w->t = (t_texture *)malloc(sizeof(t_texture));
|
||||
if (w->t != NULL)
|
||||
{
|
||||
ft_memset(w->t, 0, sizeof(t_texture));
|
||||
}
|
||||
ft_memset(&(w->s_win), 0, sizeof(t_structure_windows));
|
||||
ft_memset(&(w->s_img), 0, sizeof(t_structure_img));
|
||||
ft_memset(&(w->s_map), 0, sizeof(t_structure_map));
|
||||
ft_memset(&(w->s_player), 0, sizeof(t_structure_player));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_structure_main w;
|
||||
t_global_struct global_struct;
|
||||
|
||||
w.t = malloc(sizeof(t_texture));
|
||||
if (w.t == NULL)
|
||||
{
|
||||
// Gérer l'erreur d'allocation
|
||||
}
|
||||
ft_memset(w.t, 0, sizeof(t_texture));
|
||||
init_structure_main(&w);
|
||||
global_struct.w = &w;
|
||||
global_struct.state.jkl = -1;
|
||||
global_struct.state.yui = 0;
|
||||
if (!setup_and_load_map(argc, argv, &w, w.t))
|
||||
return (1);
|
||||
printf("main textures %s\n", w.t->north);
|
||||
printf("main textures %s\n", w.t->south);
|
||||
printf("main textures %s\n", w.t->east);
|
||||
printf("main textures %s\n", w.t->west);
|
||||
init_windows(&w);
|
||||
mlx_loop_hook(w.s_win.mlx, (void *)sleep_mouse, &global_struct);
|
||||
mlx_hook(w.s_win.win, 2, 1L << 0, deal_key, &w);
|
||||
@ -65,5 +69,9 @@ int main(int argc, char **argv)
|
||||
{
|
||||
free(w.s_map.map);
|
||||
}
|
||||
if (w.t)
|
||||
{
|
||||
free(w.t);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -2,8 +2,8 @@ NO textures/NO.xpm
|
||||
SO textures/SO.xpm
|
||||
WE textures/WE.xpm
|
||||
EA textures/EA.xpm
|
||||
F 220, 100, 0
|
||||
C 0, 255, 255
|
||||
F 80, 75, 61
|
||||
C 165, 176, 196
|
||||
|
||||
1111111 11111111111111111111 11111111111 11111111111111111111111111111111111111111111111111111111111111
|
||||
111111000001110000000000000000001 10000000001 10000000000000000000000000000000001111111111111111111111111111
|
||||
@ -17,7 +17,7 @@ C 0, 255, 255
|
||||
100000000000000000111100000000000000000000000000000000000000000000000000000000000011111111111111111111111 1000000000001
|
||||
100000100000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111 1000000000001
|
||||
110000100000011111100000000000000000000000000000000000000000000000000000000000000000000000000000000000001 1000000000001
|
||||
10000100000011 1100000000000000000000000000000000000000000000000000000000000000000000000000000000000001 1000000000001
|
||||
10000100000011 1100000000000000000000000000000000000000000000N00000000000000000000000000000000000000001 1000000000001
|
||||
110000100000011 1100000000000000000000000000000000000000000000000000000000000000000000000000000000000001 1000000000001
|
||||
100000100000011111100000000000000000000000000000000000000000000000000000000000000000000000000000000000001 1000000000001
|
||||
100000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111 1000000000001
|
||||
|
||||
@ -6,45 +6,48 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:09:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/11 20:35:31 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 21:40:56 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
void calculate_future_position(t_position_params *params)
|
||||
{
|
||||
*(params->future_px) = params->px + params->pdx + params->collisionBuffer;
|
||||
*(params->future_py) = params->py + params->pdy + params->collisionBuffer;
|
||||
void calculate_future_position(t_position_params *params) {
|
||||
*(params->future_px) = params->px + params->pdx + params->collisionBuffer;
|
||||
*(params->future_py) = params->py + params->pdy + params->collisionBuffer;
|
||||
|
||||
printf("calculate_future_position: Current px = %d, pdx = %d, collisionBuffer = %d\n", params->px, params->pdx, params->collisionBuffer);
|
||||
printf("calculate_future_position: Current py = %d, pdy = %d, collisionBuffer = %d\n", params->py, params->pdy, params->collisionBuffer);
|
||||
printf("calculate_future_position: Calculated Future Position: x = %d, y = %d\n", *(params->future_px), *(params->future_py));
|
||||
}
|
||||
|
||||
int check_collision(t_structure_main *w, int future_px, int future_py)
|
||||
{
|
||||
int future_ipx;
|
||||
int future_ipy;
|
||||
int check_collision(t_structure_main *w, int future_px, int future_py) {
|
||||
int future_ipx = future_px / w->s_map.mapS;
|
||||
int future_ipy = future_py / w->s_map.mapS;
|
||||
|
||||
future_ipx = future_px / w->s_map.mapS;
|
||||
future_ipy = future_py / w->s_map.mapS;
|
||||
return (w->s_map.map[future_ipy * w->s_map.mapX + future_ipx] == '0');
|
||||
printf("check_collision: Checking Collision at Future Map Index: x = %d, y = %d\n", future_ipx, future_ipy);
|
||||
printf("check_collision: Collision Status: %s\n", w->s_map.map[future_ipy * w->s_map.mapX + future_ipx] == '0' ? "No Collision" : "Collision Detected");
|
||||
|
||||
return (w->s_map.map[future_ipy * w->s_map.mapX + future_ipx] == '0');
|
||||
}
|
||||
|
||||
void calculate_future_position_right_left(t_position_params *params)
|
||||
{
|
||||
double angle;
|
||||
int collision_px;
|
||||
int collision_py;
|
||||
void calculate_future_position_right_left(t_position_params *params) {
|
||||
double angle = params->pa;
|
||||
int collision_px;
|
||||
int collision_py;
|
||||
|
||||
angle = params->pa;
|
||||
if (params->direction == 'd')
|
||||
angle += M_PI_2;
|
||||
else
|
||||
angle -= M_PI_2;
|
||||
*(params->future_px) = params->px + (int)(cos(angle) * 5);
|
||||
*(params->future_py) = params->py + (int)(sin(angle) * 5);
|
||||
collision_px = *(params->future_px) + (int)(cos(params->pa)
|
||||
* params->collisionBuffer);
|
||||
collision_py = *(params->future_py) + (int)(sin(params->pa)
|
||||
* params->collisionBuffer);
|
||||
*(params->future_px) = collision_px;
|
||||
*(params->future_py) = collision_py;
|
||||
if (params->direction == 'd')
|
||||
angle += M_PI_2;
|
||||
else
|
||||
angle -= M_PI_2;
|
||||
|
||||
*(params->future_px) = params->px + (int)(cos(angle) * 5);
|
||||
*(params->future_py) = params->py + (int)(sin(angle) * 5);
|
||||
collision_px = *(params->future_px) + (int)(cos(params->pa) * params->collisionBuffer);
|
||||
collision_py = *(params->future_py) + (int)(sin(params->pa) * params->collisionBuffer);
|
||||
*(params->future_px) = collision_px;
|
||||
*(params->future_py) = collision_py;
|
||||
|
||||
printf("calculate_future_position_right_left: Current px = %d, py = %d, direction = %c\n", params->px, params->py, params->direction);
|
||||
printf("calculate_future_position_right_left: Calculated Future Position: x = %d, y = %d\n", collision_px, collision_py);
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:17:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/12 20:28:07 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 21:12:41 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,37 +35,44 @@ int *kill_prog(t_structure_main *w)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void adjust_player_angle(t_structure_main *w, int key)
|
||||
void adjust_player_angle(t_structure_main *w, int key)
|
||||
{
|
||||
double angle_adjustment;
|
||||
double angle_adjustment;
|
||||
printf("adjust_player_angle: Key pressed: %d\n", key);
|
||||
printf("adjust_player_angle: Before adjustment - pa: %f\n", w->s_player.pa);
|
||||
|
||||
if (key != 65361 && key != 65363)
|
||||
return ;
|
||||
angle_adjustment = 16 * ((PI / 3) / NUMRAY);
|
||||
if (key == 65361)
|
||||
{
|
||||
w->s_player.pa -= angle_adjustment;
|
||||
if (w->s_player.pa < 0)
|
||||
w->s_player.pa += 2 * PI;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->s_player.pa += angle_adjustment;
|
||||
if (w->s_player.pa > 2 * PI)
|
||||
w->s_player.pa -= 2 * PI;
|
||||
}
|
||||
w->s_player.pdx = cos(w->s_player.pa) * 5;
|
||||
w->s_player.pdy = sin(w->s_player.pa) * 5;
|
||||
if (key != 65361 && key != 65363)
|
||||
return;
|
||||
angle_adjustment = 16 * ((PI / 3) / NUMRAY);
|
||||
if (key == 65361)
|
||||
{
|
||||
w->s_player.pa -= angle_adjustment;
|
||||
if (w->s_player.pa < 0)
|
||||
w->s_player.pa += 2 * PI;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->s_player.pa += angle_adjustment;
|
||||
if (w->s_player.pa > 2 * PI)
|
||||
w->s_player.pa -= 2 * PI;
|
||||
}
|
||||
w->s_player.pdx = cos(w->s_player.pa) * 5;
|
||||
w->s_player.pdy = sin(w->s_player.pa) * 5;
|
||||
printf("adjust_player_angle: After adjustment - pa: %f\n", w->s_player.pa);
|
||||
}
|
||||
|
||||
void handle_movement_keys(int key, t_structure_main *w)
|
||||
void handle_movement_keys(t_structure_main *w, int key)
|
||||
{
|
||||
if (key == 119 || key == 100 || key == 115 || key == 97)
|
||||
move(key, w);
|
||||
{
|
||||
adjust_player_angle(w, key);
|
||||
move(w, key);
|
||||
}
|
||||
}
|
||||
|
||||
int deal_key(int key, t_structure_main *w)
|
||||
{
|
||||
printf("deal_key: Key received: %d\n", key);
|
||||
if (key == 65307)
|
||||
{
|
||||
kill_prog(w);
|
||||
@ -74,12 +81,10 @@ int deal_key(int key, t_structure_main *w)
|
||||
{
|
||||
adjust_player_angle(w, key);
|
||||
}
|
||||
else if (key == 65362 || key == 65364 || key == 114 || key == 102)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
handle_movement_keys(key, w);
|
||||
handle_movement_keys(w, key);
|
||||
}
|
||||
printf("deal_key: Key handled: %d\n", key);
|
||||
return (key);
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,105 +6,117 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:08:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/11 20:35:09 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 21:09:26 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
void move_forward(t_structure_main *w, int key)
|
||||
void move_forward(t_structure_main *w, int key)
|
||||
{
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
printf("move_forward: Key pressed: %d\n", key);
|
||||
printf("move_forward: Before move - px: %f, py: %f, pdx: %f, pdy: %f\n", w->s_player.px, w->s_player.py, w->s_player.pdx, w->s_player.pdy);
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
|
||||
if (key != 119)
|
||||
return ;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pdx = w->s_player.pdx;
|
||||
params.pdy = w->s_player.pdy;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
calculate_future_position(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px += w->s_player.pdx;
|
||||
w->s_player.py += w->s_player.pdy;
|
||||
}
|
||||
if (key != 119)
|
||||
return;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pdx = w->s_player.pdx;
|
||||
params.pdy = w->s_player.pdy;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
calculate_future_position(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px += w->s_player.pdx;
|
||||
w->s_player.py += w->s_player.pdy;
|
||||
}
|
||||
printf("move_forward: After move - px: %f, py: %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
void move_backward(t_structure_main *w, int key)
|
||||
void move_backward(t_structure_main *w, int key)
|
||||
{
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
printf("move_forward: Key pressed: %d\n", key);
|
||||
printf("move_forward: Before move - px: %f, py: %f, pdx: %f, pdy: %f\n", w->s_player.px, w->s_player.py, w->s_player.pdx, w->s_player.pdy);
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
|
||||
if (key != 115)
|
||||
return ;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pdx = -w->s_player.pdx;
|
||||
params.pdy = -w->s_player.pdy;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
calculate_future_position(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px -= w->s_player.pdx;
|
||||
w->s_player.py -= w->s_player.pdy;
|
||||
}
|
||||
if (key != 115)
|
||||
return;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pdx = -w->s_player.pdx;
|
||||
params.pdy = -w->s_player.pdy;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
calculate_future_position(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px -= w->s_player.pdx;
|
||||
w->s_player.py -= w->s_player.pdy;
|
||||
}
|
||||
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
void move_right(t_structure_main *w, int key)
|
||||
void move_right(t_structure_main *w, int key)
|
||||
{
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
printf("move_forward: Key pressed: %d\n", key);
|
||||
printf("move_forward: Before move - px: %f, py: %f, pdx: %f, pdy: %f\n", w->s_player.px, w->s_player.py, w->s_player.pdx, w->s_player.pdy);
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
|
||||
if (key != 100)
|
||||
return ;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pa = w->s_player.pa;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
params.direction = 'd';
|
||||
calculate_future_position_right_left(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px = future_px;
|
||||
w->s_player.py = future_py;
|
||||
}
|
||||
if (key != 100)
|
||||
return;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pa = w->s_player.pa;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
params.direction = 'd';
|
||||
calculate_future_position_right_left(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px = future_px;
|
||||
w->s_player.py = future_py;
|
||||
}
|
||||
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
void move_left(t_structure_main *w, int key)
|
||||
void move_left(t_structure_main *w, int key)
|
||||
{
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
printf("move_forward: Key pressed: %d\n", key);
|
||||
printf("move_forward: Before move - px: %f, py: %f, pdx: %f, pdy: %f\n", w->s_player.px, w->s_player.py, w->s_player.pdx, w->s_player.pdy);
|
||||
t_position_params params;
|
||||
int future_px;
|
||||
int future_py;
|
||||
|
||||
if (key != 97)
|
||||
return ;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pa = w->s_player.pa;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
params.direction = 'a';
|
||||
calculate_future_position_right_left(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px = future_px;
|
||||
w->s_player.py = future_py;
|
||||
}
|
||||
if (key != 97)
|
||||
return;
|
||||
params.future_px = &future_px;
|
||||
params.future_py = &future_py;
|
||||
params.pa = w->s_player.pa;
|
||||
params.collisionBuffer = COLBUF;
|
||||
params.px = w->s_player.px;
|
||||
params.py = w->s_player.py;
|
||||
params.direction = 'a';
|
||||
calculate_future_position_right_left(¶ms);
|
||||
if (check_collision(w, future_px, future_py))
|
||||
{
|
||||
w->s_player.px = future_px;
|
||||
w->s_player.py = future_py;
|
||||
}
|
||||
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
void move(int key, t_structure_main *w)
|
||||
void move(t_structure_main *w, int key)
|
||||
{
|
||||
move_forward(w, key);
|
||||
move_backward(w, key);
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/15 20:04:23 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/16 17:47:49 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 11:54:07 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -43,7 +43,7 @@ bool handle_colors(int fd, t_texture *textures)
|
||||
{
|
||||
line[i] = '\0';
|
||||
printf("Ligne lue pour les couleurs: '%s'\n", line);
|
||||
if (process_color_line(line, textures))
|
||||
if ((line[0] == 'F' || line[0] == 'C') && process_color_line(line, textures))
|
||||
color_count++;
|
||||
i = 0;
|
||||
}
|
||||
@ -100,9 +100,5 @@ bool load_cub_file(const char *filename,
|
||||
printf("No map data found in file.\n");
|
||||
result = false;
|
||||
}
|
||||
printf("loadcubfile %s\n", textures->north);
|
||||
printf("loadcubfile %s\n", textures->south);
|
||||
printf("loadcubfile %s\n", textures->east);
|
||||
printf("loadcubfile %s\n", textures->west);
|
||||
return (cleanup_and_close(fd, map_buffer, result));
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,12 +6,33 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:43:46 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/16 15:22:35 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 13:21:28 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
void calculate_map_scale(t_structure_map *map_info)
|
||||
{
|
||||
int maps_x;
|
||||
int maps_y;
|
||||
|
||||
map_info->wd.width = WIDTH;
|
||||
map_info->wd.height = HEIGHT;
|
||||
if (map_info->mapX == 0 || map_info->mapY == 0)
|
||||
{
|
||||
fprintf(stderr, "Erreur: mapX ou mapY est zéro.\n");
|
||||
map_info->mapS = 0;
|
||||
return ;
|
||||
}
|
||||
maps_x = map_info->wd.width / (map_info->mapX * 4);
|
||||
maps_y = map_info->wd.height / (map_info->mapY * 2);
|
||||
if (maps_x < maps_y)
|
||||
map_info->mapS = maps_x;
|
||||
else
|
||||
map_info->mapS = maps_y;
|
||||
}
|
||||
|
||||
bool init_map_info(t_structure_map *map_info, int maxWidth, int height)
|
||||
{
|
||||
map_info->mapX = maxWidth;
|
||||
@ -39,7 +60,52 @@ bool copy_map_data_and_check(t_map_params *params)
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool process_map(const char *buffer, int length, t_structure_map *map_info)
|
||||
bool find_player_position_and_direction(const char *map_content, int length, t_structure_map *map_info)
|
||||
{
|
||||
int i;
|
||||
int line_number;
|
||||
int column_number;
|
||||
bool found_player;
|
||||
char current_char;
|
||||
|
||||
i = 0;
|
||||
line_number = 0;
|
||||
column_number = 0;
|
||||
found_player = false;
|
||||
calculate_map_scale(map_info);
|
||||
while (i < length)
|
||||
{
|
||||
current_char = map_content[i];
|
||||
if (current_char == 'N' || current_char == 'S' || current_char == 'E' || current_char == 'W')
|
||||
{
|
||||
if (found_player)
|
||||
{
|
||||
printf("Multiple player start positions found. Invalid map.\n");
|
||||
return (false);
|
||||
}
|
||||
found_player = true;
|
||||
map_info->player_x = column_number * map_info->mapS + map_info->mapS / 2;
|
||||
map_info->player_y = line_number * map_info->mapS + map_info->mapS / 2;
|
||||
map_info->player_direction = current_char;
|
||||
}
|
||||
if (current_char == '\n')
|
||||
{
|
||||
line_number++;
|
||||
column_number = 0;
|
||||
}
|
||||
else
|
||||
column_number++;
|
||||
i++;
|
||||
}
|
||||
if (!found_player)
|
||||
{
|
||||
printf("Player start position not found. Invalid map.\n");
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool parse_map(const char *buffer, int length, t_structure_map *map_info)
|
||||
{
|
||||
int maxwidth;
|
||||
int height;
|
||||
@ -62,35 +128,8 @@ bool process_map(const char *buffer, int length, t_structure_map *map_info)
|
||||
return (false);
|
||||
}
|
||||
if (!init_map_info(map_info, maxwidth, height))
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
return (copy_map_data_and_check(&map_params));
|
||||
}
|
||||
|
||||
bool parse_map(const char *map_content, int length, t_structure_map *map_info)
|
||||
{
|
||||
t_map_params map_params;
|
||||
int max_width;
|
||||
int height;
|
||||
|
||||
max_width = 0;
|
||||
height = 0;
|
||||
printf("Received map content (length = %d): \n%s\n", length, map_content);
|
||||
map_params.map_info = map_info;
|
||||
map_params.buffer = map_content;
|
||||
map_params.length = length;
|
||||
map_params.maxWidth = &max_width;
|
||||
map_params.height = &height;
|
||||
map_params.currentWidth = NULL;
|
||||
map_params.isNewLine = NULL;
|
||||
get_map_dimensions(&map_params);
|
||||
if (max_width <= 0 || height <= 0)
|
||||
{
|
||||
printf("Invalid map dimensions: maxWidth=%d, height=%d\n", max_width, height);
|
||||
return (false);
|
||||
}
|
||||
if (!init_map_info(map_info, max_width, height))
|
||||
if (!find_player_position_and_direction(buffer, length, map_info))
|
||||
return (false);
|
||||
return (copy_map_data_and_check(&map_params));
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/16 16:19:13 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/16 17:31:12 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/20 11:15:41 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,7 +37,6 @@ bool parse_texture_line(const char *line, t_texture *textures)
|
||||
textures->west = ft_strdup(path);
|
||||
else if (ft_strcmp(direction, "EA") == 0)
|
||||
textures->east = ft_strdup(path);
|
||||
printf("parse texture %s\n", textures->north);
|
||||
return (true);
|
||||
}
|
||||
|
||||
@ -66,25 +65,41 @@ bool handle_map(int fd, char **map_buffer, int *map_length)
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool parse_number_from_str(const char **str, int *number)
|
||||
{
|
||||
*number = 0;
|
||||
while (**str >= '0' && **str <= '9')
|
||||
{
|
||||
*number = *number * 10 + (**str - '0');
|
||||
(*str)++;
|
||||
}
|
||||
if (**str != ',' && **str != ' ' && **str != '\0')
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool parse_color_line(const char *line, unsigned int *color)
|
||||
{
|
||||
int r;
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int i;
|
||||
const char *ptr;
|
||||
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
i = 0;
|
||||
while (line[i] != ',' && line[i] != '\0')
|
||||
r = r * 10 + (line[i++] - '0');
|
||||
i++;
|
||||
while (line[i] != ',' && line[i] != '\0')
|
||||
g = g * 10 + (line[i++] - '0');
|
||||
i++;
|
||||
while (line[i] != ' ' && line[i] != '\0')
|
||||
b = b * 10 + (line[i++] - '0');
|
||||
ptr = line;
|
||||
while (*ptr == ' ') ptr++;
|
||||
if (!parse_number_from_str(&ptr, &r) || *ptr++ != ',')
|
||||
return (false);
|
||||
while (*ptr == ' ') ptr++;
|
||||
if (!parse_number_from_str(&ptr, &g) || *ptr++ != ',')
|
||||
return (false);
|
||||
while (*ptr == ' ') ptr++;
|
||||
if (!parse_number_from_str(&ptr, &b))
|
||||
return (false);
|
||||
*color = (r << 16) | (g << 8) | b;
|
||||
return (true);
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,21 +6,56 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/14 20:09:23 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:15:02 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 14:33:45 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
void init_player(t_structure_main *w)
|
||||
void init_player(t_structure_main *w)
|
||||
{
|
||||
w->s_player.px = 10;
|
||||
w->s_player.py = 10;
|
||||
w->s_player.pa = 0.1;
|
||||
w->s_player.pdx = cos(w->s_player.pa) * 5;
|
||||
w->s_player.pdy = sin(w->s_player.pa) * 5;
|
||||
// Ajouter des logs pour vérifier les valeurs
|
||||
printf("Initialisation du joueur:\n");
|
||||
printf("Position X: %f\n", w->s_map.player_x);
|
||||
printf("Position Y: %f\n", w->s_map.player_y);
|
||||
|
||||
w->s_player.px = w->s_map.player_x;
|
||||
w->s_player.py = w->s_map.player_y;
|
||||
|
||||
if (w->s_map.player_direction == 'N')
|
||||
{
|
||||
w->s_player.pa = M_PI;
|
||||
w->s_player.pdx = 0;
|
||||
w->s_player.pdy = -5;
|
||||
}
|
||||
else if (w->s_map.player_direction == 'S')
|
||||
{
|
||||
w->s_player.pa = 0;
|
||||
w->s_player.pdx = 0;
|
||||
w->s_player.pdy = 5;
|
||||
}
|
||||
else if (w->s_map.player_direction == 'E')
|
||||
{
|
||||
w->s_player.pa = M_PI / 2;
|
||||
w->s_player.pdx = 5;
|
||||
w->s_player.pdy = 0;
|
||||
}
|
||||
else if (w->s_map.player_direction == 'W')
|
||||
{
|
||||
w->s_player.pa = 3 * M_PI / 2;
|
||||
w->s_player.pdx = -5;
|
||||
w->s_player.pdy = 0;
|
||||
}
|
||||
|
||||
// Ajouter des logs pour vérifier les valeurs après l'initialisation
|
||||
printf("Angle de direction: %f radians\n", w->s_player.pa);
|
||||
printf("Vecteur de déplacement X: %f\n", w->s_player.pdx);
|
||||
printf("Vecteur de déplacement Y: %f\n", w->s_player.pdy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void init_mlx_and_window(t_structure_main *w)
|
||||
{
|
||||
w->s_win.mlx = mlx_init();
|
||||
|
||||
Binary file not shown.
@ -6,37 +6,46 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/15 19:50:24 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/15 19:51:24 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 21:10:56 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
void rescale_sprite(t_structure_main *w, t_state *state)
|
||||
{
|
||||
t_rescale_params params;
|
||||
void rescale_sprite(t_structure_main *w, t_state *state) {
|
||||
t_rescale_params params;
|
||||
|
||||
params.original_img = w->s_img.roomadslam[state->jkl];
|
||||
params.original_width = 112;
|
||||
params.original_height = 112;
|
||||
params.new_width = w->s_map.mapS;
|
||||
params.new_height = w->s_map.mapS;
|
||||
params.px = w->s_player.px - w->s_map.mapS / 2;
|
||||
params.py = w->s_player.py - w->s_map.mapS / 2;
|
||||
rescale_image(¶ms, w);
|
||||
params.original_img = w->s_img.roomadslam[state->jkl];
|
||||
params.original_width = 112;
|
||||
params.original_height = 112;
|
||||
params.new_width = w->s_map.mapS;
|
||||
params.new_height = w->s_map.mapS;
|
||||
params.px = w->s_player.px - w->s_map.mapS / 2; // Ajustez cette ligne si nécessaire
|
||||
params.py = w->s_player.py - w->s_map.mapS / 2; // Ajustez cette ligne si nécessaire
|
||||
//Sprintf("rescale_sprite: Player sprite position: x = %d, y = %d\n", params.px, params.py);
|
||||
rescale_image(¶ms, w);
|
||||
}
|
||||
|
||||
|
||||
void refresh_window(t_structure_main *w, t_state *state)
|
||||
{
|
||||
printf("refresh_window: Destroying old image\n");
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
|
||||
//printf("refresh_window: Creating new image\n");
|
||||
w->s_img.buffer = mlx_new_image(w->s_win.mlx, w->s_win.width,
|
||||
w->s_win.height);
|
||||
//printf("refresh_window: Getting data address\n");
|
||||
w->s_img.addr = mlx_get_data_addr(w->s_img.buffer,
|
||||
&(w->s_img.bpp), &(w->s_img.line_len), &(w->s_img.endian));
|
||||
//printf("refresh_window: Drawing map\n");
|
||||
draw_map(w);
|
||||
//printf("refresh_window: Drawing rays 2D\n");
|
||||
drawrays2d(w);
|
||||
//printf("refresh_window: Putting image to window\n");
|
||||
mlx_put_image_to_window(w->s_win.mlx, w->s_win.win, w->s_img.buffer, 0, 0);
|
||||
//printf("refresh_window: Rescaling sprite\n");
|
||||
rescale_sprite(w, state);
|
||||
printf("refresh_window: Window refreshed\n");
|
||||
}
|
||||
|
||||
void handle_mouse_movement(t_structure_main *w)
|
||||
@ -44,6 +53,7 @@ void handle_mouse_movement(t_structure_main *w)
|
||||
int x;
|
||||
int y;
|
||||
|
||||
|
||||
mlx_mouse_get_pos(w->s_win.mlx, w->s_win.win, &x, &y);
|
||||
if ((x > 0 && x < w->s_win.height) && (y > 0 && y < w->s_win.width))
|
||||
{
|
||||
@ -55,6 +65,7 @@ void handle_mouse_movement(t_structure_main *w)
|
||||
deal_key(65363, w);
|
||||
}
|
||||
}
|
||||
//printf("handle_mouse_movement: Mouse position: x = %d, y = %d\n", x, y);
|
||||
}
|
||||
|
||||
void r_window(t_structure_main *w, t_state *state)
|
||||
@ -73,9 +84,13 @@ void sleep_mouse(t_global_struct *global_struct)
|
||||
{
|
||||
global_struct->state.yui = 0;
|
||||
global_struct->state.jkl++;
|
||||
//printf("sleep_mouse: Iteration %d - Updating window and handling mouse movement\n", global_struct->state.jkl);
|
||||
r_window(global_struct->w, &global_struct->state);
|
||||
handle_mouse_movement(global_struct->w);
|
||||
}
|
||||
if (global_struct->state.jkl == 10)
|
||||
global_struct->state.jkl = -1;
|
||||
{
|
||||
//printf("sleep_mouse: Resetting state.jkl to -1\n");
|
||||
global_struct->state.jkl = -1;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/14 19:15:53 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/17 21:26:12 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/21 14:08:12 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -71,19 +71,6 @@ void init_buffer(t_structure_main *w)
|
||||
w->s_win.width, w->s_win.height);
|
||||
}
|
||||
|
||||
void calculate_map_scale(t_structure_main *w)
|
||||
{
|
||||
int maps_x;
|
||||
int maps_y;
|
||||
|
||||
maps_x = w->s_win.width / (w->s_map.mapX * 4);
|
||||
maps_y = w->s_win.height / (w->s_map.mapY * 2);
|
||||
if (maps_x < maps_y)
|
||||
w->s_map.mapS = maps_x;
|
||||
else
|
||||
w->s_map.mapS = maps_y;
|
||||
}
|
||||
|
||||
void init_windows(t_structure_main *w)
|
||||
{
|
||||
int temp;
|
||||
@ -92,6 +79,10 @@ void init_windows(t_structure_main *w)
|
||||
w->s_win.height = HEIGHT;
|
||||
init_player(w);
|
||||
init_mlx_and_window(w);
|
||||
w->s_img.north_texture = NULL;
|
||||
w->s_img.south_texture = NULL;
|
||||
w->s_img.west_texture = NULL;
|
||||
w->s_img.east_texture = NULL;
|
||||
load_textures(w, &temp);
|
||||
init_buffer(w);
|
||||
load_wall_textures(w);
|
||||
@ -102,5 +93,4 @@ void init_windows(t_structure_main *w)
|
||||
gettimeofday(&(w->start_time), NULL);
|
||||
w->end_time = w->start_time;
|
||||
w->frame_count = 0;
|
||||
calculate_map_scale(w);
|
||||
}
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user