-
Notifications
You must be signed in to change notification settings - Fork 1
/
enemy.c
95 lines (88 loc) · 2.07 KB
/
enemy.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* enemy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: majjig <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/12 00:55:54 by majjig #+# #+# */
/* Updated: 2021/12/12 00:57:07 by majjig ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_swap(char *c1, char *c2)
{
*c2 = ENEMY;
*c1 = EMPTY;
}
static int left_right(t_mlx *mlx, int x, int y, char *where)
{
if (*where == 'R')
{
if (mlx->map[y + 1][x + 1] == PLAYER)
mlx_loop_hook(mlx->mlx, &lose_page, mlx);
else if (mlx->map[y + 1][x + 1] != EMPTY)
{
*where = 'L';
return (0);
}
else
return (ft_swap(&mlx->map[y][x], &mlx->map[y + 1][x + 1]), 0);
}
if (mlx->map[y - 1][x - 1] == PLAYER)
mlx_loop_hook(mlx->mlx, &lose_page, mlx);
else if (mlx->map[y - 1][x - 1] != EMPTY)
{
*where = 'R';
return (0);
}
ft_swap(&mlx->map[y][x], &mlx->map[y - 1][x - 1]);
return (0);
}
int enemy_move(t_mlx *mlx)
{
int x;
int y;
static char where = 'R';
y = -1;
while (mlx->map[++y])
{
x = -1;
while (mlx->map[y][++x])
{
if (mlx->map[y][x] == ENEMY)
{
left_right(mlx, x, y, &where);
return (0);
}
}
}
return (0);
}
void enemy_pos(t_mlx *mlx)
{
static int is = 1;
int x;
int y;
y = 0;
x = 0;
if (is)
{
while (mlx->map[y])
{
x = 0;
while (mlx->map[y][x])
{
if (mlx->map[y][x] == EMPTY)
{
mlx->map[y][x] = ENEMY;
is = 0;
return ;
}
x++;
}
y++;
}
}
enemy_move(mlx);
}