-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
57 lines (52 loc) · 2.09 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaesjeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 16:00:12 by jaemjeon #+# #+# */
/* Updated: 2022/11/12 19:07:17 by jaesjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "mlx.h"
int main_loop(t_game *game)
{
if (game->pressed_keyset != 0)
{
if (game->pressed_keyset & KEY_WASD)
move_player(&game->player, game->info.map, game->pressed_keyset);
if (game->info.using_mouse == FALSE && game->pressed_keyset & KEY_ARROW)
rotate_player_key(game, game->pressed_keyset);
}
if (game->info.using_mouse == TRUE)
rotate_player_mouse(game);
draw_screen(game);
draw_minimap(game);
mlx_sync(MLX_SYNC_IMAGE_WRITABLE, game->view_data.img);
mlx_put_image_to_window(game->info.mlx_ptr, game->info.win_ptr, \
game->view_data.img, 0, 0);
mlx_sync(MLX_SYNC_WIN_CMD_COMPLETED, game->info.win_ptr);
return (0);
}
void loop(t_game *game)
{
mlx_loop_hook(game->info.mlx_ptr, main_loop, game);
mlx_hook(game->info.win_ptr, KEY_PRESS_EVENT, 1L << 0, ft_key_press, game);
mlx_hook(game->info.win_ptr, \
KEY_RELEASE_EVENT, 1L << 1, ft_key_release, game);
mlx_hook(game->info.win_ptr, KEY_EXIT, 0, exit_game, 0);
mlx_loop(game->info.mlx_ptr);
}
int main(int argc, char *argv[])
{
t_game game;
graphic_resource_init(&game);
player_handle_setting(&game);
check_argv(argc, argv, &game);
print_game_info(&game);
make_minimap_image(&game);
loop(&game);
return (0);
}