manquecorrigetouchesetparsing

This commit is contained in:
2024-01-21 21:43:07 +01:00
parent 05f1323377
commit 6d8196504c
34 changed files with 473 additions and 329 deletions

View File

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

View File

@@ -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(&params, 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(&params, 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;
}
}

View File

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