-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmove.c
95 lines (87 loc) · 3.4 KB
/
move.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvinogra <vvinogra@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/06 15:13:56 by vvinogra #+# #+# */
/* Updated: 2018/03/11 20:22:25 by vvinogra ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf.h"
void move_forward(t_wolf *wolf)
{
if (wolf->map[(int)(wolf->ray->player_posx +
wolf->ray->player_dir_x * wolf->ray->move_speed)]
[(int)wolf->ray->player_posy] == 0)
wolf->ray->player_posx += wolf->ray->player_dir_x
* wolf->ray->move_speed;
if (wolf->map[(int)wolf->ray->player_posx]
[(int)(wolf->ray->player_posy +
wolf->ray->player_dir_y * wolf->ray->move_speed)] == 0)
wolf->ray->player_posy += wolf->ray->player_dir_y
* wolf->ray->move_speed;
}
void move_back(t_wolf *wolf)
{
if (wolf->map[(int)(wolf->ray->player_posx -
wolf->ray->player_dir_x * wolf->ray->move_speed)]
[(int)wolf->ray->player_posy] == 0)
wolf->ray->player_posx -= wolf->ray->player_dir_x
* wolf->ray->move_speed;
if (wolf->map[(int)wolf->ray->player_posx]
[(int)(wolf->ray->player_posy -
wolf->ray->player_dir_y * wolf->ray->move_speed)] == 0)
wolf->ray->player_posy -= wolf->ray->player_dir_y
* wolf->ray->move_speed;
}
void move_right(t_wolf *wolf)
{
double old_player_dir_x;
double old_plane_x;
old_player_dir_x = wolf->ray->player_dir_x;
wolf->ray->player_dir_x = wolf->ray->player_dir_x *
cos(-wolf->ray->cam_speed) -
wolf->ray->player_dir_y * sin(-wolf->ray->cam_speed);
wolf->ray->player_dir_y = old_player_dir_x *
sin(-wolf->ray->cam_speed) +
wolf->ray->player_dir_y * cos(-wolf->ray->cam_speed);
old_plane_x = wolf->ray->plane_x;
wolf->ray->plane_x = wolf->ray->plane_x *
cos(-wolf->ray->cam_speed) -
wolf->ray->plane_y * sin(-wolf->ray->cam_speed);
wolf->ray->plane_y = old_plane_x *
sin(-wolf->ray->cam_speed) +
wolf->ray->plane_y * cos(-wolf->ray->cam_speed);
}
void move_left(t_wolf *wolf)
{
double old_player_dir_x;
double old_plane_x;
old_player_dir_x = wolf->ray->player_dir_x;
wolf->ray->player_dir_x = wolf->ray->player_dir_x *
cos(wolf->ray->cam_speed) -
wolf->ray->player_dir_y * sin(wolf->ray->cam_speed);
wolf->ray->player_dir_y = old_player_dir_x *
sin(wolf->ray->cam_speed) +
wolf->ray->player_dir_y * cos(wolf->ray->cam_speed);
old_plane_x = wolf->ray->plane_x;
wolf->ray->plane_x = wolf->ray->plane_x *
cos(wolf->ray->cam_speed) -
wolf->ray->plane_y * sin(wolf->ray->cam_speed);
wolf->ray->plane_y = old_plane_x *
sin(wolf->ray->cam_speed) +
wolf->ray->plane_y * cos(wolf->ray->cam_speed);
}
void move(t_wolf *wolf)
{
if (wolf->move->move_left == 1)
move_left(wolf);
if (wolf->move->move_right == 1)
move_right(wolf);
if (wolf->move->move_back == 1)
move_back(wolf);
if (wolf->move->move_forward == 1)
move_forward(wolf);
}