Advertisement
Auios

Untitled

Nov 20th, 2018
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Example code for using getJoystick() with Xbox controllers by Auios
  2.  
  3. type XboxController
  4.     as integer buttons
  5.     as single lax, lay
  6.     as single rax, ray
  7.     as single dpadx, dpady
  8.     as single triggers
  9. end type
  10.  
  11. function getXboxController(ID as long, xbct as xboxController) as integer
  12.     return getJoystick(ID, xbct.buttons, xbct.lax, xbct.lay, xbct.triggers, xbct.ray, xbct.rax, , xbct.dpadx, xbct.dpady)
  13. end function
  14.  
  15. const joystickID = 0
  16.  
  17. ' Check to see if the joystick is okay.
  18. if getJoystick(joystickID) Then
  19.     Print "Joystick doesn't exist or joystick error."
  20.     Print
  21.     Print "Press any key to continue."
  22.     Sleep
  23.     End
  24. end if
  25.  
  26. screenres 800, 600, 32
  27.  
  28. dim as XboxController myController
  29. dim as integer result
  30. const floatPrec = 1000
  31.  
  32. const pi = atn(1)*4
  33. dim as single x, y
  34. x = 400
  35. y = 300
  36.  
  37. do
  38.     screenLock()
  39.     cls()
  40.     line(0,0)-(800,600),rgb(220,220,200),bf
  41.     result = getXboxController(JoystickID, myController)
  42.    
  43.     myController.triggers = cint(floatPrec * myController.triggers ) / floatPrec
  44.     myController.lax = cint(floatPrec * myController.lax ) / floatPrec
  45.     myController.lay = cint(floatPrec * myController.lay ) / floatPrec
  46.     myController.rax = cint(floatPrec * myController.rax ) / floatPrec
  47.     myController.ray = cint(floatPrec * myController.ray ) / floatPrec
  48.    
  49.     ' If you want to turn your analog input into a straight dpad input you can try this:
  50.     ' x = cast(integer, x)
  51.     ' y = cast(integer, y)
  52.     print("Result       -> " & result)
  53.     print("Buttons      -> " & myController.buttons)
  54.     print("Triggers     -> " & myController.triggers)
  55.     print("Left analog  -> (" & myController.lax & ", " & myController.lay & ")")
  56.     print("Right analog -> (" & myController.rax & ", " & myController.ray & ")")
  57.     print("DPad         -> (" & myController.dpadx & ", " & myController.dpady & ")")
  58.     print("")
  59.    
  60.     for i as integer = 0 to 31
  61.         If (myController.buttons And (1 Shl i)) Then
  62.             Print "Button ";i;" pressed.    "
  63.         Else
  64.             Print "Button ";i;" not pressed."
  65.         End If
  66.     next i
  67.    
  68.     x+=myController.lax
  69.     y+=myController.lay
  70.    
  71.     circle(x,y),50,rgb(100,100,200),,,,f
  72.     for yy as single = y-2 to y+2
  73.         for xx as single = x-2 to x+2
  74.             line(xx, yy)-(x + myController.rax * 50, y + myController.ray * 50), rgb(250,50,50)
  75.             line(xx, yy)-(x + myController.lax * 50, y + myController.lay * 50), rgb(255,255,255)
  76.         next xx
  77.     next yy
  78.    
  79.     screenUnlock()
  80.    
  81.     sleep(1,1)
  82. loop until(inkey = chr(27) OR (myController.buttons And 2))
  83.  
  84. '   0   A
  85. '   1   B
  86. '   2   X
  87. '   3   Y
  88. '   4   Left
  89. '   5   Right
  90. '   6   Back
  91. '   7   Start
  92. '   8   Left Analog Button
  93. '   9   Right Analog Button
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement