-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.h
251 lines (236 loc) · 6.89 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* cub3d.h :+: :+: */
/* +:+ */
/* By: ksmorozo <[email protected]> +#+ */
/* +#+ */
/* Created: 2021/03/08 13:15:43 by ksmorozo #+# #+# */
/* Updated: 2021/07/27 15:12:23 by ksmorozo ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include "libft/libft.h"
# include <math.h>
# include <stdint.h>
# define KEY_A 0 //97
# define KEY_W 13 //119
# define KEY_S 1 //115
# define KEY_D 2 //100
# define KEY_ESC 53 //65307
# define KEY_LEFT 123 //65361
# define KEY_RIGHT 124 //65363
# define PI 3.14159265
# define TWO_PI 6.28318530
# define FOV_ANGLE 1.0471975500000001
# define WALL_STRIP_WIDTH 10
# define SCALE_FACTOR 0.3
# define TILE_SIZE 30
# define NUM_TEXTURES 6
# define NO_TEXTURE 0
# define SO_TEXTURE 1
# define WE_TEXTURE 2
# define EA_TEXTURE 3
# define SPRITE_TEXTURE 4
# define ANIMATION_TEX 5
# define ERROR -1
# define OK 1
# define EPSILON 0.2
# define TYPE_IDENTIFIERS 6
enum e_error
{
MALLOC = 1,
IDENTIFIER_ILLEGAL = 2,
WRONG_RES = 3,
MAP_ON_TOP = 4,
FILE_MISSING = 5,
RGB_INVALID = 6,
ARG_COUNT_WRONG = 7,
EXTENSION_INVALID = 8,
ZERO_RES = 9,
PLAYER_INVALID = 10,
MAP_INVALID = 11,
RGB_EXCEEDED = 12,
ZERO_TEXTURE = 13,
IDENTIFIERS = 14,
OPEN_ERROR = 15,
MLX_ERROR = 16,
} t_error;
typedef struct s_cub
{
long int x_res;
long int y_res;
char *no_texture;
char *so_texture;
char *we_texture;
char *ea_texture;
char *sp_texture;
int floor_colour[3];
int ceiling_colour[3];
int type_identifier_num;
t_list *map;
int contains_sprites;
} t_cub;
typedef struct s_window_settings
{
void *mlx;
void *img;
void *img_iter;
void *window;
void *addr;
int bits_per_pixel;
int line_length;
int endian;
} t_window_settings;
typedef struct s_player
{
float xpos;
float ypos;
float angle;
float walk_speed;
float turn_speed;
int turn_direction;
int walk_direction;
float sidewalk;
} t_player;
typedef struct s_wall
{
int wall_top_pixel;
int wall_bottom_pixel;
int wall_strip_height;
float proj_plane_distance;
float wall_height;
} t_wall;
typedef struct s_texture
{
void *img;
int img_width;
int img_height;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
} t_texture;
typedef struct s_sprite
{
float *x;
float *y;
float *distance;
float *angle;
int num;
int *visible;
float *top;
float *bottom;
float *screen_pos_x;
float *left_x;
float *right_x;
float height;
float width;
int animation_index;
} t_sprite;
typedef struct s_game
{
t_player *player;
t_wall *wall;
t_texture texture[NUM_TEXTURES];
t_sprite *sprite;
} t_game_state;
typedef struct s_ray
{
float ray_angle;
float wall_hit_x;
float wall_hit_y;
float horizontal_wall_hit_x;
float horizontal_wall_hit_y;
float horizontal_wall_hit;
float vertical_wall_hit;
float vertical_wall_hit_x;
float vertical_wall_hit_y;
float *distance;
int is_ray_facing_up;
int is_ray_facing_down;
int is_ray_facing_left;
int is_ray_facing_right;
int wall_hit_content;
int num_rays;
float hor_x_step;
float hor_y_step;
float vert_x_step;
float vert_y_step;
int was_hit_vertical;
} t_ray;
typedef struct s_settings
{
t_window_settings *window;
t_game_state *game;
t_cub *config;
t_ray *ray;
} t_settings;
void parse_file(char *file, t_cub *config);
int key_press_handler(int keycode, t_settings *settings);
int key_release_handler(int keycode, t_settings *settings);
int refresh(t_settings *settings);
void draw_map(t_settings *settings);
void draw_ray(t_settings *settings,
float final_x, float final_y);
void cast_rays(t_settings *settings);
void generate_wall_projection(t_settings *settings, int count);
void draw_ceiling(t_settings *settings);
void draw_floor(t_settings *settings);
void load_textures(t_settings *settings);
int choose_texture(t_settings *settings);
void check_args(int argc, char **argv);
float calculate_distance(float x, float y,
float intersection_x, float intersection_y);
void render_sprite(t_settings *settings);
float normalise_angle(float angle);
void my_mlx_pixel_put(t_window_settings *window, int x, int y, int color);
int get_colour(t_texture texture, int x, int y);
void verify_max_screen_size(t_window_settings window, t_cub *config);
void check_max_rgb_value(t_cub config);
int veirify_rgb_input(char c);
int is_map_on_top(t_cub config);
void count_type_identifiers(t_cub *config, char *line);
void is_texture_provided(t_cub config);
void check_map(t_cub config);
void check_player(t_cub config);
int is_zero_open(t_cub config, int x, int y);
int is_line_last(t_cub config);
void swap_sprites(t_sprite *sprite, int i, int j);
void sort_sprites(t_settings *settings);
float calculate_angle_sprite_player(t_settings *settings,
int count, float angle_sprite_player);
void is_sprite_visible(t_settings *settings, t_sprite *sprite, int count);
void update_player_position(t_settings *settings, t_player *player);
void find_shortest_distance(t_player *player, t_ray *ray, int count);
void find_ray_direction(t_settings *settings);
int check_wall_collision(t_settings *settings, float next_x, float next_y);
void reset_ray_struct(t_ray *ray);
void draw_minimap_components(t_settings *settings);
void draw_a_square(t_window_settings *window, float x, float y, int colour);
void init_player(t_settings *settings);
void init_sprite(t_settings *settings);
void init_ray(t_settings *settings);
void init_config(t_settings *settings, t_cub *config);
void init_texture_path(t_cub *config);
int x_button_hook(t_settings *settings);
void init_wall(t_settings *settings);
void check_config_file(t_cub config);
void check_allowed_chars(t_cub config);
void parse_floor_colour(t_cub *game_config, char *line);
void parse_ceiling_colour(t_cub *game_config, char *line);
void parse_sprite_texture(t_cub *game_config, char *line);
void parse_wall_texture(t_cub *game_config, char *line);
void draw_a_circle(t_window_settings *window, float x, float y, int colour);
void is_rgb_present(t_cub config);
int veirify_resolution_input(char c);
void ft_error(int error_code);
int is_type_identifier_allowed(char *line);
void does_file_exist(t_cub config);
int free_everything(t_settings *settings);
void check_resolution(t_cub *config);
void contains_sprites(t_cub *config);
void check_minimap_max_width_height(t_cub *config,
int *max_width, int *max_height);
#endif