-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_utils.c
More file actions
90 lines (83 loc) · 2.23 KB
/
main_utils.c
File metadata and controls
90 lines (83 loc) · 2.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aylaaouf <aylaaouf@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/11 08:37:21 by aylaaouf #+# #+# */
/* Updated: 2025/03/15 15:32:46 by aylaaouf ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void free_map(t_map *map)
{
int i;
if (!map)
return ;
if (map->map)
{
i = 0;
while (i < map->height)
{
if (map->map[i])
free(map->map[i]);
i++;
}
free(map->map);
}
free(map);
}
void free_images(t_game *game)
{
if (!game || !game->mlx)
return ;
if (game->coin)
mlx_destroy_image(game->mlx, game->coin);
if (game->empty_space)
mlx_destroy_image(game->mlx, game->empty_space);
if (game->player)
mlx_destroy_image(game->mlx, game->player);
if (game->wall)
mlx_destroy_image(game->mlx, game->wall);
if (game->gate)
mlx_destroy_image(game->mlx, game->gate);
if (game->animation)
mlx_destroy_image(game->mlx, game->animation);
if (game->killer)
mlx_destroy_image(game->mlx, game->killer);
game->coin = NULL;
game->empty_space = NULL;
game->player = NULL;
game->wall = NULL;
game->gate = NULL;
game->animation = NULL;
game->killer = NULL;
}
void clean_game(t_game *game)
{
if (game->moves_count_str != NULL)
free(game->moves_count_str);
if (!game)
return ;
free_images(game);
if (game->mlx && game->win)
mlx_destroy_window(game->mlx, game->win);
if (game->mlx)
{
mlx_destroy_display(game->mlx);
free(game->mlx);
game->mlx = NULL;
}
free(game);
}
void ft_putchar_s(char c)
{
write(1, &c, 1);
}
void ft_putnbr_s(int nbr)
{
if (nbr >= 10)
ft_putnbr_s(nbr / 10);
ft_putchar_s((nbr % 10) + '0');
}