-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.c
79 lines (73 loc) · 2.44 KB
/
tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rboudwin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/20 12:06:56 by rboudwin #+# #+# */
/* Updated: 2023/12/27 17:16:39 by rboudwin ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void collect_chest(t_map *map, t_img *img, mlx_t *mlx)
{
map->curr_col++;
ft_printf("You now have %d/%d chests.\n", map->curr_col, map->collectibles);
mlx_image_to_window(mlx, img->img_cc,
map->charx * map->tile_sq, map->chary * map->tile_sq);
map->grid[map->chary][map->charx] = 'c';
if (map->curr_col == map->collectibles)
{
map->grid[map->exity][map->exitx] = 'e';
mlx_delete_image(mlx, img->img_e);
mlx_image_to_window(mlx, img->img_eo,
map->exitx * map->tile_sq, map->exity * map->tile_sq);
}
mlx_delete_image(mlx, img->img_m);
img->img_m = mlx_texture_to_image(mlx, img->txt_m);
mlx_resize_image(img->img_m, map->tile_sq, map->tile_sq);
mlx_image_to_window(mlx, img->img_m,
map->charx * map->tile_sq, map->chary * map->tile_sq);
}
int report_bad_border(void)
{
ft_printf("ERROR: The map does not have obstacles across all edges\n");
return (0);
}
int report_map_count_error(t_map *map)
{
ft_printf("ERROR: Invalid map- starts: %d exits: %d collectibles: %d\n",
map->starts, map->exits, map->collectibles);
ft_printf("You must have exactly one start, one exit");
ft_printf(" and at least one collectible\n");
return (0);
}
void free_grid(t_map *map, int flag)
{
if (flag == 1)
{
map->y = 0;
while (map->grid[map->y] != NULL)
{
free(map->grid[map->y]);
map->y++;
}
free(map->grid);
}
if (flag == 2)
{
map->y = 0;
while (map->grid2[map->y] != NULL)
{
free(map->grid2[map->y]);
map->y++;
}
free(map->grid2);
}
}
void resolve_collectible(t_map *map, int y, int x)
{
map->curr_col--;
map->grid2[y][x] = 'X';
}