diff --git a/maps/wall_test.cub b/maps/wall_test.cub index 7ac0128..2875ebd 100644 --- a/maps/wall_test.cub +++ b/maps/wall_test.cub @@ -8,8 +8,7 @@ F 220,100,0 C 225,30,0 111111111 -100000001 1000D0001 -1000N0001 -100000001 +100DND001 +1000D0001 111111111 diff --git a/srcs/events/mouse_events.c b/srcs/events/mouse_events.c index 4e96666..76aae0f 100644 --- a/srcs/events/mouse_events.c +++ b/srcs/events/mouse_events.c @@ -6,7 +6,7 @@ /* By: jteissie +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/02 15:02:38 by jteissie #+# #+# */ -/* Updated: 2024/09/02 15:50:21 by jteissie ### ########.fr */ +/* Updated: 2024/09/02 15:50:218:16 by jteissie ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,8 @@ static double get_door_dist(t_vec *ray, t_data *data) data->side = rc_dda(&dist_ray, &unit_dist, &ray_pos, ray); if (data->map[(int)ray_pos.x][(int)ray_pos.y] == '1') return (1); - else if (data->map[(int)ray_pos.x][(int)ray_pos.y] == 'D') + else if (data->map[(int)ray_pos.x][(int)ray_pos.y] == 'D' + || data->map[(int)ray_pos.x][(int)ray_pos.y] == 'O') break ; } if (data->side == 1) @@ -37,9 +38,26 @@ static double get_door_dist(t_vec *ray, t_data *data) return ((dist_ray.x - unit_dist.x) * vec_cos(ray, &data->p_dir)); } -static void change_door_state(t_data *data, double dist) +static void change_door_state(t_data *data, double dist, t_vec *p_ray) { + int door_x; + int door_y; + printf("dist: %f\n", dist); + door_x = data->p_pos.x + p_ray->x; + door_y = data->p_pos.y + p_ray->y; + printf("Door position is: (%d, %d)\n", door_x, door_y); + printf("Map value: %c\n", data->map[door_x][door_y]); + if (data->map[door_x][door_y] == 'D') + { + printf("Opening door!\n"); + data->map[door_x][door_y] = 'O'; + } + else if (data->map[door_x][door_y] == 'O') + { + printf("Closing door!\n"); + data->map[door_x][door_y] = 'D'; + } } static void interact_door(t_data *data) @@ -49,8 +67,6 @@ static void interact_door(t_data *data) p_ray.x = data->p_dir.x; p_ray.y = data->p_dir.y; - printf("p_ray.x: %f\n", p_ray.x); - printf("p_ray.y: %f\n", p_ray.y); dist = get_door_dist(&p_ray, data); if (dist > 0.5) { @@ -58,7 +74,7 @@ static void interact_door(t_data *data) return ; } printf("In door range!\n"); - change_door_state(data, dist); + change_door_state(data, dist, &p_ray); return ; }