Cub3D
Loading...
Searching...
No Matches
move_and_strafe.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* move_and_strafe.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/10/15 13:47:13 by kamitsui #+# #+# */
9/* Updated: 2024/10/20 11:23:25 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
19bool is_through_wall(char **data, t_vector view_point, t_vector move_amount)
20{
21 int x;
22 int y;
23
24 x = (int)(view_point.x + move_amount.x);
25 y = (int)(view_point.y + move_amount.y);
26 if (data[y][x] == '1')
27 return (true);
28 return (false);
29}
30
31void move_forward(t_map *map, t_player *player)
32{
33 t_vector move_amount;
34
35 move_amount.x = player->ray_dir.x * player->move_speed;
36 move_amount.y = player->ray_dir.y * player->move_speed;
37 if (is_collision_detection_x(
38 map->data, player->view_point, move_amount.x) == false)
39 player->view_point.x += move_amount.x;
40 if (is_collision_detection_y(
41 map->data, player->view_point, move_amount.y) == false)
42 player->view_point.y += move_amount.y;
43}
44// No drift movement
45// if (is_through_wall(map->data, player->view_point, move_amount) == true)
46// return ;
47
48void move_backward(t_map *map, t_player *player)
49{
50 t_vector move_amount;
51
52 move_amount.x = - (player->ray_dir.x * player->move_speed);
53 if (is_collision_detection_x(
54 map->data, player->view_point, move_amount.x) == false)
55 player->view_point.x += move_amount.x;
56 move_amount.y = - (player->ray_dir.y * player->move_speed);
57 if (is_collision_detection_y(
58 map->data, player->view_point, move_amount.y) == false)
59 player->view_point.y += move_amount.y;
60}
61
62void strafe_left(t_map *map, t_player *player)
63{
64 t_vector move_amount;
65
66 move_amount.x = - (player->camera_forcal_plane.x * player->move_speed);
67 if (is_collision_detection_x(
68 map->data, player->view_point, move_amount.x) == false)
69 player->view_point.x += move_amount.x;
70 move_amount.y = - (player->camera_forcal_plane.y * player->move_speed);
71 if (is_collision_detection_y(
72 map->data, player->view_point, move_amount.y) == false)
73 player->view_point.y += move_amount.y;
74}
75
76void strafe_right(t_map *map, t_player *player)
77{
78 t_vector move_amount;
79
80 move_amount.x = player->camera_forcal_plane.x * player->move_speed;
81 if (is_collision_detection_x(
82 map->data, player->view_point, move_amount.x) == false)
83 player->view_point.x += move_amount.x;
84 move_amount.y = player->camera_forcal_plane.y * player->move_speed;
85 if (is_collision_detection_y(
86 map->data, player->view_point, move_amount.y) == false)
87 player->view_point.y += move_amount.y;
88}
game map
Definition type_cub3d.h:237
keyboard event flag
Definition type_cub3d.h:226
vector
Definition type_cub3d.h:74