-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversioninput.cpp
More file actions
230 lines (214 loc) · 6.81 KB
/
conversioninput.cpp
File metadata and controls
230 lines (214 loc) · 6.81 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//==========================================
//
//コントローラーの入力変換プログラム[conversioninput.cpp]
//Author:石原颯馬
//
//==========================================
#include "main.h"
#include "conversioninput.h"
//変換後入力構造体定義
typedef struct
{
bool press[BUTTON_MAX];
bool trigger[BUTTON_MAX];
bool release[BUTTON_MAX];
bool repeate[BUTTON_MAX];
} ConvButton;
//スティック用入力構造体
typedef struct
{
StickXY press;
StickXY trigger;
StickXY release;
} ConvStickState;
//グローバル
ConvButton g_aConvButton[MAX_USE_GAMEPAD] = {};
ConvStickState g_aConvStick[MAX_USE_GAMEPAD] = {};
//キーボード対応操作
const int c_aKeyboardInput[BUTTON_MAX] = { DIK_SPACE,DIK_RETURN,DIK_P };
const int c_aGamePadInput[BUTTON_MAX] = { XINPUT_GAMEPAD_X,XINPUT_GAMEPAD_A,XINPUT_GAMEPAD_START };
//========================
//初期化処理
//========================
void InitConvertionInput(void)
{
//普通に初期化
for (int nCntController = 0; nCntController < MAX_USE_GAMEPAD; nCntController++)
{
g_aConvButton[nCntController] = {};
g_aConvStick[nCntController] = {};
}
}
//========================
//更新処理
//========================
void UpdateConvertionInput(void)
{
for (int nCntController = 0; nCntController < MAX_USE_GAMEPAD; nCntController++)
{
//ボタンリセット
for (int nCntButton = 0; nCntButton < BUTTON_MAX; nCntButton++)
{
g_aConvButton[nCntController].press[nCntButton] = false;
g_aConvButton[nCntController].trigger[nCntButton] = false;
g_aConvButton[nCntController].release[nCntButton] = false;
g_aConvButton[nCntController].repeate[nCntButton] = false;
}
if (GetUseGamepad(nCntController) == true)
{//ゲームパッドの入力を代入(すべて)
//ボタン
for (int nCntButton = 0; nCntButton < BUTTON_MAX; nCntButton++)
{
g_aConvButton[nCntController].press[nCntButton] = GetGamepadPress(nCntController, c_aGamePadInput[nCntButton]);
g_aConvButton[nCntController].trigger[nCntButton] = GetGamepadTrigger(nCntController, c_aGamePadInput[nCntButton]);
g_aConvButton[nCntController].release[nCntButton] = GetGamepadRelease(nCntController, c_aGamePadInput[nCntButton]);
}
//スティック
//X
if (GetLStickX(nCntController) < 0)
{//左に傾いている
g_aConvStick[nCntController].trigger.x = g_aConvStick[nCntController].press.x != CONVSTICK_LEFT ? CONVSTICK_LEFT : CONVSTICK_NEUTRAL;
g_aConvStick[nCntController].release.x = g_aConvStick[nCntController].press.x != CONVSTICK_NEUTRAL ? CONVSTICK_NEUTRAL : CONVSTICK_LEFT;
g_aConvStick[nCntController].press.x = CONVSTICK_LEFT;
}
else if (GetLStickX(nCntController) > 0)
{//右に傾いている
g_aConvStick[nCntController].trigger.x = g_aConvStick[nCntController].press.x != CONVSTICK_RIGHT ? CONVSTICK_RIGHT : CONVSTICK_NEUTRAL;
g_aConvStick[nCntController].release.x = g_aConvStick[nCntController].press.x != CONVSTICK_NEUTRAL ? CONVSTICK_NEUTRAL : CONVSTICK_RIGHT;
g_aConvStick[nCntController].press.x = CONVSTICK_RIGHT;
}
else
{//傾いていない
g_aConvStick[nCntController].trigger.x =
g_aConvStick[nCntController].release.x =
g_aConvStick[nCntController].press.x = CONVSTICK_NEUTRAL;
}
//Y
if (GetLStickY(nCntController) < 0)
{//下に傾いている
g_aConvStick[nCntController].trigger.y = g_aConvStick[nCntController].press.y != CONVSTICK_DOWN ? CONVSTICK_DOWN : CONVSTICK_NEUTRAL;
g_aConvStick[nCntController].release.y = g_aConvStick[nCntController].press.y != CONVSTICK_NEUTRAL ? CONVSTICK_NEUTRAL : CONVSTICK_DOWN;
g_aConvStick[nCntController].press.y = CONVSTICK_DOWN;
}
else if (GetLStickY(nCntController) > 0)
{//上に傾いている
g_aConvStick[nCntController].trigger.y = g_aConvStick[nCntController].press.y != CONVSTICK_UP ? CONVSTICK_UP : CONVSTICK_NEUTRAL;
g_aConvStick[nCntController].release.y = g_aConvStick[nCntController].press.y != CONVSTICK_NEUTRAL ? CONVSTICK_NEUTRAL : CONVSTICK_UP;
g_aConvStick[nCntController].press.y = CONVSTICK_UP;
}
else
{//傾いていない
g_aConvStick[nCntController].trigger.y =
g_aConvStick[nCntController].release.y =
g_aConvStick[nCntController].press.y = CONVSTICK_NEUTRAL;
}
}
else if (nCntController == 0)
{//キーボードの入力を代入(1Pのみ)
for (int nCntButton = 0; nCntButton < BUTTON_MAX; nCntButton++)
{
//ボタン
g_aConvButton[0].press[nCntButton] = GetKeyboardPress(c_aKeyboardInput[nCntButton]);
g_aConvButton[0].trigger[nCntButton] = GetKeyboardTrigger(c_aKeyboardInput[nCntButton]);
g_aConvButton[0].release[nCntButton] = GetKeyboardRelease(c_aKeyboardInput[nCntButton]);
g_aConvButton[0].repeate[nCntButton] = GetKeyboardRepeate(c_aKeyboardInput[nCntButton]);
}
//(ゲームパッドで言う)スティック
//X
if (GetKeyboardPress(DIK_A) == true)
{//左に傾いている
g_aConvStick[0].press.x = CONVSTICK_LEFT;
}
else if (GetKeyboardPress(DIK_D) == true)
{//右に傾いている
g_aConvStick[0].press.x = CONVSTICK_RIGHT;
}
else
{//傾いていない
g_aConvStick[0].press.x = CONVSTICK_NEUTRAL;
}
//Y
if (GetKeyboardPress(DIK_W) == true)
{//左に傾いている
g_aConvStick[0].press.y = CONVSTICK_UP;
}
else if (GetKeyboardPress(DIK_S) == true)
{//右に傾いている
g_aConvStick[0].press.y = CONVSTICK_DOWN;
}
else
{//傾いていない
g_aConvStick[0].press.y = CONVSTICK_NEUTRAL;
}
}
}
}
//========================
//ボタン入力設定処理
//========================
void SetButton(int nPadNum, INPUTTYPE type, BUTTON button, bool stat)
{
switch (type)
{
case INPUTTYPE_PRESS:
g_aConvButton[nPadNum].press[button] = stat;
break;
case INPUTTYPE_TRIGGER:
g_aConvButton[nPadNum].trigger[button] = stat;
break;
case INPUTTYPE_RELEASE:
g_aConvButton[nPadNum].release[button] = stat;
break;
case INPUTTYPE_REPEATE:
g_aConvButton[nPadNum].repeate[button] = stat;
break;
}
}
//========================
//ボタン入力取得処理
//========================
bool GetButton(int nPadNum, INPUTTYPE type, BUTTON button)
{
switch (type)
{
case INPUTTYPE_PRESS:
return g_aConvButton[nPadNum].press[button];
break;
case INPUTTYPE_TRIGGER:
return g_aConvButton[nPadNum].trigger[button];
break;
case INPUTTYPE_RELEASE:
return g_aConvButton[nPadNum].release[button];
break;
case INPUTTYPE_REPEATE:
return g_aConvButton[nPadNum].repeate[button];
break;
}
return false;
}
//========================
//スティック入力設定処理(Xのみ)
//========================
void SetStick(int nPadNum, CONVSTICK stick)
{
g_aConvStick[nPadNum].press.x = stick;
}
//========================
//スティック入力取得処理
//========================
StickXY GetStick(int nPadNum, INPUTTYPE type)
{
switch (type)
{
case INPUTTYPE_PRESS:
return g_aConvStick[nPadNum].press;
break;
case INPUTTYPE_TRIGGER:
return g_aConvStick[nPadNum].trigger;
break;
case INPUTTYPE_RELEASE:
return g_aConvStick[nPadNum].release;
break;
}
return{ CONVSTICK_NEUTRAL,CONVSTICK_NEUTRAL };
}