-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_handler.c
73 lines (67 loc) · 1.94 KB
/
event_handler.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* event_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hgrissen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/21 17:09:24 by hgrissen #+# #+# */
/* Updated: 2021/02/20 15:41:58 by hgrissen ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int update(void)
{
mlx_hook(g_mlx.mlx_win, 2, 0, key_pressed, &g_mlx);
mlx_hook(g_mlx.mlx_win, 3, 0, key_released, &g_mlx);
mlx_hook(g_mlx.mlx_win, 17, 0, ft_quit, &g_mlx);
move();
render();
return (0);
}
void refresh(void)
{
mlx_destroy_image(g_mlx.mlx, g_img.img);
g_img.img = mlx_new_image(g_mlx.mlx, g_prm.w, g_prm.h);
g_img.addr = mlx_get_data_addr(g_img.img, &g_img.bpp,
&g_img.ll, &g_img.end);
}
int key_pressed(int keycode)
{
if (keycode == ESC_KEY)
ft_quit();
wasd_p_events(keycode);
arrow_p_events(keycode);
bonus_events(keycode, 1);
return (0);
}
int key_released(int keycode)
{
wasd_r_events(keycode);
arrow_r_events(keycode);
bonus_events(keycode, 0);
return (0);
}
int render(void)
{
cast_rays();
render_flr_cei();
walls3d();
sprites_conf();
if (!g_save && BON == 1 && g_p.ismap)
{
render_map();
draw_player(g_p.x, g_p.y, 0x00FF00FF);
}
if (BON)
{
red_post();
health_bg();
health_bar();
}
mlx_put_image_to_window(g_mlx.mlx, g_mlx.mlx_win, g_img.img, 0, 0);
if (g_save)
screenshot();
refresh();
return (0);
}