-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.h
219 lines (201 loc) · 4.93 KB
/
cub3d.h
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jtrancos <jtrancos@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/30 11:43:22 by jtrancos #+# #+# */
/* Updated: 2021/02/03 10:51:19 by jtrancos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include "mlx/mlx.h"
# include "mlx_linux/mlx.h"
# include "libft/libft.h"
# include "./utils/GNL/get_next_line.h"
# include <stdlib.h>
# include <math.h>
# include <fcntl.h>
# include <stdio.h>
# include <string.h>
# include <unistd.h>
# define MAX_SCREENWIDTH 2560
# define MAX_SCREENHEIGHT 1440
typedef struct s_keys
{
int w;
int a;
int s;
int d;
int left;
int right;
int esc;
} t_keys;
typedef struct s_player
{
float x;
float y;
float dir_x;
float dir_y;
float plane_x;
float plane_y;
float rotation;
float speed;
t_keys keys;
} t_player;
typedef struct s_map
{
char **map;
int height;
int width;
int inmap;
int barra_n;
} t_map;
typedef struct s_colour
{
int floor[3];
int sky[3];
int b;
} t_colour;
typedef struct s_ray
{
float camera_x;
float dir_x;
float dir_y;
int map_x;
int map_y;
float side_dist_x;
float side_dist_y;
float delta_dist_x;
float delta_dist_y;
float perpwalldist;
int step_x;
int step_y;
int hit;
int side;
int line_height;
} t_ray;
typedef struct s_img
{
void *img;
int *addr;
int bpp;
int line_len;
int endian;
} t_img;
typedef struct s_texture
{
int width;
int height;
char *path;
t_img img;
} t_texture;
typedef struct s_textures
{
t_texture sprite;
t_texture north;
t_texture east;
t_texture south;
t_texture west;
} t_textures;
typedef struct s_wall
{
t_texture texture;
int texture_x;
int x;
float draw_start;
float draw_end;
} t_wall;
typedef struct s_sprite
{
float map_x;
float map_y;
unsigned int color;
float dist;
float calc_x;
float calc_y;
float inv_det;
float trans_x;
float trans_y;
int spritescreen_x;
int sprite_h;
int sprite_w;
int drawstart_x;
int drawstart_y;
int drawend_x;
int drawend_y;
int tex_x;
int tex_y;
int d;
} t_sprite;
typedef struct s_bmp
{
char bmpheader[14];
char bmpinfo[40];
int screenshot;
} t_bmp;
typedef struct s_data
{
void *mlx;
void *win;
unsigned int rgb;
int blockx;
int blocky;
int blocklen;
int screen_width;
int screen_height;
int map_height;
int map_width;
int sprite_num;
float *zbuffer;
t_player player;
t_ray ray;
t_img img;
t_wall wall;
t_textures textures;
t_sprite *sprite;
t_map map;
t_colour colour;
t_bmp bmp;
} t_data;
int ft_isspace(int c);
void init_data(t_data *data);
int empty_line_end(char *line);
int read_file(t_data *data, const char *file);
int parse_resolution(t_data *data, char *line);
int parse_texture(t_data *data, int type, char *line);
int parse_colour(t_data *data, int type, char *line, int i);
int check_data(t_data *data);
int map_count(t_data *data, char *line);
int parse_map(t_data *data, int fd);
void flood_fill(t_data *data, int x, int y, int prev_number);
int check_player(t_data *data, char *line, int y);
void convert_map(t_data *data);
int handle_error(int type);
int colour_error(int type);
int map_error(int type);
int player_error(int type);
int tex_error(int type);
int res_error(int type);
int file_error(int type);
int check_extension(const char *file, char *ext);
void my_mlx_pixel_put(t_data *data, int x, int y, int color);
void assign_sprite(t_data *data);
void sort_sprites(t_data *data);
void draw_texture(t_data *data, t_wall wall, t_ray ray, int x);
void move_player(t_data *data);
void rotation_right(t_data *data);
void rotation_left(t_data *data);
int ft_close(t_data *data);
int ft_escape(int keycode, t_data *data);
int press_key(int keycode, t_data *data);
int release_key(int keycode, t_data *data);
void draw_sprite(t_data *data);
int raycasting(t_data *data);
void print_sky_wall_floor(t_data *data, int x);
int rgb_to_hex(int colour[3]);
int create_bmp(t_data *data);
int check_args(t_data *data, int argc, char **argv);
#endif