-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathso_long.h
233 lines (184 loc) · 5.16 KB
/
so_long.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpeeters <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/05 15:24:59 by lpeeters #+# #+# */
/* Updated: 2023/08/07 21:59:20 by lpeeters ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SO_LONG_H
# define SO_LONG_H
//personal libft library functions
# include "libft/libft.h"
//minilibx library functions
# include "mlx/mlx.h"
//NULL
# include <stddef.h>
//bool
# include <stdbool.h>
//open
# include <fcntl.h>
//close
# include <unistd.h>
//malloc, free, exit
# include <stdlib.h>
//perror
# include <stdio.h>
//map data structure
typedef struct s_map
{
char **arr;
char **cpy;
char **suffix;
char *str;
char *line;
bool conditional;
int fd;
int count;
int i;
int j;
int coll;
int ccoll;
int cccoll;
int play;
int ext;
int x;
int y;
int prev;
int mx;
int my;
} t_map;
//mlx data structure
typedef struct s_mlx
{
void *ptr;
void *win;
void *gimg;
void *wimg;
void *cimg;
void *pimg;
void *eimg;
void *pcimg;
void *peimg;
void *oimg;
int y;
int x;
int n;
t_map *map;
} t_mlx;
//backtracing data structure
typedef struct s_bt
{
int mv;
struct s_bt *next;
} t_bt;
//macros
# define SUCCESS 0
# define TRUE 0
# define FAILURE 1
# define ERROR 1
# define FALSE 1
# define CASE1 1
# define BT 1
# define STEP 1
# define PRINT_LEGEND 2
# define CURR 2
# define CASE2 2
# define CASE3 3
# define CASE4 4
# define MALLOC 12
# define MAP -22
# define AC 22
# define BER 222
# define OPEN 77
//key macros
# define SPACEBAR 32
# define ESCAPE 65307
# define W 119
# define A 97
# define S 115
# define D 100
# define M 109
# define UP 65362
# define LEFT 65361
# define DOWN 65364
# define RIGHT 65363
/*************************************/
/* so_long */
/*************************************/
//initialize the map strucuture's values
void map_init(t_map *map, char *file);
//load the xpm files to image pointers
void img_init(t_mlx *mlx);
//parse map, handle errors, convert into interactive 2d video game
int main(int ac, char **av);
/*************************************/
/* handling */
/*************************************/
//exit in a clean way
int close_window(t_mlx *mlx, int status);
//handles errors
void error_handler(t_mlx *mlx, int type, int status, t_map *map);
//defines what happens when certain keys are pressed
int key_event(int keycode, t_mlx *mlx);
/*************************************/
/* map_checking */
/*************************************/
//check if argument is of the correct filetype
void check_filetype(t_map *map);
//calculate the length of a map and allocate memory for it
char **maparr(t_map *map);
//convert map to array
char **maptoarr(t_map *map);
//parse the elements in the map and check if they are correct
void mapparser(t_map *map);
//check if map is valid
void checkmap(t_map *map);
/*************************************/
/* backtracing_algorithm */
/*************************************/
//fetch the position of a character
void getcpos(t_map *map, char c);
//move to a given direction and store it in the singly linked list
void case_handler(t_map *map, t_bt **bt, int arrow);
//trace steps back untill point of intrest
void backtracer(t_bt **bt, t_map *map);
//master algorithm
void bt_algo(t_map *map);
/*************************************/
/* singly_linked_list */
/*************************************/
//free the memory of a singly linked list
void free_sll(t_bt *bt, t_bt **curr, int structure);
//initialize singly linked list
t_bt *mksll(int move);
//add values to the singly linked list
void addmv(t_bt **bt, int move);
//print a linked list's values
void print_sll(t_bt *bt);
/*************************************/
/* map_to_window */
/*************************************/
//fetch the correct sprite and send it to the window
void img_handler(t_mlx *mlx, t_map *map);
//print the map to the graphical window around the player
void map2win(t_mlx *mlx, t_map *map);
//print the map
void print_map(t_map *map);
/*************************************/
/* game_handling */
/*************************************/
//ending handler
void ending(t_map *map);
//fetch the position of a character
int checkc(t_map *map);
//update an image to the window
void upd_win(t_mlx *mlx, t_map *map, char c);
//count how many steps were taken and display them
void step_or_print_legend(t_map *map, int function);
//move the player
void move(t_mlx *mlx, t_map *map, int keycode);
#endif