-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
90 lines (82 loc) · 2.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mchatzip <mchatzip@student.42wolfsburg.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/15 20:12:33 by ekraujin #+# #+# */
/* Updated: 2022/04/15 12:16:25 by mchatzip ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static void err_mlx(t_data *game)
{
freedirec2(game);
free_map(game, 0);
printf("Error\nmlx decided to fail for some reason\n");
exit(1);
}
int finish_game(t_data *game)
{
free_map(game, 1);
freedirec2(game);
write(1, "Game closed!\n", 13);
exit(0);
}
static int key_hook(int keycode, t_data *game)
{
if (keycode == ESC)
finish_game(game);
else
move(game, keycode);
return (0);
}
int arg_check(t_data *game, int mfd)
{
char *temp;
bool b;
b = 1;
if (!ft_strncmp(game->map_file
+ (ft_strlen(game->map_file) - 5), ".cub", 5))
return (0);
while (b)
{
temp = skip_empty_lines(game, mfd, temp);
if (!check_validity(temp))
{
free(temp);
break ;
}
else
b = get_textures_n_colors(game, temp);
free(temp);
}
b = check_if_map(game, temp);
if (!b)
return (0);
return (1);
}
int main(int argc, char **argv)
{
t_data game;
int mfd;
initialize(&game, argv);
init_check(&game, argc, mfd);
game.mlx = mlx_init();
if (!game.mlx)
err_mlx(&game);
game.mlx_win = mlx_new_window
(game.mlx, SCREEN_W, SCREEN_H, "cub3d");
if (!game.mlx_win)
{
mlx_destroy_window(game.mlx, game.mlx_win);
err_mlx(&game);
}
img_init(&game);
init_map3d(&game);
cast_rays2(&game);
mlx_hook(game.mlx_win, 2, 0, key_hook, &game);
mlx_hook(game.mlx_win, 17, 0, finish_game, &game);
mlx_loop(game.mlx);
}