-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
77 lines (70 loc) · 2.48 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: ksmorozo <ksmorozo@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/03/14 17:53:04 by ksmorozo #+# #+# */
/* Updated: 2021/07/27 14:44:36 by ksmorozo ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "mlx/mlx.h"
#include <stdlib.h>
t_window_settings set_up_window(t_cub *config)
{
t_window_settings window;
window.mlx = mlx_init();
if (!window.mlx)
ft_error(MLX_ERROR);
verify_max_screen_size(window, config);
check_resolution(config);
window.window = mlx_new_window(window.mlx,
config->x_res, config->y_res, "cub3D");
if (!window.window)
ft_error(MLX_ERROR);
window.img = mlx_new_image(window.mlx,
config->x_res, config->y_res);
if (!window.img)
ft_error(MLX_ERROR);
window.addr = (int *)mlx_get_data_addr(window.img,
&window.bits_per_pixel, &window.line_length,
&window.endian);
if (!window.addr)
ft_error(MLX_ERROR);
return (window);
}
void set_up_game(t_window_settings *window,
t_game_state *game, t_cub *config)
{
t_settings *settings;
settings = malloc(sizeof(t_settings));
if (!settings)
ft_error(MALLOC);
settings->game = game;
settings->window = window;
init_config(settings, config);
init_wall(settings);
init_player(settings);
init_ray(settings);
load_textures(settings);
init_sprite(settings);
mlx_hook(window->window, 17, 1L << 17, &x_button_hook, settings);
mlx_hook(window->window, 2, 1L << 0, key_press_handler, settings);
mlx_hook(window->window, 3, 0, key_release_handler, settings);
mlx_loop_hook(window->mlx, refresh, settings);
}
int main(int argc, char **argv)
{
t_cub config;
t_game_state game;
t_window_settings window;
check_args(argc, argv);
init_texture_path(&config);
parse_file(argv[1], &config);
check_config_file(config);
window = set_up_window(&config);
set_up_game(&window, &game, &config);
mlx_loop(window.mlx);
}