-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_v3.c
124 lines (116 loc) · 3.23 KB
/
init_v3.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_v3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aqadil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/07 15:49:36 by aqadil #+# #+# */
/* Updated: 2022/06/11 19:36:25 by aqadil ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void open_textures(t_data *mlx)
{
mlx->t_path = mlx->world->north_texure;
mlx->ts_path = mlx->world->south_texure;
mlx->te_path = mlx->world->east_texure;
mlx->tw_path = mlx->world->west_texure;
mlx->door_path = "./textures/door.xpm";
}
void read_loading(t_data *mlx)
{
mlx->press_img = mlx_xpm_file_to_image(mlx->mlx,
"./textures/press.xpm", &mlx->press_w, &mlx->press_h);
if (mlx->press_img == NULL)
{
printf("Error press image is invalid\n");
exit(0);
}
mlx->press_addr = mlx_get_data_addr(mlx->press_img,
&mlx->bits_per_pixel, &mlx->press_line_length, &mlx->press_endian);
if (mlx->press_addr == NULL)
{
printf("Error press image is invalid\n");
exit(0);
}
mlx->loading_img = mlx_new_image(mlx->mlx, mlx->loading_w, mlx->loading_h);
if (mlx->loading_img == NULL)
{
printf("Error loading image is invalid\n");
exit(0);
}
mlx->loading_addr = mlx_get_data_addr(mlx->loading_img,
&mlx->loading_bits_per_pixel,
&mlx->loading_line_length, &mlx->loading_endian);
if (mlx->loading_addr == NULL)
exit(printf("Error loading image is invalid\n"));
}
void read_home_image(t_data *mlx)
{
mlx->home_img = mlx_xpm_file_to_image(mlx->mlx,
"./textures/CUB3d.xpm", &mlx->home_w, &mlx->home_h);
if (mlx->home_img == NULL)
{
printf("error: invalid home image\n");
exit(0);
}
mlx->home_addr = mlx_get_data_addr(mlx->home_img,
&mlx->bits_per_pixel, &mlx->home_line_length, &mlx->home_endian);
if (mlx->home_addr == NULL)
{
printf("error: invalid home image\n");
exit(0);
}
read_loading(mlx);
}
int get_player_direction(t_data *mlx)
{
int i;
int j;
i = 0;
j = 0;
while (i < mlx->map_y)
{
j = 0;
while (j < mlx->map_x)
{
if (mlx->world->map[i][j] == NORTH)
mlx->pa = 90;
if (mlx->world->map[i][j] == EAST)
mlx->pa = 0;
if (mlx->world->map[i][j] == SOUTH)
mlx->pa = 270;
if (mlx->world->map[i][j] == WEST)
mlx->pa = 180;
j++;
}
i++;
}
return (0);
}
void draw_loading(t_data *mlx)
{
int i;
int j;
i = 0;
j = 0;
while (mlx->loading_i < 1)
{
while (mlx->loading_j < mlx->loading_w)
{
my_mlx_pixel_put_loading(mlx, mlx->loading_j,
mlx->loading_i, 0x00FFFFFF);
mlx->loading_j++;
if (mlx->loading_j % 2 == 0)
break ;
}
if (mlx->loading_j >= mlx->loading_w - 1)
{
mlx->loading_i++;
mlx->isloadingdone = 1;
}
if (mlx->loading_j % 2 == 0)
break ;
}
}