-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.c
84 lines (77 loc) · 1.96 KB
/
tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zbabahmi <zbabahmi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/05 05:20:27 by zbabahmi #+# #+# */
/* Updated: 2023/04/14 00:58:01 by zbabahmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
t_dim get_player_position(t_savage *criminal)
{
int idx1;
int idx2;
t_dim player_pos;
player_pos.x = -1;
player_pos.y = -1;
idx1 = 0;
while (criminal->map[idx1])
{
idx2 = 0;
while (criminal->map[idx1][idx2])
{
if (criminal->map[idx1][idx2] == 'P')
{
player_pos.x = idx2;
player_pos.y = idx1;
return (player_pos);
}
idx2++;
}
idx1++;
}
return (player_pos);
}
char get_position_in_map(t_savage *criminal, t_dim *wanted_dim)
{
char res;
int idx1;
int idx2;
res = '\0';
idx1 = 0;
while (criminal->map[idx1])
{
idx2 = 0;
while (criminal->map[idx1][idx2])
{
if (idx1 == wanted_dim->y && idx2 == wanted_dim->x)
return (criminal->map[idx1][idx2]);
idx2++;
}
idx1++;
}
return (res);
}
void modify_map(t_savage *criminal, t_dim *position, char with_what)
{
int idx1;
int idx2;
idx1 = 0;
while (criminal->map[idx1])
{
idx2 = 0;
while (criminal->map[idx1][idx2])
{
if (idx1 == position->y && idx2 == position->x)
{
criminal->map[idx1][idx2] = with_what;
return ;
}
idx2++;
}
idx1++;
}
}