-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_skin.c
130 lines (119 loc) · 3.55 KB
/
get_skin.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_skin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rvan-der <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/27 16:58:16 by rvan-der #+# #+# */
/* Updated: 2017/02/27 17:09:11 by rvan-der ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
int is_skin(t_coord pos, t_skin *list)
{
t_skin *tmp;
tmp = list;
while (tmp != NULL)
{
if ((tmp->crd).x == pos.x && (tmp->crd).y == pos.y)
return (1);
tmp = tmp->next;
}
return (0);
}
void get_skin4(t_plateau p, t_ennemi *e)
{
t_coord pos;
pos.y = (e->sqr).s;
while (pos.y >= (e->sqr).n)
{
pos.x = ((e->sqr).w ? (e->sqr).w - 1 : 0);
while (!is_ennemi((p.map)[pos.y][pos.x], p.pl))
{
if (((pos.y + 1 < (p.size).y && \
is_ennemi((p.map)[pos.y + 1][pos.x], p.pl)) || \
(pos.y - 1 >= 0 && \
is_ennemi((p.map)[pos.y - 1][pos.x], p.pl)) || \
is_ennemi((p.map)[pos.y][pos.x + 1], p.pl)) \
&& is_surface(pos, p) \
&& !is_inhole(pos, p) \
&& !is_skin(pos, e->skin))
skin_pushback(&(e->skin), pos, p);
(pos.x)++;
}
(pos.y)--;
}
}
void get_skin3(t_plateau p, t_ennemi *e)
{
t_coord pos;
pos.x = (e->sqr).e;
while (pos.x >= (e->sqr).w)
{
pos.y = ((e->sqr).s == (p.size).y - 1 ? (e->sqr).s : (e->sqr).s + 1);
while (!is_ennemi((p.map)[pos.y][pos.x], p.pl))
{
if (((pos.x + 1 < (p.size).x && \
is_ennemi((p.map)[pos.y][pos.x + 1], p.pl)) || \
(pos.x - 1 >= 0 && \
is_ennemi((p.map)[pos.y][pos.x - 1], p.pl)) || \
is_ennemi((p.map)[pos.y - 1][pos.x], p.pl)) \
&& is_surface(pos, p) \
&& !is_inhole(pos, p) \
&& !is_skin(pos, e->skin))
skin_pushback(&(e->skin), pos, p);
(pos.y)--;
}
(pos.x)--;
}
get_skin4(p, e);
}
void get_skin2(t_plateau p, t_ennemi *e)
{
t_coord pos;
pos.y = (e->sqr).n;
while (pos.y <= (e->sqr).s)
{
pos.x = ((e->sqr).e == (p.size).x - 1 ? (e->sqr).e : (e->sqr).e + 1);
while (!is_ennemi((p.map)[pos.y][pos.x], p.pl))
{
if (((pos.y + 1 < (p.size).y && \
is_ennemi((p.map)[pos.y + 1][pos.x], p.pl)) || \
(pos.y - 1 >= 0 && \
is_ennemi((p.map)[pos.y - 1][pos.x], p.pl)) || \
is_ennemi((p.map)[pos.y][pos.x - 1], p.pl)) \
&& is_surface(pos, p) \
&& !is_inhole(pos, p) \
&& !is_skin(pos, e->skin))
skin_pushback(&(e->skin), pos, p);
(pos.x)--;
}
(pos.y)++;
}
get_skin3(p, e);
}
void get_skin(t_plateau p, t_ennemi *e)
{
t_coord pos;
pos.x = (e->sqr).w;
while (pos.x <= (e->sqr).e)
{
pos.y = ((e->sqr).n > 0 ? (e->sqr).n - 1 : 0);
while (!is_ennemi((p.map)[pos.y][pos.x], p.pl))
{
if (((pos.x + 1 < (p.size).x && \
is_ennemi((p.map)[pos.y][pos.x + 1], p.pl)) || \
(pos.x - 1 >= 0 && \
is_ennemi((p.map)[pos.y][pos.x - 1], p.pl)) || \
is_ennemi((p.map)[pos.y + 1][pos.x], p.pl)) \
&& is_surface(pos, p) \
&& !is_inhole(pos, p) \
&& !is_skin(pos, e->skin))
skin_pushback(&(e->skin), pos, p);
(pos.y)++;
}
(pos.x)++;
}
get_skin2(p, e);
}