-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_moves.c
79 lines (70 loc) · 2.41 KB
/
key_moves.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* key_moves.c :+: :+: */
/* +:+ */
/* By: ydemura <ydemura@student.42.fr> +#+ */
/* +#+ */
/* Created: 2022/12/08 16:43:28 by ydemura #+# #+# */
/* Updated: 2022/12/08 21:45:36 by adoner ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "key_moves.h"
#include <math.h>
void key_left(t_parsing_result *data)
{
data->player.pa -= 0.05 * M_PI;
if (data->player.pa < 0)
data->player.pa += 2 * M_PI;
data->player.x_camera = cos(data->player.pa) * 5.0;
data->player.y_camera = sin(data->player.pa) * 5.0;
}
void key_right(t_parsing_result *data)
{
data->player.pa += 0.05 * M_PI;
if (data->player.pa > 2 * M_PI)
data->player.pa -= 2 * M_PI;
data->player.x_camera = cos(data->player.pa) * 5.0;
data->player.y_camera = sin(data->player.pa) * 5.0;
}
void key_a(t_parsing_result *data)
{
double move_x;
double move_y;
move_x = data->player.x + data->player.game_speed
* cos(data->player.pa - 0.5 * M_PI);
move_y = data->player.y + data->player.game_speed
* sin(data->player.pa - 0.5 * M_PI);
if (check_move(move_x, move_y, data))
{
data->player.y = move_y;
data->player.x = move_x;
}
}
void key_d(t_parsing_result *data)
{
double move_x;
double move_y;
move_x = data->player.x + data->player.game_speed
* cos(data->player.pa + 0.5 * M_PI);
move_y = data->player.y + data->player.game_speed
* sin(data->player.pa + 0.5 * M_PI);
if (check_move(move_x, move_y, data))
{
data->player.y = move_y;
data->player.x = move_x;
}
}
void key_s(t_parsing_result *data)
{
double move_x;
double move_y;
move_x = data->player.x - data->player.game_speed * cos(data->player.pa);
move_y = data->player.y - data->player.game_speed * sin(data->player.pa);
if (check_move(move_x, move_y, data))
{
data->player.x = move_x;
data->player.y = move_y;
}
}