-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.cpp
125 lines (110 loc) · 2.79 KB
/
controller.cpp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// Created by Allen on 2/5/2020.
//
#include <cstdint>
#include "stdio.h"
#include "SDL.h"
#include "controller.h"
double joystick1_h = 0; // A, D, Left, Right
double joystick1_v = 0; // W, S, Up, Down
bool btn1_a; // V
bool btn1_b; // B
bool btn1_start; // Space
bool btn1_l; // LShift
bool btn1_r; // RShift
double joystick2_h = 0; // J, L
double joystick2_v = 0; // I, K
bool btn2_a; // .
bool btn2_b; // /
bool btn2_start; // ,
bool btn2_l; // n
bool btn2_r; // ;
void controller_updateController() {
joystick1_h = 0;
joystick1_v = 0;
btn1_a = false;
btn1_b = false;
btn1_start = false;
btn1_l = false;
btn1_r = false;
joystick2_h = 0;
joystick2_v = 0;
btn2_a = false;
btn2_b = false;
btn2_start = false;
btn2_l = false;
btn2_r = false;
const uint8_t *keys = SDL_GetKeyboardState(NULL);
if(keys[SDL_SCANCODE_LEFT])
joystick1_h += -0.2;
if(keys[SDL_SCANCODE_RIGHT])
joystick1_h += 0.2;
if(keys[SDL_SCANCODE_UP])
joystick1_v += 0.2;
if(keys[SDL_SCANCODE_DOWN])
joystick1_v -= 0.2;
if(keys[SDL_SCANCODE_W])
joystick1_v += 0.7;
if(keys[SDL_SCANCODE_S])
joystick1_v += -0.7;
if(keys[SDL_SCANCODE_A])
joystick1_h += -0.7;
if(keys[SDL_SCANCODE_D])
joystick1_h += 0.7;
if(keys[SDL_SCANCODE_V])
btn1_a = true;
if(keys[SDL_SCANCODE_B])
btn1_b = true;
if(keys[SDL_SCANCODE_LSHIFT])
btn1_l = true;
if(keys[SDL_SCANCODE_RSHIFT])
btn1_r = true;
if(keys[SDL_SCANCODE_SPACE])
btn1_start = true;
if(keys[SDL_SCANCODE_I])
joystick2_v += 0.7;
if(keys[SDL_SCANCODE_K])
joystick2_v += -0.7;
if(keys[SDL_SCANCODE_J])
joystick2_h += -0.7;
if(keys[SDL_SCANCODE_L])
joystick2_h += 0.7;
if(keys[SDL_SCANCODE_PERIOD])
btn2_a = true;
if(keys[SDL_SCANCODE_SLASH])
btn2_b = true;
if(keys[SDL_SCANCODE_N])
btn2_l = true;
if(keys[SDL_SCANCODE_SEMICOLON])
btn2_r = true;
if(keys[SDL_SCANCODE_M])
btn2_start = true;
}
double getJoystick_h(uint8_t player) {
if(player == 2) return joystick2_h;
else return joystick1_h;
}
double getJoystick_v(uint8_t player) {
if(player == 2) return joystick2_v;
else return joystick1_v;
}
bool getBtn_a(uint8_t player) {
if(player == 2) return btn2_a;
else return btn1_a;
}
bool getBtn_b(uint8_t player) {
if(player == 2) return btn2_b;
else return btn1_b;
}
bool getBtn_l(uint8_t player) {
if(player == 2) return btn2_l;
else return btn1_l;
}
bool getBtn_r(uint8_t player) {
if(player == 2) return btn2_r;
else return btn1_r;
}
bool getBtn_start(uint8_t player) {
if(player == 2) return btn2_start;
else return btn1_start;
}