-
Notifications
You must be signed in to change notification settings - Fork 0
/
cub3d_main.c
executable file
·61 lines (54 loc) · 2.13 KB
/
cub3d_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d_main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mg <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/31 20:15:13 by mg #+# #+# */
/* Updated: 2020/10/07 23:19:35 by mg ### ########.fr */
/* */
/* ************************************************************************** */
/*
** gcc -Wextra -Werror -Wall
** cub3d*.c libft/ft*.c getline/get*.c ft_printf/ft*.c ft_printf/pf*.c
** -L minilibx-linux -lmlx -lXext -lX11 -lbsd -lm -g
**
** mlx_key_hook(cub3d.win, c3d_key_press, &cub3d);
*/
#include "cub3d.h"
int main(int argc, char **argv)
{
t_param cub3d;
ft_memset(&cub3d, 0, sizeof(t_param));
if (argc > 3 || argc == 1)
c3d_print_error(&cub3d, "INVALID NUMBER OF ARUGMENTS");
if (!c3d_is_cub_extension(cub3d.map.file = argv[1]))
c3d_print_error(&cub3d, "GAME FILE NOT CUB EXTENSION");
if (argc == 3 && c3d_is_save(argv[2]))
cub3d.bitmap = 1;
if (argc == 3 && cub3d.bitmap == 0)
c3d_print_error(&cub3d, "INVALID THIRD ARUGMENT");
c3d_initiate_game(&cub3d);
c3d_raycasting(&cub3d);
c3d_valid_keys();
mlx_hook(cub3d.win, KEYPRESS, 1L << 0, c3d_key_press, &cub3d);
mlx_hook(cub3d.win, DESTROYNOTIFY, 1L << 17, c3d_game_exit, &cub3d);
mlx_hook(cub3d.win, RESIZEREQUEST, 1L << 18, c3d_window_refresh, &cub3d);
mlx_loop(cub3d.mlx);
return (1);
}
int c3d_is_save(char *arg)
{
if (ft_strlen(arg) == 6 && !ft_strcmp(arg, "--save"))
return (1);
return (0);
}
int c3d_is_cub_extension(char *line)
{
char *file_extension;
file_extension = line + ft_strlen(line) - 4;
if (!ft_strncmp(file_extension, ".cub", 4))
return (1);
return (0);
}