-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_destroy_map.c
95 lines (88 loc) · 3.07 KB
/
create_destroy_map.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_destroy_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/17 14:04:00 by vsimeono #+# #+# */
/* Updated: 2022/03/21 19:32:04 by vsimeono ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
/* Freeing the Allocated Memory for Linked List and for Graphical Interface */
int finish(t_long *arch)
{
free_list(&arch->lines);
mlx_destroy_window(arch->mlx, arch->mlx_win);
write(1, "You have Closed the Game!\n", 26);
exit(0);
}
/* Returning Error Message, Freeing Memory, Terminating Game Window */
int error(t_long *arch)
{
write(1, "Error,\nMap is Wack!", 19);
free_list(&arch->lines);
exit(0);
}
/* Returning Error Message, Freeing Memory, Terminating Game Window */
int error_arg()
{
write(1, "Error,\neither Invalid Argument or Invalid Map", 44);
exit(0);
}
/* Creating the Visual Map */
void create_visual_map(t_long *arch)
{
t_list *temp;
char *line;
int i;
i = 0;
arch->img.point_x = 0;
arch->img.point_y = 0;
temp = arch->lines;
while (temp)
{
line = temp->line;
while (line[i] && line[i] != '\n')
{
load_assests(arch, line[i], arch->img.point_x, arch->img.point_y);
i++;
arch->img.point_x += 48;
}
temp = temp->next;
arch->img.point_x = 0;
arch->img.point_y += 48;
i = 0;
}
}
/* Loading Pictures as the Pixels for the Graphical Map
according to their Corresponding Lettter or Number */
void load_assests(t_long *arch, char c, int x, int y)
{
if (c == '1')
arch->img.img = mlx_xpm_file_to_image(arch->mlx, \
"./data/red_walls.xpm", &arch->img.size_x, &arch->img.size_y);
else if (c == 'P')
{
arch->img.img = mlx_xpm_file_to_image(arch->mlx, \
"./data/space.xpm", &arch->img.size_x, &arch->img.size_y);
arch->img.img = mlx_xpm_file_to_image(arch->mlx, \
"./data/sun_resized.xpm", &arch->img.size_x, &arch->img.size_y);
}
else if (c == 'E')
arch->img.img = mlx_xpm_file_to_image(arch->mlx, \
"./data/exit_x.xpm", &arch->img.size_x, &arch->img.size_y);
else if (c == 'C')
{
arch->img.img = mlx_xpm_file_to_image(arch->mlx, \
"./data/space.xpm", &arch->img.size_x, &arch->img.size_y);
arch->img.img = mlx_xpm_file_to_image(arch->mlx, \
"./data/heart.xpm", &arch->img.size_x, &arch->img.size_y);
}
else
arch->img.img = mlx_xpm_file_to_image(arch->mlx, \
"./data/space.xpm", &arch->img.size_x, &arch->img.size_y);
mlx_put_image_to_window(arch->mlx, arch->mlx_win, arch->img.img, x, y);
mlx_destroy_image(arch->mlx, arch->img.img);
}