-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdpad_logic.c
More file actions
103 lines (98 loc) · 3.17 KB
/
dpad_logic.c
File metadata and controls
103 lines (98 loc) · 3.17 KB
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
102
103
#pragma once
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "game_state.h"
#include "gesture_injector.c"
#include "config.h"
int finger_id_vertical = -1;
int finger_id_horizontal = -1;
int process_dpad_vertical(int event_fd, int value, int game_state)
{
switch(game_state)
{
case GAME_STATE_PAUSED:
if (value == -1)
{
inject_tap_gesture(event_fd, QUIT_GAME_ACTION);
return GAME_STATE_MENU;
}
if (value == 1)
{
inject_tap_gesture(event_fd, CONTINUE_GAME_ACTION);
return GAME_STATE_PLAYING;
}
break;
case GAME_STATE_PLAYING:
switch (value)
{
case -1:
if(finger_id_vertical != -1)
{
inject_finger_up(event_fd, finger_id_vertical);
finger_id_vertical = -1;
}
finger_id_vertical = inject_finger_down(event_fd, HARD_DROP_ACTION);
break;
case 0:
if(finger_id_vertical != -1)
{
inject_finger_up(event_fd, finger_id_vertical);
finger_id_vertical = -1;
}
break;
case 1:
if(finger_id_vertical != -1)
{
inject_finger_up(event_fd, finger_id_vertical);
finger_id_vertical = -1;
}
finger_id_vertical = inject_finger_down(event_fd, SOFT_DROP_ACTION);
break;
}
break;
}
return game_state;
}
int process_dpad_horizontal(int event_fd, int value, int game_state)
{
switch(game_state)
{
case GAME_STATE_PAUSED:
if (value == 1)
{
inject_tap_gesture(event_fd, NEW_GAME_ACTION);
return GAME_STATE_PLAYING;
}
break;
case GAME_STATE_PLAYING:
switch(value)
{
case -1:
if(finger_id_horizontal != -1)
{
inject_finger_up(event_fd, finger_id_horizontal);
finger_id_horizontal = -1;
}
finger_id_horizontal = inject_finger_down(event_fd, MOVE_LEFT_ACTION);
break;
case 0:
if(finger_id_horizontal != -1)
{
inject_finger_up(event_fd, finger_id_horizontal);
finger_id_horizontal = -1;
}
break;
case 1:
if(finger_id_horizontal != -1)
{
inject_finger_up(event_fd, finger_id_horizontal);
finger_id_horizontal = -1;
}
finger_id_horizontal = inject_finger_down(event_fd, MOVE_RIGHT_ACTION);
break;
}
break;
}
return game_state;
}