Advertisement
Extreemhost

Joystick.cpp

Oct 10th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include "joystick.h"
  2.  
  3. JoyStick::Joystick(void)
  4. {
  5.     for(int i=0; i<8; i++) keys[i] = 0;
  6.     gamepad_x = gamepad_y = gamepad_z = gamepad_r = gamepad_u = gamepad_v = 0;
  7. }
  8.  
  9. void JoyStick::OnDownKey(const int key)
  10. {
  11.     keys[key] = 1;
  12. }
  13.  
  14. void JoyStick::OnUpKey(const int key)
  15. {
  16.     keys[key] = 3;
  17. }
  18.  
  19. bool JoyStick::OnKeyDown(const int key)
  20. {
  21.     return (keys[key] == 1);
  22. }
  23.  
  24. bool JoyStick::OnKeyUp(const int key)
  25. {
  26.     return (keys[key] == 3);
  27. }
  28.  
  29. bool JoyStick::OnKeyPressed(const int key)
  30. {
  31.     return ((keys[key] == 1) || (keys[key] == 2));
  32. }
  33.  
  34. void JoyStick::flush(void)
  35. {
  36.     for(int i=0; i<8; i++)
  37.     {
  38.         if(keys[i] == 1) keys[i] = 2;
  39.         else if(keys[i] == 3) keys[i] = 0;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement