-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_response.c
101 lines (94 loc) · 2.31 KB
/
key_response.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
** key_response.c for key_response in /home/nicolas/Modules/gfx_raytracer1
**
** Made by menett_a
** Login <[email protected]>
**
** Started on Tue Mar 1 21:53:33 2016 menett_a
** Last update Sun Mar 13 23:52:39 2016 menett_a
*/
#include <lapin.h>
#include "macro.h"
#include "struct.h"
void init_move(t_loop *loop)
{
loop->move.move_z = 0;
loop->move._move_z = 0;
loop->move.move_y = 0;
loop->move._move_y = 0;
loop->move.move_x = 0;
loop->move._move_x = 0;
loop->move._angle = 0;
loop->move.angle = 0;
}
void view_pos(t_loop *loop)
{
if (loop->move.move_z == 1)
loop->pos_z = loop->pos_z + SPEED;
if (loop->move._move_z == -1)
loop->pos_z = loop->pos_z - SPEED;
if (loop->move.move_y == 1)
loop->pos_y = loop->pos_y + SPEED;
if (loop->move._move_y == -1)
loop->pos_y = loop->pos_y - SPEED;
if (loop->move.move_x == 1)
loop->pos_x = loop->pos_x + SPEED;
if (loop->move._move_x == -1)
loop->pos_x = loop->pos_x - SPEED;
if (loop->move.angle == 1)
loop->info.screen_info.angle = loop->info.screen_info.angle - 2;
if (loop->move._angle == -1)
loop->info.screen_info.angle = loop->info.screen_info.angle + 2;
}
void key_down(t_loop *loop, t_bunny_keysym key)
{
if (key == BKS_Z)
loop->move.move_z = 1;
if (key == BKS_S)
loop->move._move_z = -1;
if (key == BKS_D)
loop->move.move_x = 1;
if (key == BKS_Q)
loop->move._move_x = -1;
if (key == BKS_A)
loop->move._move_y = -1;
if (key == BKS_E)
loop->move.move_y = 1;
if (key == BKS_J)
loop->move._angle = -1;
if (key == BKS_L)
loop->move.angle = 1;
}
void key_up(t_loop *loop, t_bunny_keysym key)
{
if (key == BKS_Z)
loop->move.move_z = 0;
if (key == BKS_S)
loop->move._move_z = 0;
if (key == BKS_D)
loop->move.move_x = 0;
if (key == BKS_Q)
loop->move._move_x = 0;
if (key == BKS_A)
loop->move._move_y = 0;
if (key == BKS_E)
loop->move.move_y = 0;
if (key == BKS_J)
loop->move._angle = 0;
if (key == BKS_L)
loop->move.angle = 0;
}
t_bunny_response key_rsp(t_bunny_event_state event,
t_bunny_keysym key,
void *data)
{
t_loop *loop;
loop = data;
if (event == GO_UP && key == BKS_ESCAPE)
return (EXIT_ON_SUCCESS);
if (event == GO_DOWN)
key_down(loop, key);
if (event == GO_UP)
key_up(loop, key);
return (GO_ON);
}