-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_imgs.c
More file actions
101 lines (92 loc) · 3.67 KB
/
load_imgs.c
File metadata and controls
101 lines (92 loc) · 3.67 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
93
94
95
96
97
98
99
100
101
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* load_imgs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nosahimi <nosahimi@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/21 22:03:16 by nosahimi #+# #+# */
/* Updated: 2025/03/27 22:33:57 by nosahimi ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void if_img_load_fail(t_game *game)
{
if (!game->img_grass || !game->img_castle || !game->img_player_a1
|| !game->img_player_s1 || !game->img_player_d1 || !game->img_player_w1
|| !game->img_player_a || !game->img_player_s || !game->img_player_d
|| !game->img_player_w || !game->img_wall || !game->img_sheep)
{
morgan_freeman(game, "img");
exit(1);
}
}
void load_player_imgs(t_game *game)
{
int size;
size = IMG_SIZE;
game->img_player_a = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerA.xpm", &size, &size);
game->img_player_d = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerD.xpm", &size, &size);
game->img_player_s = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerS.xpm", &size, &size);
game->img_player_w = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerW.xpm", &size, &size);
}
void load_player_n_castle_imgs(t_game *game)
{
int size;
size = IMG_SIZE;
game->img_player_a1 = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerA1.xpm", &size, &size);
game->img_player_d1 = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerD1.xpm", &size, &size);
game->img_player_s1 = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerS1.xpm", &size, &size);
game->img_player_w1 = mlx_xpm_file_to_image(game->mlx,
"textures/player/playerW1.xpm", &size, &size);
}
void load_imgs(t_game *game)
{
int size;
size = IMG_SIZE;
game->img_grass = mlx_xpm_file_to_image(game->mlx,
"textures/env/grass.xpm", &size, &size);
game->img_wall = mlx_xpm_file_to_image(game->mlx,
"textures/env/wall.xpm", &size, &size);
game->img_castle = mlx_xpm_file_to_image(game->mlx,
"textures/env/castle.xpm", &size, &size);
game->img_sheep = mlx_xpm_file_to_image(game->mlx,
"textures/collectable/sheep1.xpm", &size, &size);
load_player_imgs(game);
load_player_n_castle_imgs(game);
if_img_load_fail(game);
}
void destroy_imgs(t_game *game)
{
if (game->img_player_a1)
mlx_destroy_image(game->mlx, game->img_player_a1);
if (game->img_castle)
mlx_destroy_image(game->mlx, game->img_castle);
if (game->img_grass)
mlx_destroy_image(game->mlx, game->img_grass);
if (game->img_sheep)
mlx_destroy_image(game->mlx, game->img_sheep);
if (game->img_wall)
mlx_destroy_image(game->mlx, game->img_wall);
if (game->img_player_s1)
mlx_destroy_image(game->mlx, game->img_player_s1);
if (game->img_player_d1)
mlx_destroy_image(game->mlx, game->img_player_d1);
if (game->img_player_w1)
mlx_destroy_image(game->mlx, game->img_player_w1);
if (game->img_player_a)
mlx_destroy_image(game->mlx, game->img_player_a);
if (game->img_player_s)
mlx_destroy_image(game->mlx, game->img_player_s);
if (game->img_player_d)
mlx_destroy_image(game->mlx, game->img_player_d);
if (game->img_player_w)
mlx_destroy_image(game->mlx, game->img_player_w);
}