-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jean Teissier
authored and
Jean Teissier
committed
Sep 2, 2024
1 parent
937924d
commit 7d9c030
Showing
2 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,7 @@ F 220,100,0 | |
C 225,30,0 | ||
|
||
111111111 | ||
100000001 | ||
1000D0001 | ||
1000N0001 | ||
100000001 | ||
100DND001 | ||
1000D0001 | ||
111111111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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,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 ; | ||
} | ||
|
||
|