-
Notifications
You must be signed in to change notification settings - Fork 0
/
cub3d.h
executable file
·372 lines (324 loc) · 7.2 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hgrissen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/29 14:19:33 by hgrissen #+# #+# */
/* Updated: 2021/03/06 17:16:28 by hgrissen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <stdio.h>
# include <stdlib.h>
# include <mlx.h>
# include <math.h>
# include "GNL/get_next_line.h"
# include "basic/libft.h"
# include <signal.h>
# define FLT_MAX 3.402823e+38
# define P_RADIUS 1
# define MINI_MAP 12
# define TILE_SIZE 128
# define FOV 1.0472
# define COL_DIS 10
# define DMG 20
# define CROUCH 200
# define LGHT 200
# define PLAYER_MOVE_SPEED 20
# define PLAYER_TURN_SPEED 0.05
# define C_EMPTY 0x001B112C
# define C_WALL 0x00721F7A
# define C_SPRITE 0x00B63F82
# define C_PLAYER 0x006EBDEA
# define C_RAY 0x00FFFFFF
# define A_KEY 0
# define D_KEY 2
# define S_KEY 1
# define W_KEY 13
# define ESC_KEY 53
# define L_ARR 123
# define R_ARR 124
# define U_ARR 126
# define D_ARR 125
# define SPACE 49
# define TAB 48
int g_hmini;
int g_wmini;
int g_post;
int g_healthmax;
int g_dmg;
int g_damageable;
int g_x;
int g_is_down;
int g_is_up;
int g_is_right;
int g_is_left;
unsigned int g_red;
unsigned int g_green;
unsigned int g_blue;
int *g_spad;
float g_sz;
int g_h;
int g_v;
float g_inc;
float g_str_ang;
int g_xc;
int g_yc;
int g_i;
int g_j;
int g_tmp;
int g_pid;
typedef struct s_prms {
int inc;
int w;
int h;
int fr;
int fg;
int fb;
int cr;
int cg;
int cb;
char *no;
char *so;
char *we;
char *ea;
char *s;
char *str;
char **map;
int nwlcnt;
int lnglin;
} t_prm;
t_prm g_prm;
typedef struct s_errs {
int num_prm;
int dbl_inc;
int elm_inv;
int plr_cnt;
int map_bgn;
int inv_nwl;
int map_inv;
int map_spc;
int map_open;
} t_err;
t_err g_err;
typedef struct s_img {
void *img;
char *addr;
int bpp;
int ll;
int end;
} t_img;
t_img g_img;
t_img g_so;
t_img g_ea;
t_img g_we;
t_img g_no;
t_img g_si;
typedef struct s_mlx {
void *mlx;
void *mlx_win;
} t_mlx;
t_mlx g_mlx;
typedef struct s_player {
float x;
float y;
char spawn_dir;
float hor_dir;
float vir_dir;
float turndir;
double rotang;
float movespeed;
float turnspeed;
float hlfpi;
int iscrouch;
int crouch;
int ismap;
} t_player;
t_player g_p;
typedef struct s_rays {
float angle;
float hitx;
float hity;
float dist;
int hit_v;
int is_up;
int is_down;
int is_left;
int is_right;
} t_rays;
t_rays g_rays[10000];
typedef struct s_ray
{
float x_intercept;
float y_intercept;
float ystep;
float xstep;
int found_horzhit;
int found_verthit;
float horz_hitx;
float vert_hitx;
float vert_hity;
float horz_hity;
float nhx;
float nvx;
float nvy;
float nhy;
float xcheck;
float ycheck;
float hdist;
float vdist;
} t_ray;
t_ray g_r;
typedef struct s_wall
{
float perp_dist;
float distproj;
float projwallh;
int strip_h;
int walltop;
int wallbot;
int xoff;
int yoff;
int dist;
} t_wall;
t_wall g_col;
typedef struct s_bmp_header
{
char type[2];
u_int32_t filesize;
u_int16_t reserved1;
u_int16_t reserved2;
u_int32_t pxdataoff;
u_int32_t headersize;
int32_t width;
int32_t height;
u_int16_t planes;
u_int16_t bpp;
u_int32_t compression;
u_int32_t imagesize;
int32_t xpermeter;
int32_t ypermeter;
u_int32_t totalcolors;
u_int32_t importantcolors;
} t_bmp_file;
t_bmp_file g_bmp;
int g_save;
typedef struct s_prite
{
float x;
float xof;
float y;
float yof;
float dist;
float size;
} t_sprite;
t_sprite *g_sp;
int g_s_count;
int g_save;
char *g_file;
void get_file(char *argv[]);
void prm_init();
void err_init(void);
void treat_file(char *line);
void get_map(char *line);
void routing(char *line);
void get_res(char *line);
void get_rgb(char *line, int f);
int prm_count(int num, int cnt, int f);
void get_path(char *line, int c);
void path_rout(char *s, int c);
int is_map(int c);
int is_player(int c);
int is_srndbl(int c);
int is_notspace(int c);
void addline(char *line);
void lng_lin();
void nwl_cnt();
void map_fil();
void spc_fil();
void build_map();
void spc2wal();
float spawn_direction();
void arguments_errors(int error);
void print_errs();
int ch_err();
int rgb_err();
int res_err();
int pat_err();
int res_out();
int rgb_out();
void ch_fil_err();
void map_err();
void map_chk_opn();
int white_space(char *line);
void render_flr_cei();
void walls3d(void);
int render();
void canvas_init();
void player_init();
void render_player();
void draw_player(int x, int y, int clr);
void draw_ray();
void render_map();
void circlebres(int xc, int yc, int r, int clr);
void draw_rect(int x, int y, int clr);
void draw_ver(int x, int start, int end, int clr);
void my_mlx_pixel_put(t_img *data, int x, int y, int color);
int shade(int i, char x);
unsigned int shadow(unsigned int color, int col);
int shadedcolor(int r, int g, int b, float percent);
void texture_error(int error);
void init_textures(void);
int assign_textures(int i);
void ray_norm(int i);
void draw_sprite(int id);
void sprites_conf(void);
void sprite_sort(void);
void init_sprites(void);
void save_bmp(void);
void screenshot();
float clamp_clr(float clr);
int get_r(int trgb);
int get_g(int trgb);
int get_b(int trgb);
int rgb_to_int(int t, int r, int g, int b);
void cast_rays(void);
int update();
int key_released(int keycode);
int key_pressed(int keycode);
int ft_quit(void);
void move();
void collision(float newx, float newy);
void player_pos();
int is_corner(int x, int y);
char side_hit(float x, float y);
int is_wall(float x, float y);
int is_sprite(float x, float y);
float clamp_percent(float percent);
float normalize_ang(float ang);
float d2r(float ang);
float dis_pts(float x1, float y1, float x2, float y2);
float deg(float x);
void print_struct_elemts();
void printmap();
int res_invalid(int i, char *line);
void set_color(char f, char rgb, int num);
int skip_digit(char *line);
int map_is_last();
void bonus_events(int keycode, int pr);
void wasd_r_events(int keycode);
void arrow_r_events(int keycode);
void wasd_p_events(int keycode);
void arrow_p_events(int keycode);
void play_m();
void play_damage_sfx();
void health_bg(void);
void health_bar(void);
void red_post();
#endif