-
Notifications
You must be signed in to change notification settings - Fork 0
/
cub3d.h
186 lines (145 loc) · 4.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: polmarti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 11:52:10 by polmarti #+# #+# */
/* Updated: 2024/05/07 11:52:12 by polmarti ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include <stdio.h>
# include <stdlib.h>
# include <stdbool.h>
# include <math.h>
# include <limits.h>
# include "MLX42/include/MLX42/MLX42.h"
# include <unistd.h>
# include "libft/libft.h"
# define WIDTH 1920
# define HEIGHT 1080
# define TILE_SIZE 64
# define LATERAL_RADIANS 1.570796326794897
# define FOV 60
# define M_PI 3.14159265358979323846
# define ERROR_ARG 5
# define ERROR_OPEN 6
# define ERROR_TEX_BG 7
# define ERROR_NL 8
# define ERROR_CHAR 9
# define ERROR_SPAWN 10
# define ERROR_NO_SPAWN 11
# define ERROR_MAP_SURROUND 12
# define ERROR_DATA 13
# define ERROR_DUP_DATA 14
# define ERROR_RGBA 15
# define HORIZONTAL 16
# define VERTICAL 17
# define OFFSET_TILE 24
typedef uint32_t t_32;
typedef struct s_data_player
{
int advance;
int turn_on;
double speed_advance;
double speed_turn_on;
double angle_rotation; //en radianes
int lateral_move;
int x;
int y;
float fov_radians;
bool west;
bool south;
} t_data_player;
typedef struct s_minimap
{
int x;
int y;
int x_limit;
int y_limit;
int tile_size;
} t_minimap;
typedef struct s_rays
{
int collission;//if horizontal collision is the lower 1, else 0
int index;//index of rays
double wall_hit_x_horizontal;
double wall_hit_y_horizontal;
double wall_hit_x_vertical;
double wall_hit_y_vertical;
double ray_ngl;//angle of ray
double distance;// our unit of measurement (1 tile = 64 pixels)
} t_rays;
typedef struct s_textures
{
mlx_texture_t *no;
mlx_texture_t *so;
mlx_texture_t *we;
mlx_texture_t *ea;
unsigned int *arr;
} t_textures;
typedef struct s_dda_data
{
double dda_x;
double dda_y;
double x_step;
double y_step;
int pixel;
} t_dda_data;
typedef struct s_map
{
t_textures tex;
uint32_t f_color;
uint32_t c_color;
int spawn;
int spawn_x; //old map_x
int spawn_y; //old map_y
int size_x;//tamaño del mapa
int size_y;//tamaño del mapa
char **map;
} t_map;
typedef struct s_data
{
mlx_t *mlx;
mlx_image_t *image;
mlx_image_t *n_image;
t_data_player data_player;
t_rays cast_rays;
t_minimap minimap;
t_map map;
} t_data;
int get_rgba(int r, int g, int b, int a);
int ft_check_coll(t_data *d, double y, double x);
void ft_render_scene(t_data *d);
double ft_nor_angle(double angle);
void ft_draw_fl_ce(t_data *d, int ray, int t_pix, int b_pix);
int color_walls(t_data *d, int flag);
mlx_texture_t *get_texture_walls(t_data *d, int flag);
void ft_ray_caster(t_data *d, int ray);
void ft_movement_hook(t_data *d);
void ft_move_player(t_data *d);
void ft_free_map(t_map *map);
void safe_pixel_put(mlx_image_t *image, int x, int y, int color);
double ft_get_hinter(t_data *d, double angl);
double ft_get_vinter(t_data *d, double angl);
void ft_check_side(t_data *d, double angle);
void ft_draw_texture(t_data *d, int t_pix, int b_pix, \
double wall_h);
int ft_torgba(int c);
void ft_draw_minimap(t_data *d, int y, int x);
void ft_draw_square(mlx_image_t *image, t_minimap *map, int color);
void ft_esc(void *param);
int ft_parse_input(int argc, char **argv, t_map *map);
int ft_load_mapdata(t_map *map, char *line);
void ft_search_replace(char *str, char og, char new);
char *ft_skip_spaces(char *str);
int ft_read_texture(t_map *map, char *line);
int ft_parse_mapdata(char **line, int scenefd, t_map *map);
int ft_parse_map(char **line, int scenefd, t_map *map);
void init_data_map(t_data *d);
void init_data_player(t_data *d);
int ft_parse_error(int type);
#endif