-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_player_location.c
71 lines (64 loc) · 2.14 KB
/
get_player_location.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_player_location.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fflores <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/02 15:13:19 by fflores #+# #+# */
/* Updated: 2020/11/02 15:13:21 by fflores ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int find_north(t_data *data, int i, int j)
{
data->player.rotation_angel -= M_PI / 2;
data->player.x = (i + 1) * TILE_SIZE;
data->player.y = (j + 1) * TILE_SIZE;
return (1);
}
static int find_east(t_data *data, int i, int j)
{
data->player.x = (i + 1) * TILE_SIZE;
data->player.y = (j + 1) * TILE_SIZE;
return (1);
}
static int find_south(t_data *data, int i, int j)
{
data->player.rotation_angel += M_PI / 2;
data->player.x = (i + 1) * TILE_SIZE;
data->player.y = (j + 1) * TILE_SIZE;
return (1);
}
static int find_west(t_data *data, int i, int j)
{
data->player.rotation_angel += M_PI;
data->player.x = (i + 1) * TILE_SIZE;
data->player.y = (j + 1) * TILE_SIZE;
return (1);
}
void get_player_location(t_data *data)
{
int i;
int j;
int detcted;
j = -1;
detcted = 0;
while (++j < data->conf.map_h)
{
i = -1;
while (data->conf.world_map[j][++i])
{
if (data->conf.world_map[j][i] == 'N')
detcted += find_north(data, i, j);
if (data->conf.world_map[j][i] == 'E')
detcted += find_east(data, i, j);
if (data->conf.world_map[j][i] == 'S')
detcted += find_south(data, i, j);
if (data->conf.world_map[j][i] == 'W')
detcted += find_west(data, i, j);
}
}
if (detcted != 1)
ft_put_error("\nInvalid map\n", EINVAL);
}