mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2026-11-09 13:47:10 +01:00
220124
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:09:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/21 21:40:56 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/22 13:25:35 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,17 +16,17 @@ 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));
|
||||
//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 = future_px / w->s_map.mapS;
|
||||
int future_ipy = future_py / w->s_map.mapS;
|
||||
|
||||
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");
|
||||
//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');
|
||||
}
|
||||
@@ -48,6 +48,6 @@ void calculate_future_position_right_left(t_position_params *params) {
|
||||
*(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);
|
||||
//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/21 21:12:41 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/22 16:24:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -35,32 +35,26 @@ int *kill_prog(t_structure_main *w)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void adjust_player_angle(t_structure_main *w, int key)
|
||||
{
|
||||
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);
|
||||
void adjust_player_angle(t_structure_main *w, int key) {
|
||||
const double rotation_speed = 0.174533; // Environ 10 degrés en radians
|
||||
|
||||
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;
|
||||
if (key == 65363) { // Touche droite
|
||||
w->s_player.pa += rotation_speed;
|
||||
} else if (key == 65361) { // Touche gauche
|
||||
w->s_player.pa -= rotation_speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->s_player.pa += angle_adjustment;
|
||||
if (w->s_player.pa > 2 * PI)
|
||||
w->s_player.pa -= 2 * PI;
|
||||
|
||||
// Normalisation de l'angle
|
||||
if (w->s_player.pa < 0) {
|
||||
w->s_player.pa += 2 * M_PI;
|
||||
} else if (w->s_player.pa >= 2 * M_PI) {
|
||||
w->s_player.pa -= 2 * M_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(t_structure_main *w, int key)
|
||||
{
|
||||
if (key == 119 || key == 100 || key == 115 || key == 97)
|
||||
@@ -81,7 +75,7 @@ int deal_key(int key, t_structure_main *w)
|
||||
{
|
||||
adjust_player_angle(w, key);
|
||||
}
|
||||
else
|
||||
else if (key == 119 || key == 100 || key == 115 || key == 97)
|
||||
{
|
||||
handle_movement_keys(w, key);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:08:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/21 21:09:26 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/01/22 16:10:32 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -35,6 +35,7 @@ void move_forward(t_structure_main *w, int key)
|
||||
w->s_player.px += w->s_player.pdx;
|
||||
w->s_player.py += w->s_player.pdy;
|
||||
}
|
||||
//printf("move %d, pa %f\n", key, w->s_player.pa);
|
||||
printf("move_forward: After move - px: %f, py: %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
@@ -61,6 +62,7 @@ void move_backward(t_structure_main *w, int key)
|
||||
w->s_player.px -= w->s_player.pdx;
|
||||
w->s_player.py -= w->s_player.pdy;
|
||||
}
|
||||
//printf("move %d, pa %f\n", key, w->s_player.pa);
|
||||
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
@@ -87,6 +89,7 @@ void move_right(t_structure_main *w, int key)
|
||||
w->s_player.px = future_px;
|
||||
w->s_player.py = future_py;
|
||||
}
|
||||
//printf("move %d, pa %f\n", key, w->s_player.pa);
|
||||
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
@@ -113,6 +116,7 @@ void move_left(t_structure_main *w, int key)
|
||||
w->s_player.px = future_px;
|
||||
w->s_player.py = future_py;
|
||||
}
|
||||
//printf("move %d, pa %f\n", key, w->s_player.pa);
|
||||
printf("Move Backward: Player position after moving backward: x = %f, y = %f\n", w->s_player.px, w->s_player.py);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user