-
Notifications
You must be signed in to change notification settings - Fork 0
/
so_walls.c
118 lines (107 loc) · 2.33 KB
/
so_walls.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_walls.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/05 18:06:11 by zwalad #+# #+# */
/* Updated: 2022/02/10 01:23:14 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_test.h"
void check_newlines(t_jinx *p)
{
int i;
i = 0;
while (p->dmap[i])
{
if (p->dmap[i][0] == '\n')
{
ez_exit(i);
}
i++;
}
}
void walls_x(t_jinx *p, int i, int j)
{
int k;
k = 0;
i -= 1;
while (k < j)
{
if (p->dmap[0][k] != '1')
{
ez_exit(i);
}
if (p->dmap[i][k] != '1')
{
ez_exit(i);
}
k++;
}
}
void walls_y(t_jinx *p, int i, int j)
{
int k;
k = 0;
i -= 1;
j -= 1;
while (k < i)
{
if (p->dmap[k][0] != '1')
{
ez_exit(i);
}
if (p->dmap[k][j] != '1')
{
ez_exit(i);
}
k++;
}
}
int wall_check(t_jinx *p, int keycode, int x, int y)
{
static int i;
static int j;
i = y / 80;
j = x / 80;
if (keycode == 13 || keycode == 126)
if (p->dmap[i - 1][j] == '1')
return (0);
if (keycode == 1 || keycode == 125)
if (p->dmap[i + 1][j] == '1')
return (0);
if (keycode == 0 || keycode == 123)
if (p->dmap[i][j - 1] == '1')
return (0);
if (keycode == 2 || keycode == 124)
if (p->dmap[i][j + 1] == '1')
return (0);
return (1);
}
t_jinx sub_main(t_jinx *p, int argc, char **argv)
{
int i;
int j;
i = 0;
map_check(argc, argv);
p->dmap = mapi(argv);
real_check(p);
check_newlines(p);
check_components2(p);
check_components(p);
while (p->dmap[i])
{
j = 0;
while (p->dmap[i][j])
j++;
i++;
}
j = ft_strlen(p->dmap[0]) - 1;
walls_x(p, i, j);
walls_y(p, i, j);
p->mlx_ptr = mlx_init();
p->win_ptr = mlx_new_window(p->mlx_ptr, j * 80, i * 80, "so_long");
return (*p);
}