-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_enemy_moves.c
87 lines (81 loc) · 2.34 KB
/
ft_enemy_moves.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_enemy_moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbourziq <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/12 21:54:55 by sbourziq #+# #+# */
/* Updated: 2024/03/12 21:55:01 by sbourziq ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_move_enemy(t_mlx *data, int i, int j, int x)
{
if (data->str[i][j + 1] == 'P' && x == 1)
ft_print_lost(data);
if (data->str[i][j - 1] == 'P' && x == 2)
ft_print_lost(data);
}
void ft_speed_right(t_mlx *data, int i, int j)
{
ft_move_enemy(data, i, j, 1);
(data->count_enemy_left)++;
data->str[i][j] = '0';
data->str[i][j + 1] = 'N';
if (data->count_enemy_left == 6)
data->count_enemy_left = 0;
}
void ft_speed_left(t_mlx *data, int i, int j)
{
ft_move_enemy(data, i, j, 2);
(data->count_enemy_left)--;
data->str[i][j] = '0';
data->str[i][j - 1] = 'N';
if (data->count_enemy_left == -7)
data->count_enemy_left = -1;
}
void ft_enemy_speed(t_mlx *data, int i, int j, int x)
{
if (data->count_enemy == 0 && x == 1)
{
if (data->str[i][j + 1] != '1' && data->str[i][j + 1] != 'C'
&& data->str[i][j + 1] != 'E')
ft_speed_right(data, i, j);
else
{
data->count_enemy = 1;
data->count_enemy_left = -1;
}
}
else if (data->count_enemy == 1 && x == 1)
{
if (data->str[i][j - 1] != '1' && data->str[i][j - 1] != 'C'
&& data->str[i][j - 1] != 'E')
ft_speed_left(data, i, j);
else
{
data->count_enemy = 0;
data->count_enemy_left = 0;
}
}
}
void loaction_enemy(t_mlx *data)
{
while (data->i < data->height - 1)
{
data->j = 0;
while (data->j < data->width)
{
if (data->str[data->i][data->j] == 'N')
{
data->x = 1;
break ;
}
(data->j)++;
}
if (data->x == 1)
break ;
(data->i)++;
}
}