-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathso_long.h
More file actions
393 lines (349 loc) · 8.8 KB
/
so_long.h
File metadata and controls
393 lines (349 loc) · 8.8 KB
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: esafar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/28 18:11:34 by esafar #+# #+# */
/* Updated: 2021/11/17 09:53:04 by esafar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SO_LONG_H
# define SO_LONG_H
# include <unistd.h>
# include <stdlib.h>
# include <sys/types.h>
# include <sys/uio.h>
# include <limits.h>
# include <stdbool.h>
# include <fcntl.h>
# include <math.h>
# include "./libft/libft.h"
# include "./get_next_line/get_next_line.h"
# include "./mlx/mlx.h"
# define ESC 65307
# define SPACE 32
# define W 119
# define A 97
# define S 115
# define D 100
# define E 101
# define P 112
# define C 99
# define O 111
# define BUFFER_SIZE 1
# define FRAME 250
# define ERROR -1
# define SUCCESS 1
typedef struct s_data
{
void *img;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
int x;
int y;
} t_data;
typedef struct s_intro
{
t_data one;
t_data two;
t_data three;
t_data four;
t_data five;
} t_intro;
typedef struct s_param
{
char **map;
int width;
int width_with_x;
int height;
int height_with_wall;
int rendered;
} t_param;
typedef struct s_player
{
int pos_i;
int lastpos_i;
int pos_j;
int lastpos_j;
int pos_x;
int pos_y;
int steps;
int lock_pos;
int hurt;
t_data frontside;
t_data backside;
t_data rightside;
t_data leftside;
t_data dmg_front;
t_data dmg_back;
t_data dmg_right;
t_data dmg_left;
t_data *side;
} t_player;
typedef struct s_piano
{
t_data topright;
t_data topmid;
t_data topleft;
t_data midright;
t_data midmid;
t_data midleft;
t_data downright;
t_data downmid;
t_data downleft;
} t_piano;
typedef struct s_exit
{
int opened;
t_data exit_half_right;
t_data exit_half_left;
t_data trapdoor_right;
t_data trapdoor_left;
t_data open_to_right;
t_data open_to_left;
} t_exit;
typedef struct s_chimney
{
t_data bottom_right;
t_data bottom_left;
t_data mid_right;
t_data mid_left;
t_data top_right;
t_data top_left;
} t_chimney;
typedef struct s_fire
{
t_data frame_one;
t_data frame_two;
t_data frame_three;
t_data frame_four;
t_data frame_five;
t_data frame_six;
t_data frame_seven;
t_data frame_eight;
t_data *frame;
} t_fire;
typedef struct s_all
{
int babo;
int random_obj;
int ispiano;
t_data wall;
t_data floor;
t_data floor_half_right;
t_data floor_half_left;
t_data box;
t_data pot;
t_data cardboard;
t_data dresser_topright;
t_data dresser_topleft;
t_data dresser_downright;
t_data dresser_downleft;
t_data babolex_painting;
t_chimney chimney;
t_fire fire;
t_piano piano;
t_exit exit;
t_data spike;
} t_all;
typedef struct s_collec
{
int amount;
int count;
int exit;
int random;
t_data newspaper;
t_data wanted;
t_data murder_article;
} t_collec;
typedef struct s_button
{
int time;
t_data e_key;
t_data p_key;
t_data o_key;
} t_button;
typedef struct s_dialog
{
int keep;
int event;
t_data right;
t_data mid;
t_data left;
} t_dialog;
typedef struct s_stats
{
int lives;
int damages;
t_data typeface_life;
t_data full_heart;
t_data empty_heart;
t_data glass;
t_data step;
} t_stats;
typedef struct s_iter
{
int i;
int j;
int x;
int y;
} t_iter;
typedef struct s_tex
{
int tex_x;
int tex_y;
double ratio_x;
double ratio_y;
} t_tex;
typedef struct s_test
{
void *mlx;
void *win;
int frame;
int loop;
int intro_or_not;
t_param param;
t_data data;
t_all all;
t_player player;
t_collec collec;
t_button button;
t_dialog dialog_box;
t_stats stats;
t_intro intro;
t_iter iter;
t_tex tex;
} t_test;
char *get_line(char *save);
int get_map(t_test *test, int ac, char **av);
//CHECK ERRORS
int check_error(t_test *test, char **av);
void which_error_msg_to_print(t_test *test, int event);
int ft_check_extension(char *map_name);
int check_chars(t_test *test);
int map_surounded_by_walls(t_test *test, char **map);
int min_one_collectible(t_test *test);
int only_one(t_test *test, char to_check);
int map_is_rectangular(t_test *test);
//INIT
void initialize(t_test *test);
void init_stats(t_test *test);
void init_event(t_test *test);
void init_param(t_test *test);
void init_intro(t_test *test);
void init_player(t_test *test);
void init_player_pos(t_test *test);
void init_chimney_dresser(t_test *test);
void init_fire(t_test *test);
void init_collec_exit(t_test *test);
void init_all_remain(t_test *test);
void init_img1(t_test *test);
void get_fire(t_test *test);
void get_player(t_test *test);
void get_event(t_test *test);
void get_stats(t_test *test);
void get_exit(t_test *test);
void get_chimney_and_dresser(t_test *test);
void get_piano(t_test *test);
void get_collec(t_test *test);
void get_remain(t_test *test);
void norme1(t_test *test);
void norme2(t_test *test);
void norme3(t_test *test);
void norme4(t_test *test);
void norme5(t_test *test);
void norme6(t_test *test);
void norme7(t_test *test);
void norme8(t_test *test);
void norme9(t_test *test);
void norme10(t_test *test);
void norme11(t_test *test);
void norme12(t_test *test);
void norme13(t_test *test);
void norme14(t_test *test);
void norme15(t_test *test);
void norme16(t_test *test);
//MOVE
void move_right(t_test *test);
void exec_right(t_test *test);
void move_left(t_test *test);
void exec_left(t_test *test);
void move_up(t_test *test);
void exec_up(t_test *test);
void move_down(t_test *test);
void exec_down(t_test *test);
void exec_trap(t_test *test, int direction);
void exec_exit(t_test *test, int direction);
void exec_not_all_items(t_test *test, int direction);
//DRAW
void draw_on_image(t_test *test, t_data *img, int startx, int starty);
void draw_on_image_bis(t_test *test, t_data *img, int startx, int starty);
void draw_on_image_intro(t_test *test, t_data *img, int startx, int starty);
void draw_background(t_test *test);
void draw_walls(t_test *test);
void draw_floors(t_test *test);
void draw_furnitures(t_test *test);
int isvpcte(t_test *test, int i, int j);
int cond1(t_test *test);
int cond2(t_test *test);
int cond3(t_test *test);
int cond4(t_test *test);
int draw_chimney(t_test *test, int random_obj, int x, int y);
void draw_dresser(t_test *test, int x, int y);
void draw_flames(t_test *test, int x, int y);
int draw_piano(t_test *test, int piano, int x, int y);
void draw_pot(t_test *test, int random_obj, int x, int y);
void four_pot_line(t_test *test, int x, int y);
void draw_collectibles(t_test *test);
void check_which_collectible(t_test *test, int i, int x, int y);
void draw_player(t_test *test);
void choose_player_image(t_test *test);
void get_pos_player(t_test *test);
void draw_exit(t_test *test);
void check_how_to_draw_exit(t_test *test);
void draw_trap(t_test *test);
void draw_life(t_test *test);
void draw_score(t_test *test);
void free_string(char *steps, char *collec, char *amount);
void draw_dialog_box(t_test *test);
void write_piano_event(t_test *test);
void write_newspaper_event(t_test *test);
void write_new_item_event(t_test *test);
void write_press_c_event(t_test *test);
void print_box(t_test *test);
void draw_button(t_test *test);
void make_exit_key_event(t_test *test);
void make_piano_key_event(t_test *test);
void make_collec_key_event(t_test *test);
void check_which_player_side(t_test *test);
void print_map(t_test *test);
//EVENT
void pick_up_coll(t_test *test);
void pick_up_coll_event(t_test *test);
void play_piano(t_test *test);
void open_trapdoor(t_test *test);
void clean_dialog(t_test *test);
//KEYPRESS
int handle_keypress(int keysym, t_test *test);
void check_intro_keypress(t_test *test, int keysym);
void check_game_keypress(t_test *test, int keysym);
//UTILS
int get_pixel(t_data *img, int x, int y);
void my_mlx_pixel_put(t_test *test, int x, int y, int color);
void draw_on_image(t_test *test, t_data *img, int startx, int starty);
void draw_on_image_bis(t_test *test, t_data *img, int startx, int starty);
void draw_on_image_intro(t_test *test, t_data *img, int startx, int starty);
//EXIT
void clean_exit(t_test *test);
int close_win_cross(t_test *test);
void free_map(t_test *test);
void destroy_collec_floor_wall(t_test *test);
void destroy_event_img(t_test *test);
void destroy_obj_img(t_test *test);
void destroy_fire_img(t_test *test);
void destroy_player_img(t_test *test);
#endif