blob: 07c192b69bae4824e30b8112ee157fea4fb33da6 (
plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_key_events.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2020/02/02 17:19:30 by rbousset #+# ## ## #+# */
/* Updated: 2020/02/02 17:19:30 by rbousset ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
static int8_t
ft_w_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
pl->pos_y += 0.2 * (-1); /* pl->mult; */
pl->pos_x += 0;
return (0);
}
static int8_t
ft_a_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
pl->pos_x -= 0.2;
return (0);
}
static int8_t
ft_s_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
pl->pos_y += 0.2;
return (0);
}
static int8_t
ft_d_key(t_cub *clist)
{
t_player *pl;
pl = clist->plist;
pl->pos_x += 0.2;
return (0);
}
int
ft_key_event(int keycode, t_cub *clist)
{
t_player *pl;
t_map *ml;
int8_t (*fun_ptr[4])(t_cub*);
const uint16_t tmp_code = keycode;
fun_ptr[0] = ft_w_key;
fun_ptr[1] = ft_a_key;
fun_ptr[2] = ft_s_key;
fun_ptr[3] = ft_d_key;
ft_printf("Key [%d] pressed\n", tmp_code);
(tmp_code == FT_W_KEY) ? (keycode = 0) : 0;
(tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
(tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
(tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
(tmp_code == 3) ? (keycode = INT16_MAX) : 0;
(tmp_code == 4) ? (keycode = INT16_MAX) : 0;
pl = clist->plist;
ml = clist->mlist;
if (keycode <= 3)
{
(*fun_ptr[keycode])(clist);
(pl->pos_y < 0.4) ? (pl->pos_y = 0.4) : 0;
(pl->pos_x < 0.4) ? (pl->pos_x = 0.4) : 0;
(pl->pos_y > ml->map_h - 1.4) ? (pl->pos_y = ml->map_h - 1.4) : 0;
(pl->pos_x > ml->map_w - 1.4) ? (pl->pos_x = ml->map_w - 1.4) : 0;
ft_draw_scene(clist);
return (0);
}
else if (keycode == FT_ESC_KEY)
return (ft_exit(0, (clist)));
else if (keycode == FT_F1_KEY)
return (ft_f1_key(clist));
return (0);
}
|