-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitializer.c
64 lines (59 loc) · 2.43 KB
/
initializer.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* initializer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: szerisen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 19:07:33 by szerisen #+# #+# */
/* Updated: 2023/04/20 20:53:25 by szerisen ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
static void ft_initializer_help(t_data *data)
{
char *relative_path;
int img_width;
int img_height;
relative_path = "./textures/ship_left.xpm";
data->img->player_left = mlx_xpm_file_to_image(data->mlx, relative_path,
&img_width, &img_height);
relative_path = "./textures/ship_down.xpm";
data->img->player_down = mlx_xpm_file_to_image(data->mlx, relative_path,
&img_width, &img_height);
relative_path = "./textures/ship_right.xpm";
data->img->player_right = mlx_xpm_file_to_image(data->mlx, relative_path,
&img_width, &img_height);
if (!data->img->player_left || !data->img->player_down)
handle_error(data, "Error\nOne of Player files not found", 1);
if (!data->img->player_right)
handle_error(data, "Error\nPlayer right file not found", 1);
relative_path = "./textures/background.xpm";
data->img->background = mlx_xpm_file_to_image(data->mlx, relative_path,
&img_width, &img_height);
if (!data->img->background)
handle_error(data, "Error\nbackground file not found", 1);
}
void ft_initializer(t_data *data, t_map *map)
{
char *relative_path;
int img_width;
int img_height;
t_img *img;
data->map = map;
img = malloc(sizeof(t_img));
if (!img)
{
perror("Error\nmalloc failed\n");
exit(EXIT_FAILURE);
}
data->img = img;
relative_path = "textures/ship_up.xpm";
data->img->player_up = mlx_xpm_file_to_image(data->mlx, relative_path,
&img_width, &img_height);
if (!data->img->player_up)
handle_error(data, "Error\nPlayer up file not found", 1);
ft_initializer_help(data);
data->counter = 0;
data->collected = 0;
}