-
Notifications
You must be signed in to change notification settings - Fork 1
/
cub.h
222 lines (199 loc) · 3.95 KB
/
cub.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nschumac <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/16 16:18:21 by jsiller #+# #+# */
/* Updated: 2021/10/08 16:46:07 by nschumac ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB_H
# define CUB_H
# include "mlx/mlx.h"
# include "libft/libft.h"
# include <unistd.h>
# include <stdlib.h>
# include <stdio.h>
# include <math.h>
# define FLOOR 0
# define ROOF 1
# define NORTH 0
# define EAST 1
# define SOUTH 2
# define WEST 3
# define MAIN_SCREEN 0
# define GAME_SCREEN 1
# define DONT_DO_SHIT 2
typedef enum e_keys
{
KEY_A,
KEY_S,
KEY_D,
KEY_F,
KEY_H,
KEY_G,
KEY_Z,
KEY_X,
KEY_C,
KEY_V,
KEY_B = 11,
KEY_Q,
KEY_W,
KEY_E,
KEY_R,
KEY_Y,
KEY_T,
KEY_ONE,
KEY_TWO,
KEY_THREE,
KEY_FOUR,
KEY_SIX,
KEY_FIVE,
KEY_NINE = 25,
KEY_SEVEN,
KEY_EIGHT = 28,
KEY_ZERO,
KEY_BRACE_R,
KEY_O,
KEY_U,
KEY_BRACE_L,
KEY_I,
KEY_P,
KEY_L = 37,
KEY_J,
KEY_K = 40,
KEY_SEMI,
KEY_N = 45,
KEY_M,
KEY_TAB = 48,
KEY_PLUS = 69,
KEY_MINUS = 78,
KEY_LEFT = 123,
KEY_RIGHT,
KEY_DOWN,
KEY_UP,
KEY_ESC = 0x35,
} t_keys;
/*
**bpp = BitsPerPixel
*/
typedef struct s_imgdata
{
int bpp;
int size_line;
int endian;
char *data_addr;
} t_imgdata;
typedef struct s_img
{
void *img_ptr;
int height;
int width;
int x;
int y;
t_imgdata data;
} t_img;
t_img *ft_new_mlx_img(void *mlx, int width, int height);
t_img *ft_new_xpm(void *mlx, char *path);
t_img *ft_resize(void *mlx, t_img *org, float percentage);
/*
** Window Struct with all the infos
*/
typedef struct s_window
{
void *win_ptr;
int width;
int height;
} t_window;
typedef struct s_line
{
float m;
float t;
} t_line;
typedef struct s_point
{
int x;
int y;
} t_point;
typedef struct s_player
{
float view_direction;
float fov;
float x_coord;
float y_coord;
int move;
float x_move;
float y_move;
int keycode;
} t_player;
typedef struct s_texture
{
int direction;
char *path;
int fd;
} t_texture;
typedef struct s_colour
{
int a;
int r;
int g;
int b;
} t_colour;
typedef struct s_map
{
int x;
int y;
char **arr;
int block_size;
t_img *org;
} t_map;
typedef struct s_file
{
char **line;
int fd;
t_colour clr[2];
t_texture txt[4];
t_map map;
t_player player;
} t_file;
typedef struct s_sprite
{
t_img *spritesheet;
t_img *displayimg;
int frame_count;
int current_frame;
} t_sprite;
/*
** imgs will be an array where last element mlx_img is empty
*/
typedef struct s_mlx
{
void *mlx_ptr;
t_img **imgs;
int cube_size;
t_sprite **sprites;
t_window win;
t_player player;
t_file file;
int menu;
t_img *map;
unsigned long fcount;
} t_mlx;
char ft_setimages(t_mlx *mlx);
char ft_create_window(t_mlx *mlx, int width, int height, char *title);
char ft_free_allimg(t_mlx *mlx, void *mlx_ptr, t_img *img);
int valdiate(char *str, t_file *file);
int mouse_hook(int x, int y, void *param);
int key_hook(int keycode, void *param);
int key_press_hook(int keycode, t_mlx *param);
t_img *rotate(t_img *img, float degree, t_mlx *mlx);
int create_map_img(t_map *map, t_mlx *data);
int update_map(t_map *map, t_mlx *data);
void set_img_col(t_img *img, int width, int height, int color);
void free_map(t_mlx *data);
/* file: main_utils.c */
int reader(t_mlx *mlx, int argc, char **argv);
int init_mlx_stuff(t_mlx *mlx);
#endif