-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_trap_moves.c
106 lines (98 loc) · 3.15 KB
/
ft_trap_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_trap_moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rabustam <rabustam@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/15 23:22:56 by rabustam #+# #+# */
/* Updated: 2022/08/15 23:56:19 by rabustam ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int ft_move_trap_down(t_data *game, int i);
int ft_move_trap_left(t_data *game, int i);
int ft_move_trap_right(t_data *game, int i);
int ft_move_trap_up(t_data *game, int i);
int ft_move_trap(t_data *game);
int ft_move_trap_down(t_data *game, int i)
{
if (game->map.map[game->t_pos.y[i] + 1][game->t_pos.x[i]] == 'P'\
|| game->map.map[game->t_pos.y[i] + 1][game->t_pos.x[i]] == '0')
{
game->map.map[game->t_pos.y[i] + 1][game->t_pos.x[i]] = 'T';
game->map.map[game->t_pos.y[i]][game->t_pos.x[i]] = '0';
game->t_pos.y[i]++;
}
if (game->t_pos.y[i] == game->p_pos.y && \
game->t_pos.x[i] == game->p_pos.x)
ft_game_over(game);
return (0);
}
int ft_move_trap_left(t_data *game, int i)
{
if (game->map.map[game->t_pos.y[i]][game->t_pos.x[i] - 1] == 'P'\
|| game->map.map[game->t_pos.y[i]][game->t_pos.x[i] - 1] == '0')
{
game->map.map[game->t_pos.y[i]][game->t_pos.x[i] - 1] = 'T';
game->map.map[game->t_pos.y[i]][game->t_pos.x[i]] = '0';
game->t_pos.x[i]--;
}
else
ft_move_trap_down(game, i);
if (game->t_pos.y[i] == game->p_pos.y && \
game->t_pos.x[i] == game->p_pos.x)
ft_game_over(game);
return (0);
}
int ft_move_trap_right(t_data *game, int i)
{
if (game->map.map[game->t_pos.y[i]][game->t_pos.x[i] + 1] == 'P'\
|| game->map.map[game->t_pos.y[i]][game->t_pos.x[i] + 1] == '0')
{
game->map.map[game->t_pos.y[i]][game->t_pos.x[i] + 1] = 'T';
game->map.map[game->t_pos.y[i]][game->t_pos.x[i]] = '0';
game->t_pos.x[i]++;
}
else
ft_move_trap_left(game, i);
if (game->t_pos.y[i] == game->p_pos.y && \
game->t_pos.x[i] == game->p_pos.x)
ft_game_over(game);
return (0);
}
int ft_move_trap_up(t_data *game, int i)
{
if (game->map.map[game->t_pos.y[i] - 1][game->t_pos.x[i]] == 'P'\
|| game->map.map[game->t_pos.y[i] - 1][game->t_pos.x[i]] == '0')
{
game->map.map[game->t_pos.y[i] - 1][game->t_pos.x[i]] = 'T';
game->map.map[game->t_pos.y[i]][game->t_pos.x[i]] = '0';
game->t_pos.y[i]--;
}
else
ft_move_trap_right(game, i);
if (game->t_pos.y[i] == game->p_pos.y && \
game->t_pos.x[i] == game->p_pos.x)
ft_game_over(game);
return (0);
}
int ft_move_trap(t_data *game)
{
static int x;
int i;
if (x < 50000)
{
x++;
return (0);
}
i = 0;
while (game->t_pos.y[i])
{
ft_move_trap_up(game, i);
i++;
}
i = 0;
x = 0;
return (0);
}