-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextures.c
More file actions
113 lines (105 loc) · 3.19 KB
/
textures.c
File metadata and controls
113 lines (105 loc) · 3.19 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
102
103
104
105
106
107
108
109
110
111
112
113
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* textures.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamir <mamir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/05 21:53:53 by mamir #+# #+# */
/* Updated: 2024/05/21 09:54:12 by mamir ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_put_exit(t_data *data)
{
int i;
int j;
i = 0;
while (i < data->map_dim[0])
{
j = 0;
while (j < data->map_dim[1])
{
if (data->map[i][j] == 'E')
{
if (all_collected(data))
mlx_put_image_to_window(data->mlx, data->win, data->open, j
* 45, i * 45);
else
mlx_put_image_to_window(data->mlx, data->win, data->exit, j
* 45, i * 45);
}
if (data->map[i][j] == 'C')
mlx_put_image_to_window(data->mlx, data->win, data->colectible,
j * 45, i * 45);
j++;
}
i++;
}
}
void ft_put_textures(t_data *data)
{
int i;
int j;
ft_init_textures(data);
i = 0;
while (i < data->map_dim[0])
{
j = 0;
while (j < data->map_dim[1])
{
mlx_put_image_to_window(data->mlx, data->win, data->floor, j * 45, i
* 45);
ft_put_exit(data);
if (data->map[i][j] == '1')
mlx_put_image_to_window(data->mlx, data->win, data->wall, j
* 45, i * 45);
if (data->map[i][j] == 'P')
mlx_put_image_to_window(data->mlx, data->win, data->player, j
* 45, i * 45);
j++;
}
i++;
}
}
void ft_init_textures(t_data *data)
{
data->floor = mlx_xpm_file_to_image(data->mlx, "./textures/wood.xpm",
&data->width, &data->height);
check_xpm(data->floor);
data->wall = mlx_xpm_file_to_image(data->mlx, "./textures/wall3.xpm",
&data->width, &data->height);
check_xpm(data->wall);
data->player = mlx_xpm_file_to_image(data->mlx, "./textures/king.xpm",
&data->width, &data->height);
check_xpm(data->player);
data->colectible = mlx_xpm_file_to_image(data->mlx,
"./textures/bomb.xpm",
&data->width,
&data->height);
check_xpm(data->colectible);
data->exit = mlx_xpm_file_to_image(data->mlx, "./textures/door2.xpm",
&data->width, &data->height);
check_xpm(data->exit);
data->open = mlx_xpm_file_to_image(data->mlx, "./textures/exit2.xpm",
&data->width, &data->height);
check_xpm(data->open);
}
int ft_exit(t_data *data)
{
mlx_destroy_window(data->mlx, data->win);
write(1, "Closed!\n", 9);
exit(0);
}
void ft_start_game(t_data *data)
{
data->mlx = mlx_init();
data->win = mlx_new_window(data->mlx, data->map_dim[1] * 45,
data->map_dim[0] * 45, "so_long");
ft_put_textures(data);
data->moves = 0;
printf("moves: %d\n", data->moves);
mlx_hook(data->win, 02, 0, ft_keys, data);
mlx_hook(data->win, 17, 0, ft_exit, data);
mlx_loop(data->mlx);
}