-
Notifications
You must be signed in to change notification settings - Fork 3
/
map.c
58 lines (54 loc) · 2.06 KB
/
map.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tblaase <tblaase@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/06 12:32:53 by tblaase #+# #+# */
/* Updated: 2021/12/08 16:18:08 by tblaase ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_window_size(t_data *data, char **argv)
/* will find the window size and check for some errors */
{
int fd;
fd = open(argv[1], O_RDONLY);
if (fd < 0)
{
perror("Error\nInvalid map_path/map\n");
exit(EXIT_FAILURE);
}
if (ft_strnstr(argv[1], ".ber", ft_strlen(argv[1])) == NULL)
{
printf("Error\nmap has to be .ber\n");
exit(EXIT_FAILURE);
}
data->size_x = (ft_line_length(fd) * IMG_W);
data->size_y = (ft_count_lines(fd, data->size_x, IMG_W) * IMG_H);
}
void ft_create_map(t_data *data)
/* will fill the map with the corresponding images */
{
data->map->x = 0;
data->map->y = 0;
while (data->map->y < (data->size_y / IMG_H))
{
if (data->map->map[data->map->y][data->map->x] == 'P')
ft_put_player(data);
else if (data->map->map[data->map->y][data->map->x] == '1')
ft_put_object(data, "./textures/wall.xpm");
else if (data->map->map[data->map->y][data->map->x] == 'C')
ft_put_object(data, "./textures/collectable.xpm");
else if (data->map->map[data->map->y][data->map->x] == 'E')
ft_put_object(data, "./textures/exit.xpm");
if (data->map->x < (data->size_x / IMG_W))
data->map->x++;
else
{
data->map->y++;
data->map->x = 0;
}
}
}