-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovements.c
37 lines (33 loc) · 1.27 KB
/
movements.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
#include "wolf.h"
void move_forward(t_player *pl, int **map)
{
if (!map[(int)(pl->player_x + pl->dir_x * pl->speed)][(int)(pl->player_y)])
pl->player_x += pl->dir_x * pl->speed;
if (!map[(int)(pl->player_x)][(int)(pl->player_y + pl->dir_y * pl->speed)])
pl->player_y += pl->dir_y * pl->speed;
}
void move_back(t_player *pl, int **map)
{
if (!map[(int)(pl->player_x - pl->dir_x * pl->speed)][(int)(pl->player_y)])
pl->player_x -= pl->dir_x * pl->speed;
if (!map[(int)(pl->player_x)][(int)(pl->player_y - pl->dir_y * pl->speed)])
pl->player_y -= pl->dir_y * pl->speed;
}
void turn_left(t_player *pl)
{
pl->old_dir_x = pl->dir_x;
pl->dir_x = pl->dir_x * cos(0.05) - pl->dir_y * sin(0.05);
pl->dir_y = pl->old_dir_x * sin(0.05) + pl->dir_y * cos(0.05);
pl->old_plane_x = pl->plane_x;
pl->plane_x = pl->plane_x * cos(0.05) - pl->plane_y * sin(0.05);
pl->plane_y = pl->old_plane_x * sin(0.05) + pl->plane_y * cos(0.05);
}
void turn_right(t_player *pl)
{
pl->old_dir_x = pl->dir_x;
pl->dir_x = pl->dir_x * cos(-0.05) - pl->dir_y * sin(-0.05);
pl->dir_y = pl->old_dir_x * sin(-0.05) + pl->dir_y * cos(-0.05);
pl->old_plane_x = pl->plane_x;
pl->plane_x = pl->plane_x * cos(-0.05) - pl->plane_y * sin(-0.05);
pl->plane_y = pl->old_plane_x * sin(-0.05) + pl->plane_y * cos(-0.05);
}