-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.c
More file actions
109 lines (101 loc) · 2.27 KB
/
game.c
File metadata and controls
109 lines (101 loc) · 2.27 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* game.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamir <mamir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/05 19:12:49 by mamir #+# #+# */
/* Updated: 2024/05/16 14:48:57 by mamir ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int all_collected(t_data *data)
{
int c;
int i;
int j;
i = 0;
c = 0;
while (i < data->map_dim[0])
{
j = 0;
while (j < data->map_dim[1])
{
if (data->map[i][j] == 'C')
c++;
j++;
}
i++;
}
if (c == 0)
return (1);
return (0);
}
void ft_player_position(t_data *data)
{
int i;
int j;
i = 0;
data->px = 0;
data->py = 0;
while (i < data->map_dim[0])
{
j = 0;
while (j < data->map_dim[1])
{
if (data->map[i][j] == 'P')
{
data->px = j;
data->py = i;
}
if (data->map[i][j] == 'E')
{
data->ex = j;
data->ey = i;
}
j++;
}
i++;
}
}
int ft_right_left(int keycode, t_data *data)
{
if (keycode == 2 || keycode == 124)
{
ft_move_right(data);
mlx_clear_window(data->mlx, data->win);
ft_put_textures(data);
}
if (keycode == 0 || keycode == 123)
{
ft_move_left(data);
mlx_clear_window(data->mlx, data->win);
ft_put_textures(data);
}
return (0);
}
int ft_up_down(int keycode, t_data *data)
{
if (keycode == 13 || keycode == 126)
{
ft_move_up(data);
mlx_clear_window(data->mlx, data->win);
ft_put_textures(data);
}
if (keycode == 1 || keycode == 125)
{
ft_move_down(data);
mlx_clear_window(data->mlx, data->win);
ft_put_textures(data);
}
return (0);
}
int ft_keys(int keycode, t_data *data)
{
ft_right_left(keycode, data);
ft_up_down(keycode, data);
if (keycode == 53)
ft_exit(data);
return (0);
}