Subscribe to:

The Kiwi's TaleWitchBlasterDerelict Blow Stuff Up

XBox 360 Library for Blitz3D

This is the Blitz3D Library I wrote (as part of my re-release project) for adding near complete XBox 360 controller support. 

It's free for anyone to use with no limitations whatsoever. I may publish this to the Blitz research site later.


;XBox 360 controller library for Blitz3D by Earok (Earok.Net)

;I declare this code to be in the public domain



;This library provides complete XBox 360 controller support except for the following limitations:

;1. No force feedback support

;2. Left and Right triggers cancel each other out. Holding them both down is the same as holding neither down.

;3. No support for the center glowing button


;Constants defining every XBox 360 button, just pass these to the standard joyhit, joydown functions etc.

Const x360_button_a = 1

Const x360_button_b = 2

Const x360_button_x = 3

Const x360_button_y = 4

Const x360_button_lb = 5

Const x360_button_rb = 6

Const x360_button_back = 7

Const x360_button_start = 8

Const x360_button_lts = 9

Const x360_button_rts = 10


;Uncomment the next line to run an example controller application



;This trims out small values from not quite centered analogue sticks and triggers.  You don't need to call this from your game. 

;Alter trim value to adjust the "dead zone" from the stick/trigger center.

Const x360_trim_value# = 0.20

Function x360_Trim#(value#)


If(Abs(value#) > x360_trim_value#) Return value#


End Function


;Returns the left trigger value

Function x360_LTrigger#(port=0)


If (JoyZ(port) > x360_trim_value#) Return x360_Trim#(JoyZ(port))


End Function


;Returns the right trigger value

Function x360_RTrigger#(port=0)


If JoyZ(port) < (0 - x360_trim_value) Return x360_Trim#(JoyZ(port)) * -1


End Function


;Returns the X value on the D-Pad

Function x360_DPadX(port=0)


If JoyHat(port) > -1 Then Return x360_Trim#(Sin(JoyHat(port)))


End Function


;Returns the Y value on the D-Pad

Function x360_DPadY(port=0)


If JoyHat(port) > -1 Then Return -x360_Trim#(Cos(JoyHat(port)))


End Function


;Returns the X value on the Left Thumbstick

Function x360_LeftStickX#(port=0)


Return x360_Trim#(JoyX(port))


End Function


;Returns the Y value on the Left Thumbstick

Function x360_LeftStickY#(port=0)


Return x360_Trim#(JoyY(port))


End Function


;Returns the X value on the Right Thumbstick

Function x360_RightStickX#(port=0)


Return x360_Trim#(Sin(JoyPitch(port) / 2))


End Function


;Returns the Y value on the Right Thumbstick

Function x360_RightStickY#(port=0)


Return x360_Trim#(Sin(JoyYaw(port) / 2))


End Function


;Demo application for Xbox 360 controller support

Function DemoProgram()


Local ButtonDefs$[11]

ButtonDefs[0] = "None"

ButtonDefs[1] = "A"

ButtonDefs[2] = "B"

ButtonDefs[3] = "X"

ButtonDefs[4] = "Y"

ButtonDefs[5] = "Left Shoulder"

ButtonDefs[6] = "Right Shoulder"

ButtonDefs[7] = "Back"

ButtonDefs[8] = "Start"

ButtonDefs[9] = "Left Thumbstick"

ButtonDefs[10] = "Right Thumbstick"


While Not KeyHit(1)




Text 0,00,"Stick Left X: " + x360_LeftStickX()

Text 0,20,"Stick Left Y: " + x360_LeftStickY()

Text 0,40,"Stick Right X: " + x360_RightStickX()

Text 0,60,"Stick Right Y: " + x360_RightStickY()

Text 0,80,"Left Trigger: " + x360_LTrigger()

Text 0,100,"Right Trigger: " + x360_RTrigger()

Text 0,120,"DPad X: " + x360_DPadX()

Text 0,140,"DPad Y: " + x360_DPadY()


lastpressed = GetJoy()

If lastpressed > 0 Then press = lastpressed

Text 0,160,"Button Pressed: " + ButtonDefs[press]

Text 0,200,"Press Escape to quit"






End Function