-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.c
More file actions
92 lines (84 loc) · 2.24 KB
/
check.c
File metadata and controls
92 lines (84 loc) · 2.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rahidalg <rahidalg@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/25 11:09:22 by rahidalg #+# #+# */
/* Updated: 2024/12/25 11:09:24 by rahidalg ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
char check_movement(t_mlx_data *data, int pos_x, int pos_y)
{
int i;
char id;
i = 0;
while (data->game.map[i].id != '\0')
{
if (data->game.map[i].pos_x == pos_x)
{
if (data->game.map[i].pos_y == pos_y)
{
id = data->game.map[i].id;
if (id == 'C')
data->game.map[i].id = '0';
return (id);
}
}
i++;
}
return ('\0');
}
int check_coins(t_mlx_data *data)
{
if (data->counter == data->coins)
open_door(data);
return (0);
}
int map_handler(int player_count, int coin_count, int door_count)
{
if (player_count <= 0 || player_count > 1)
{
ft_printf("Error\nThe map must have one player instance!\n");
return (0);
}
else if (coin_count <= 0)
{
ft_printf("Error\nThe map must have at least one coin!\n");
return (0);
}
else if (door_count <= 0 || door_count > 1)
{
ft_printf("Error\nThe map must have one exit door instance!\n");
return (0);
}
return (1);
}
void check_map_size(int *x, int *map_width, int *error)
{
int zero;
zero = 0;
if (*map_width == 0)
{
*map_width = *x;
}
else if (*x != *map_width)
{
*error = 1;
}
*x = zero;
}
int save_xpm(char *directory, t_mlx_data *data, t_xpm *xpm)
{
xpm->ptr = mlx_xpm_file_to_image(data->mlx_ptr,
directory, &xpm->width, &xpm->height);
if (xpm->ptr == NULL)
{
mlx_destroy_display(data->mlx_ptr);
free(data->mlx_ptr);
return (0);
}
return (1);
}