-
Notifications
You must be signed in to change notification settings - Fork 3
/
key_hook.c
32 lines (30 loc) · 1.37 KB
/
key_hook.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* key_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tblaase <tblaase@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/07 16:51:04 by tblaase #+# #+# */
/* Updated: 2021/10/08 15:12:21 by tblaase ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int ft_key_hook(int keycode, t_data *data)
/* will cause the different actions of the valid key presses
** will cause you to win if you reached the exit */
{
if (keycode == ESC)
ft_exit(data);
else if (keycode == W)
ft_move(data, 'y', UP);
else if (keycode == A)
ft_move(data, 'x', LEFT);
else if (keycode == S)
ft_move(data, 'y', DOWN);
else if (keycode == D)
ft_move(data, 'x', RIGHT);
if (data->map->map[data->p_y][data->p_x] == 'E')
ft_win(data);
return (0);
}