-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_player_data.c
98 lines (89 loc) · 2.33 KB
/
init_player_data.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
96
97
98
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_player_data.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenheni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 13:30:26 by abenheni #+# #+# */
/* Updated: 2023/12/04 13:30:27 by abenheni ### ########.fr */
/* */
/* ************************************************************************** */
#include "render_map.h"
/*return the x-coord of the player*/
static int get_player_x(char **map)
{
int x;
int y;
y = 0;
x = 0;
while (y < get_height(map))
{
x = 0;
while (map[y][x])
{
if (is_player(map[y][x]))
break ;
else
x++;
}
if (is_player(map[y][x]))
break ;
y++;
}
return (x * TILE_SIZE + (TILE_SIZE / 2));
}
/*return the y-coord of the player*/
static int get_player_y(char **map)
{
int x;
int y;
y = 0;
while (y < get_height(map))
{
x = 0;
while (map[y][x])
{
if (is_player(map[y][x]))
break ;
else
x++;
}
if (is_player(map[y][x]))
break ;
y++;
}
return (y * TILE_SIZE + (TILE_SIZE / 2));
}
/*return the angle depending on the charactere that represent player*/
static double update_angle(char dir)
{
if (dir == 'N')
return (norm_angl(-(M_PI / 2)));
else if (dir == 'E')
return (0);
else if (dir == 'S')
return (M_PI / 2);
else
return (M_PI);
}
/*return the angle that a player should take as initialisation angle*/
static double handle_player_direction(t_player player, char **map)
{
int x;
int y;
double angle;
x = player.x / TILE_SIZE;
y = player.y / TILE_SIZE;
angle = update_angle(map[y][x]);
return (angle);
}
void init_player_data(t_player *player, char **map)
{
player->x = get_player_x(map);
player->y = get_player_y(map);
player->turn_direction = 0;
player->walk_direction = 0;
player->is_lr = 0;
player->rotation_angle = handle_player_direction(*player, map);
}