Skip to content

Commit

Permalink
It works, remove printf calls"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Teissier authored and Jean Teissier committed Sep 2, 2024
1 parent 937924d commit 7d9c030
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
5 changes: 2 additions & 3 deletions maps/wall_test.cub
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ F 220,100,0
C 225,30,0

111111111
100000001
1000D0001
1000N0001
100000001
100DND001
1000D0001
111111111
28 changes: 22 additions & 6 deletions srcs/events/mouse_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jteissie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -49,16 +67,14 @@ 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)
{
printf("Door too far!\n");
return ;
}
printf("In door range!\n");
change_door_state(data, dist);
change_door_state(data, dist, &p_ray);
return ;
}

Expand Down

0 comments on commit 7d9c030

Please sign in to comment.