wip: adding door interaction

This commit is contained in:
Theo Champion 2025-10-01 00:30:08 +02:00
parent ebd4b282cf
commit b606159ac3
3 changed files with 32 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/05 12:53:06 by kcolin #+# #+# */
/* Updated: 2025/08/12 12:16:51 by kcolin ### ########.fr */
/* Updated: 2025/09/30 20:08:31 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
/* Updated: 2025/09/17 16:52:41 by tchampio ### ########.fr */
/* Updated: 2025/09/30 20:31:08 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,6 +49,8 @@ typedef struct s_player
t_vec2 movement;
t_weapon *weapon;
t_sprite *aimed_zombie;
int closest_door[2];
bool can_open_door;
} t_player;
#endif // PLAYER_H

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
/* Updated: 2025/09/15 14:08:27 by tchampio ### ########.fr */
/* Updated: 2025/09/30 23:05:11 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@
#include <math.h>
#include <stdlib.h>
#include "../map/collision.h"
#include "../../libft/includes/libft.h"
void init_ray(t_ray *ray, int pos_x, t_player *player)
{
@ -57,6 +58,28 @@ void ray_calculate_step(t_ray *ray, t_player *player)
}
}
void handle_door_ray(t_ray *ray, t_cub3d_data *data)
{
if (data->map->map[ray->map_y][ray->map_x] == 'd' && ray->wall_dist < 1.5)
{
ft_printf("map[%d][%d] = door reachable\n", ray->map_y, ray->map_x);
data->player.closest_door[0] = ray->map_x;
data->player.closest_door[1] = ray->map_y;
data->player.can_open_door = true;
if (data->keypresses.is_f_pressed)
{
data->keypresses.is_f_pressed = false;
data->map->map[ray->map_y][ray->map_x] = 'i';
}
}
else
{
data->player.closest_door[0] = -1;
data->player.closest_door[1] = -1;
data->player.can_open_door = false;
}
}
void calculate_wall_dist(t_ray *ray, int x, t_cub3d_data *data)
{
while (true)
@ -76,8 +99,12 @@ void calculate_wall_dist(t_ray *ray, int x, t_cub3d_data *data)
ray->side = SOUTH;
}
if (blocks_view(data->map, ray->map_x, ray->map_y))
{
if (x == WIDTH / 2)
handle_door_ray(ray, data);
break ;
}
}
if (ray->side == NORTH)
ray->wall_dist = ray->side_dist_x - ray->delta_dist_x;
else