-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.c
55 lines (51 loc) · 2.09 KB
/
image.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: matlopes <matlopes@student.42.rio> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/28 10:38:04 by matlopes #+# #+# */
/* Updated: 2023/11/28 10:38:06 by matlopes ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_free_images(t_game *game)
{
if (game->person.ref)
mlx_destroy_image(game->mlx, game->person.ref);
if (game->wall)
mlx_destroy_image(game->mlx, game->wall);
if (game->floor)
mlx_destroy_image(game->mlx, game->floor);
if (game->coin.ref)
mlx_destroy_image(game->mlx, game->coin.ref);
if (game->exit.ref)
mlx_destroy_image(game->mlx, game->exit.ref);
}
void ft_images(t_game *game)
{
game->person.ref = mlx_xpm_file_to_image(game->mlx,
"imgs/person.xpm", &game->x, &game->y);
game->wall = mlx_xpm_file_to_image(game->mlx,
"imgs/wall.xpm", &game->x, &game->y);
game->floor = mlx_xpm_file_to_image(game->mlx,
"imgs/floor.xpm", &game->x, &game->y);
game->coin.ref = mlx_xpm_file_to_image(game->mlx,
"imgs/coin.xpm", &game->x, &game->y);
game->exit.ref = mlx_xpm_file_to_image(game->mlx,
"imgs/exit.xpm", &game->x, &game->y);
if (!game->person.ref || !game->wall || !game->floor
|| !game->coin.ref || !game->exit.ref)
{
ft_free_images(game);
ft_error_free(game->map, NULL, "Failed to load images");
}
game->x = 50;
game->y = 50;
}
void ft_put_image(t_game *game, void *ref, int x, int y)
{
mlx_put_image_to_window(game->mlx, game->screen.ref,
ref, x * game->x, y * game->y);
}