Stargrove

scr_inputControlUpdateGamepad

Mar 24th, 2018
216
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 1 0
  1. /// @description updates keyboard and mouse inputs for player
  2. /// @param playerID
  3.  
  4. /// we want to run different functions depending on whether this button is currently assigned to a mouse or keyboard button. So here you'll see a simple way that we can handle either one. This system, although it is a bit clunky, will allow you to easily assign keyboard or mouse inputs for the keyboard and mouse player and read them on the fly.
  5.  
  6. var i = argument0;
  7. var _inputDevice = playerInputDevice[i];
  8.  
  9. if gamepad_is_connected(_inputDevice)
  10. {
  11.  
  12. playerJumpPressed[i] = gamepad_button_check_pressed(_inputDevice,playerJumpButton[i]);
  13. playerJumpHeld[i] = gamepad_button_check(_inputDevice,playerJumpButton[i]);
  14.  
  15. playerAttackPressed[i] = gamepad_button_check_pressed(_inputDevice,playerAttackButton[i]);
  16. playerAttackHeld[i] = gamepad_button_check(_inputDevice,playerAttackButton[i]);
  17.  
  18. playerRunPressed[i] = gamepad_button_check_pressed(_inputDevice,playerRunButton[i]);
  19. playerRunHeld[i] = gamepad_button_check(_inputDevice,playerRunButton[i]);
  20.  
  21.  
  22. playerStartPressed[i] = gamepad_button_check_pressed(_inputDevice,playerStartButton[i]);
  23. playerStartHeld[i] = gamepad_button_check(_inputDevice,playerStartButton[i]);
  24.  
  25.  
  26. // XAXIS STUFF and YAXIS STUFF
  27. // Collect raw X/YINput values for LEFT STICK on this controller.
  28.  
  29. // UPDATE xAxis, yAxis, and Directional Pressed/held values.
  30. var _xAxis = playerXAxis[i];
  31. var _yAxis = playerYAxis[i];
  32.  
  33. if (_xAxis*_xAxis + _yAxis*+_yAxis) >= gamepadDeadzoneSquared
  34. {
  35. playerXAxis[i] = gamepad_axis_value(_inputDevice, gp_axislh);
  36. playerYAxis[i] = gamepad_axis_value(_inputDevice, gp_axislv);
  37.  
  38. _xAxis = round(_xAxis);
  39. _yAxis = round(_yAxis);
  40.  
  41. if playerAxisReady[i] == true
  42. {
  43. playerAxisReady[i] = false;
  44. switch _xAxis
  45. {
  46. case -1:
  47. playerLeftPressed[i] = true;
  48. break;
  49. case 1:
  50. playerRightPressed[i] = true;
  51. break;
  52. }
  53. switch _yAxis
  54. {
  55. case -1:
  56. playerUpPressed[i] = true;
  57. break;
  58. case 1:
  59. playerDownPressed[i] = true;
  60. break;
  61. }
  62. }
  63.  
  64. switch _xAxis
  65. {
  66. case -1:
  67. playerLeftHeld[i] = true;
  68. break;
  69. case 1:
  70. playerRightHeld[i] = true;
  71. break;
  72. }
  73.  
  74. switch _yAxis
  75. {
  76. case -1:
  77. playerUpHeld[i] = true;
  78. break;
  79. case 1:
  80. playerDownHeld[i] = true;
  81. break;
  82. }
  83. }
  84. else
  85. {
  86. playerAxisReady[i] = true;
  87. playerUpPressed[i] = gamepad_button_check_pressed(_inputDevice, gp_padu);
  88. playerDownPressed[i] = gamepad_button_check_pressed(_inputDevice, gp_padd);
  89. playerLeftPressed[i] = gamepad_button_check_pressed(_inputDevice, gp_padl);
  90. playerRightPressed[i] = gamepad_button_check_pressed(_inputDevice, gp_padr);
  91.  
  92. playerUpHeld[i] = gamepad_button_check(_inputDevice, gp_padu);
  93. playerDownHeld[i] = gamepad_button_check(_inputDevice, gp_padd);
  94. playerLeftHeld[i] = gamepad_button_check(_inputDevice, gp_padl);
  95. playerRightHeld[i] = gamepad_button_check(_inputDevice, gp_padr);
  96. }
  97. }
Add Comment
Please, Sign In to add comment