forked from RanniSch/cub3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
executable file
·216 lines (197 loc) · 4.72 KB
/
main.c
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
#include "./inc/cub3d.h"
void raycast_and_picturework(t_info *info)
{
raycast_scan_in_fov(info, info->p);
fill_background(info->ceiling, info->floor, info->img);
draw_wall_textures(info, 0);
mlx_put_image_to_window(info->mlx_ptr, info->mlx_win, info->img->img, 0, 0);
}
int key_event(int key, t_info *info)
{
if (key == W)
move_forward(info);
else if (key == S)
move_backward(info);
else if (key == A)
move_left(info);
else if (key == D)
move_right(info);
else if (key == ARROW_LEFT)
rotate_left(info);
else if (key == ARROW_RIGHT)
rotate_right(info);
else if (key == ESC)
{
ft_free_destroy(info);
exit(0);
}
raycast_and_picturework(info);
return (0);
}
// bool success_malloc_game(t_info *info)
// {
// if (!init_process_game())
// {
// message(ERROR_4);
// return (false);
// }
// if(!init_dist_arr(info)) // wichtig
// {
// message(ERROR_4);
// return (false);
// }
// if(!init_info_player_images(info))
// {
// message(ERROR_4);
// return (false);
// }
// return (true);
// }
// bool success_malloc_converter(t_info *info)
// {
// if(!map_converter(info)) // wichtig
// {
// message(ERROR_4);
// return (false);
// }
// return (true);
// }
void check_argc_and_dist_from_wall(int argc)
{
if (argc != 2)
{
message(ERROR_3);
exit(0);
}
if (DISTANCE_FROM_WALL < 0.3)
{
message(ERROR_5);
exit(0);
}
}
/**
* @brief
* if (!parsing(info)) // unsaved malloc in:
* check_valid_textures -> ft_save_path_texture -> ft_substr
*
* printf("parsing false\n"); // only for debugging purpuse!
* @param info
*/
void parsing_(t_info *info)
{
if (!parsing(info))
{
clean_up_parser(info);
exit (0);
}
}
int main(int argc, char **argv)
{
t_info *info;
check_argc_and_dist_from_wall(argc);
info = init_process_game();
info->map_path = ft_strdup(argv[1]);
if (!info->map_path)
{
clean_up_all_expt_mlx(info);
message(ERROR_4);
exit(1);
}
valid_map_extension(info);
info->row = count_nb_row(info->map_path);
info->map = save_map(info);
parsing_(info);
info->map_int = map_converter(info);
convert_player_pos_dir(info);
init_mlx_and_textures(info);
init_mlx_window_first_screen(info);
mlx_key_hook(info->mlx_win, key_event, info);
mlx_hook(info->mlx_win, 17, 1L << 2, ft_free_destroy, info);
mlx_loop(info->mlx_ptr);
return (0);
}
/*
int main(int argc, char **argv)
{
t_info *info;
check_argc_and_dist_from_wall(argc);
info = init_process_game();
// init info, p, images, dist info, dist arr mit saved malloc
info->map_path = ft_strdup(argv[1]);
if (!info->map_path)
{
clean_up_all_expt_mlx(info);
message(ERROR_4);
exit(1);
}
valid_map_extension(info);
// max: ok (6te Zeile) (habe cleanup mit rein gepackt)
info->row = count_nb_row(info->map_path);
//unsave malloc inside?? (get_next_line)
info->map = save_map(info);
// returns 0 when malloc fails -> not save
parsing_(info);
// -> parsing ist in unterfunktion
info->map_int = map_converter(info);
// if malloc fails? - Max: ist gehändelt
convert_player_pos_dir(info);
init_mlx_and_textures(info);
// nach parsing damit die Pfade zu den Texturen bekannt sind
init_mlx_window_first_screen(info);
mlx_key_hook(info->mlx_win, key_event, info);
mlx_hook(info->mlx_win, 17, 1L << 2, ft_free_destroy, info);
mlx_loop(info->mlx_ptr);
return (0);
}
*/
/*
int main(int argc, char **argv)
{
t_info *info;
check_argc_and_dist_from_wall(argc);
// if (argc != 2)
// {
// message(ERROR_3);
// exit(0);
// }
// if (DISTANCE_FROM_WALL < 0.3)
// An Max: Soll das hier bleiben?
// {
// printf("DISTANCE_FROM_WALL ist to low\n");
// exit(0);
// }
info = init_process_game(); //max: ok
info->map_path = ft_strdup(argv[1]); //max: ok
// if (!valid_map_extension(info)) // kann eine Zeile sein
// {
// clean_up_extension(info);
// exit (0);
// }
valid_map_extension(info);
// max: ok (6te Zeile) (habe cleanup mit rein gepackt)
info->row = count_nb_row(info->map_path);
//max says: unsave malloc in here
info->map = save_map(info);
// returns 0 when malloc fails -> not save
//if (!success_malloc_game(info))
// provides leaks -> alles schon halb gut abgesichert in init_process_game
//{
// clean_up_parser(info);
// exit(0);
//}
parsing_(info);
printf("great\n"); // only for debugging purpuse!
info->map_int = map_converter(info);
// if malloc fails? - Max: keine Ahnung - so viele unsichere mallocs
// if (!success_malloc_converter(info)) // provides leaks
// exit(0);
convert_player_pos_dir(info);
init_mlx_and_textures(info);
// nach parsing damit die Pfade zu den Texturen bekannt sind
init_mlx_window_first_screen(info);
mlx_key_hook(info->mlx_win, key_event, info);
mlx_hook(info->mlx_win, 17, 1L << 2, ft_free_destroy, info);
mlx_loop(info->mlx_ptr);
return (0);
}
*/