-
Notifications
You must be signed in to change notification settings - Fork 0
/
moves.c
96 lines (91 loc) · 2.66 KB
/
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
#include "header/so_long.h"
int ft_close_window(t_Mainstuct *main_struct)
{
if (main_struct->img->window != NULL)
mlx_destroy_window(main_struct->img->mlx, main_struct->img->window);
exit (0);
}
void ft_move_up(t_Mainstuct *m_s)
{
if (m_s->map_info->map[m_s->img->player_y - 1][m_s->img->player_x] != '1')
{
if (m_s->map_info->map[m_s->img->player_y - 1][m_s->img->player_x]
== 'C')
{
m_s->map_info->map[m_s->img->player_y - 1][m_s->img->player_x]
= '0';
m_s->map_info->collected += 1;
}
m_s->img->player_y -= 1;
m_s->map_info->steps += 1;
printf("Steps = %d\n", m_s->map_info->steps);
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x]
== 'E')
if (m_s->map_info->collected == m_s->map_info->items)
ft_win_game(m_s);
}
ft_create_basic_image(m_s->map_info, m_s->img);
}
void ft_move_down(t_Mainstuct *m_s)
{
if (m_s->map_info->map[m_s->img->player_y + 1][m_s->img->player_x] != '1')
{
if (m_s->map_info->map[m_s->img->player_y + 1][m_s->img->player_x]
== 'C')
{
m_s->map_info->map[m_s->img->player_y + 1][m_s->img->player_x]
= '0';
m_s->map_info->collected += 1;
}
m_s->img->player_y += 1;
m_s->map_info->steps += 1;
printf("Steps = %d\n", m_s->map_info->steps);
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x]
== 'E')
if (m_s->map_info->collected == m_s->map_info->items)
ft_win_game(m_s);
}
ft_create_basic_image(m_s->map_info, m_s->img);
}
void ft_move_left(t_Mainstuct *m_s)
{
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x - 1] != '1')
{
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x - 1]
== 'C')
{
m_s->map_info->map[m_s->img->player_y][m_s->img->player_x - 1]
= '0';
m_s->map_info->collected += 1;
}
m_s->img->player_x -= 1;
m_s->map_info->steps += 1;
printf("Steps = %d\n", m_s->map_info->steps);
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x]
== 'E')
if (m_s->map_info->collected == m_s->map_info->items)
ft_win_game(m_s);
}
ft_create_basic_image(m_s->map_info, m_s->img);
}
void ft_move_right(t_Mainstuct *m_s)
{
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x + 1] != '1')
{
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x + 1]
== 'C')
{
m_s->map_info->map[m_s->img->player_y][m_s->img->player_x + 1]
= '0';
m_s->map_info->collected += 1;
}
m_s->map_info->steps += 1;
printf("Steps = %d\n", m_s->map_info->steps);
m_s->img->player_x += 1;
if (m_s->map_info->map[m_s->img->player_y][m_s->img->player_x]
== 'E')
if (m_s->map_info->collected == m_s->map_info->items)
ft_win_game(m_s);
}
ft_create_basic_image(m_s->map_info, m_s->img);
}