SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Joypad.h
1 #pragma once
2 #include <Multimedia/SDX.h>
3 #include <Multimedia/Key.h>
4 #include <Multimedia/InputEnum.h>
5 
6 namespace SDX
7 {
9 class Joypad
11 {
12 private:
13  PadType inputType = PadType::KeyAndPad1;
14  StickHandle handle;
15  Joypad(const Joypad &joypad){};
16  Joypad operator =(const Joypad &joypad){};
17 public:
18  int StickX = 0;
19  int StickY = 0;
20 
21  bool press[32];
22 
23  Key Down;
24  Key Left;
25  Key Right;
26  Key Up;
27  Key Button1;
28  Key Button2;
29  Key Button3;
30  Key Button4;
31  Key Button5;
32  Key Button6;
33  Key Button7;
34  Key Button8;
35  Key Button9;
36  Key Button10;
37  Key Button11;
38  Key Button12;
39  Key Button13;
40  Key Button14;
41  Key Button15;
42  Key Button16;
43  Key Button17;
44  Key Button18;
45  Key Button19;
46  Key Button20;
47  Key Button21;
48  Key Button22;
49  Key Button23;
50  Key Button24;
51  Key Button25;
52  Key Button26;
53  Key Button27;
54  Key Button28;
55 
56  Joypad()
57  {
58  #ifdef DXLIB
59  #elif defined(SDL)
60  SDL_JoystickEventState(SDL_ENABLE);
61  handle = SDL_JoystickOpen(0);
62  #endif
63  };
64 
66  void Make(PadType パッドタイプ)
67  {
68  inputType = パッドタイプ;
69  }
70 
72  void Reset()
73  {
74  Up.Reset();
75  Down.Reset();
76  Left.Reset();
77  Right.Reset();
78  Button1.Reset();
79  Button2.Reset();
80  Button3.Reset();
81  Button4.Reset();
82  Button5.Reset();
83  Button6.Reset();
84  Button7.Reset();
85  Button8.Reset();
86  Button9.Reset();
87  Button10.Reset();
88  Button11.Reset();
89  Button12.Reset();
90  Button13.Reset();
91  Button14.Reset();
92  Button15.Reset();
93  Button16.Reset();
94  Button17.Reset();
95  Button18.Reset();
96  Button19.Reset();
97  Button20.Reset();
98  Button21.Reset();
99  Button22.Reset();
100  Button23.Reset();
101  Button24.Reset();
102  Button25.Reset();
103  Button26.Reset();
104  Button27.Reset();
105  Button28.Reset();
106 
107  StickX = 0;
108  StickY = 0;
109  }
110 
112  void Update()
113  {
114  #ifdef DXLIB
115  const int N = DxLib::GetJoypadInputState(static_cast<int>(inputType));
116  DxLib::GetJoypadAnalogInput( &StickX , &StickY, (int)inputType );
117  Down.Update( N & (int)PadCode::Down);
118  Left.Update( N & (int)PadCode::Left );
119  Right.Update( N & (int)PadCode::Right );
120  Up.Update( N & (int)PadCode::Up );
121  Button1.Update( N & (int)PadCode::Button1 );
122  Button2.Update( N & (int)PadCode::Button2 );
123  Button3.Update( N & (int)PadCode::Button3 );
124  Button4.Update( N & (int)PadCode::Button4 );
125  Button5.Update( N & (int)PadCode::Button5 );
126  Button6.Update( N & (int)PadCode::Button6 );
127  Button7.Update( N & (int)PadCode::Button7 );
128  Button8.Update( N & (int)PadCode::Button8 );
129  Button9.Update( N & (int)PadCode::Button9 );
130  Button10.Update( N & (int)PadCode::Button10 );
131  Button11.Update( N & (int)PadCode::Button11 );
132  Button12.Update( N & (int)PadCode::Button12 );
133  Button13.Update( N & (int)PadCode::Button13 );
134  Button14.Update( N & (int)PadCode::Button14 );
135  Button15.Update( N & (int)PadCode::Button15 );
136  Button16.Update( N & (int)PadCode::Button16 );
137  Button17.Update( N & (int)PadCode::Button17 );
138  Button18.Update( N & (int)PadCode::Button18 );
139  Button19.Update( N & (int)PadCode::Button19 );
140  Button20.Update( N & (int)PadCode::Button20 );
141  Button21.Update( N & (int)PadCode::Button21 );
142  Button22.Update( N & (int)PadCode::Button22 );
143  Button23.Update( N & (int)PadCode::Button23 );
144  Button24.Update( N & (int)PadCode::Button24 );
145  Button25.Update( N & (int)PadCode::Button25 );
146  Button26.Update( N & (int)PadCode::Button26 );
147  Button27.Update( N & (int)PadCode::Button27 );
148  Button28.Update( N & (LONG64)PadCode::Button28 );
149  #elif defined(SDL)
150  Down.Update( press[(int)PadCode::Down]);
151  Left.Update(press[(int)PadCode::Left]);
152  Right.Update(press[(int)PadCode::Right]);
153  Up.Update(press[(int)PadCode::Up]);
154  Button1.Update(press[(int)PadCode::Button1]);
155  Button2.Update(press[(int)PadCode::Button2]);
156  Button3.Update(press[(int)PadCode::Button3]);
157  Button4.Update(press[(int)PadCode::Button4]);
158  Button5.Update(press[(int)PadCode::Button5]);
159  Button6.Update(press[(int)PadCode::Button6]);
160  Button7.Update(press[(int)PadCode::Button7]);
161  Button8.Update(press[(int)PadCode::Button8]);
162  Button9.Update(press[(int)PadCode::Button9]);
163  Button10.Update(press[(int)PadCode::Button10]);
164  Button11.Update(press[(int)PadCode::Button11]);
165  Button12.Update(press[(int)PadCode::Button12]);
166  Button13.Update(press[(int)PadCode::Button13]);
167  Button14.Update(press[(int)PadCode::Button14]);
168  Button15.Update(press[(int)PadCode::Button15]);
169  Button16.Update(press[(int)PadCode::Button16]);
170  Button17.Update(press[(int)PadCode::Button17]);
171  Button18.Update(press[(int)PadCode::Button18]);
172  Button19.Update(press[(int)PadCode::Button19]);
173  Button20.Update(press[(int)PadCode::Button20]);
174  Button21.Update(press[(int)PadCode::Button21]);
175  Button22.Update(press[(int)PadCode::Button22]);
176  Button23.Update(press[(int)PadCode::Button23]);
177  Button24.Update(press[(int)PadCode::Button24]);
178  Button25.Update(press[(int)PadCode::Button25]);
179  Button26.Update(press[(int)PadCode::Button26]);
180  Button27.Update(press[(int)PadCode::Button27]);
181  Button28.Update(press[(int)PadCode::Button28]);
182  #endif
183  }
184 
186  PadType GetInputType()
187  {
188  return inputType;
189  }
190 
192  void SetInputType(PadType 入力タイプ)
193  {
194  inputType = 入力タイプ;
195  }
196 
198  bool SetInputToKey(PadCode padInput,KeyCode keyInput1 ,KeyCode keyInput2, KeyCode keyInput3,KeyCode keyInput4)
200  {
201  #ifdef DXLIB
202  return !DxLib::SetJoypadInputToKeyInput( (int)inputType , (int)padInput, (int)keyInput1, (int)keyInput2, (int)keyInput3, (int)keyInput4 ) ;
203  #elif defined(SDL)
204  return false;
205  #endif
206  }
207 
209  bool StartVibration(double 強さ,int 振動ミリ秒)
212  {
213  #ifdef DXLIB
214  return !DxLib::StartJoypadVibration((int)inputType, int(強さ * 1000), 振動ミリ秒);
215  #elif defined(SDL)
216  return false;
217  #endif
218  }
219 
222  {
223  #ifdef DXLIB
224  return !DxLib::StopJoypadVibration((int)inputType);
225  #elif defined(SDL)
226  return false;
227  #endif
228  }
229 
231  static int GetCount()
232  {
233  #ifdef DXLIB
234  return DxLib::GetJoypadNum();
235  #elif defined(SDL)
236  return false;
237  #endif
238  }
239 };
240 }
static int GetCount()
接続中のパッド数を取得.
Definition: Joypad.h:231
bool StopVibration()
パッドの振動を停止する.
Definition: Joypad.h:221
bool SetInputToKey(PadCode padInput, KeyCode keyInput1, KeyCode keyInput2, KeyCode keyInput3, KeyCode keyInput4)
キーのパッド割当て設定.
Definition: Joypad.h:199
void Reset()
キーのリセット.
Definition: Key.h:17
void Update(int 押下フラグ)
押下状態の更新.
Definition: Key.h:26
PadType GetInputType()
パッドタイプの取得.
Definition: Joypad.h:186
void Reset()
状態のリセット.
Definition: Joypad.h:72
void Make(PadType パッドタイプ)
パッドの作成.
Definition: Joypad.h:66
void Update()
状態の更新.
Definition: Joypad.h:112
bool StartVibration(double 強さ, int 振動ミリ秒)
パッドを振動させる.
Definition: Joypad.h:211
void SetInputType(PadType 入力タイプ)
パッドタイプの設定.
Definition: Joypad.h:192