03-12-2006, 09:50 AM
cha0s: handling both is relatively easy. Here's how I handled it in Phantasm:
-The game is configured for one of three methods: keyboard, analog gamepad, or POV gamepad. This configuration is set with an external config app.
-The program itself has a special function designed to abstract input. This function handles input for whichever device is configured to be used (gamepad or keyboard) and returns a standard control code. It's hard for me to explain at almost 1 in the morning, but basically this function returns a value based on the state of your configured keys or your gamepad, and does so in a standard way...say you have it configured for keyboard and the Up key was pressed...it would return a CTRL_UP constant value...but having the gamepad configured, pressing Up on the analog stick or the POV (depending on which config is used) would also return a CTRL_UP, so the whole process would be abstracted by the function.
-Your other functions simply call this abstraction function and operate based on its result. Since no other function has to care which input method you're using, your code works the same no matter what it's being controlled with.
This was a bit tricky to pull off but when it was finished, it was an extremely cool thing to have working. Sorry if I'm not explaining it very clear but as I said, it's almost 1 in the morning.
I could test it here, I have a POV gamepad, so no sweat.
EDIT: Here's the abstraction function I used for Phantasm. It's not the best function (it needs recoding) but I think it gets the point across:
This exact code is useless for an action game (since only one value can ever be returned) but the basic idea is there.
-The game is configured for one of three methods: keyboard, analog gamepad, or POV gamepad. This configuration is set with an external config app.
-The program itself has a special function designed to abstract input. This function handles input for whichever device is configured to be used (gamepad or keyboard) and returns a standard control code. It's hard for me to explain at almost 1 in the morning, but basically this function returns a value based on the state of your configured keys or your gamepad, and does so in a standard way...say you have it configured for keyboard and the Up key was pressed...it would return a CTRL_UP constant value...but having the gamepad configured, pressing Up on the analog stick or the POV (depending on which config is used) would also return a CTRL_UP, so the whole process would be abstracted by the function.
-Your other functions simply call this abstraction function and operate based on its result. Since no other function has to care which input method you're using, your code works the same no matter what it's being controlled with.
This was a bit tricky to pull off but when it was finished, it was an extremely cool thing to have working. Sorry if I'm not explaining it very clear but as I said, it's almost 1 in the morning.
I could test it here, I have a POV gamepad, so no sweat.
EDIT: Here's the abstraction function I used for Phantasm. It's not the best function (it needs recoding) but I think it gets the point across:
Code:
Function GetInput(Byval BlockingType As Byte = 0) As Byte
'this function returns the keying depending on the control scheme
Dim returnvalue As Byte, result As Integer, dumm As String
returnvalue = CTRL_NIL
Select Case GameCtrl
Case 0
'return values from the keyboard
dumm = Inkey$
If BlockingType = 1 Then
If dumm = Chr$(38) Then 'up
While Inkey$ <> "": Wend
returnvalue = CTRL_UP
End If
If dumm = Chr$(40) Then 'down
While Inkey$ <> "": Wend
returnvalue = CTRL_DOWN
End If
If dumm = Chr$(37) Then 'left
While Inkey$ <> "": Wend
returnvalue = CTRL_LEFT
End If
If dumm = Chr$(39) Then 'right
While Inkey$ <> "": Wend
returnvalue = CTRL_RIGHT
End If
Else
If GetKeyState(VK_LEFT) And &H80 Then returnvalue = CTRL_LEFT
If GetKeyState(VK_UP) And &H80 Then returnvalue = CTRL_UP
If GetKeyState(VK_RIGHT) And &H80 Then returnvalue = CTRL_RIGHT
If GetKeyState(VK_DOWN) And &H80 Then returnvalue = CTRL_DOWN
End If
If dumm = Chr$(13) Then
While Inkey$ <> "": Wend
returnvalue = CTRL_OK
End If
If dumm = Chr$(32) Then
While Inkey$ <> "": Wend
returnvalue = CTRL_OK
End If
If dumm = Chr$(27) Then
While Inkey$ <> "": Wend
returnvalue = CTRL_CANCEL
End If
Case 1
'if we're dealing with an analog control, get its axis values here
result = joyGetPosEx(0, joystick)
If joystick.dwXpos<30000 Then returnvalue = CTRL_LEFT
If joystick.dwXpos>36000 Then returnvalue = CTRL_RIGHT
If joystick.dwYpos<30000 Then returnvalue = CTRL_UP
If joystick.dwYpos>36000 Then returnvalue = CTRL_DOWN
Case 2
'if we're dealing with a POV HAT, get its d-pad value here
result = joyGetPosEx(0, joystick)
If joystick.dwPOV = 0 Then returnvalue = CTRL_UP
If joystick.dwPOV = 4500 Then returnvalue = CTRL_UP
If joystick.dwPOV = 9000 Then returnvalue = CTRL_RIGHT
If joystick.dwPOV = 13500 Then returnvalue = CTRL_RIGHT
If joystick.dwPOV = 18000 Then returnvalue = CTRL_DOWN
If joystick.dwPOV = 22500 Then returnvalue = CTRL_DOWN
If joystick.dwPOV = 27000 Then returnvalue = CTRL_LEFT
If joystick.dwPOV = 31500 Then returnvalue = CTRL_LEFT
End Select
'get buttons last so we can face and press at the same time and have the buttons register at a higher priority
If GameCtrl > 0 Then
If joystick.dwButtons = 1 Then returnvalue = CTRL_OK
If joystick.dwButtons = 2 Then returnvalue = CTRL_CANCEL
End If
GetInput = returnvalue
End Function
\__/)
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.