-
Notifications
You must be signed in to change notification settings - Fork 0
/
cub3d.c
executable file
·86 lines (80 loc) · 2.19 KB
/
cub3d.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hgrissen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/11 11:57:14 by hgrissen #+# #+# */
/* Updated: 2021/02/20 15:25:51 by hgrissen ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void arguments_errors(int error)
{
if (error == 1)
printf("Error:\nwrong config file extension");
if (error == 2)
printf("Error:\nthe second argument must be --save");
if (error == 3)
printf("Error:\nwrong number of parameters");
if (error == 4)
printf("Error:\nwrong config file");
exit(0);
}
void arguments(int argc, char *argv[])
{
int end;
end = ft_strlen(argv[1]) - 1;
if (argc == 3)
{
if (argv[1][end] == 'b' && argv[1][end - 1] == 'u' &&
argv[1][end - 2] == 'c' && argv[1][end - 3] == '.')
g_file = ft_strdup(argv[1]);
else
arguments_errors(1);
if (!ft_strncmp(argv[2], "--save", 7))
g_save = 1;
else
arguments_errors(2);
}
else if (argc == 2)
{
if (argv[1][end] == 'b' && argv[1][end - 1] == 'u' &&
argv[1][end - 2] == 'c' && argv[1][end - 3] == '.')
g_file = ft_strdup(argv[1]);
else
arguments_errors(1);
}
else
arguments_errors(3);
}
void screenshot(void)
{
save_bmp();
exit(0);
}
int main(int argc, char **argv)
{
if (argc <= 1)
{
printf("Error\n .cub file missing");
ft_quit();
}
prm_init();
err_init();
arguments(argc, argv);
get_file(argv);
if (g_err.map_bgn)
{
build_map();
map_chk_opn();
}
ch_fil_err();
play_m();
canvas_init();
init_sprites();
mlx_loop_hook(g_mlx.mlx, update, &g_mlx);
mlx_loop(g_mlx.mlx);
return (0);
}