Multi by DarkPhear17th Jun 2004 19:31
|
---|
Summary Use multiple joypads in your game with GLFW.DLL and my functions. Description `This code shows how to use multiple joypads in Dark Basic Pro with GLFW.DLL. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `------------------------------------------------------------------ `Unified Multi-Joypad/Joystick Functions by Cleber de Mattos Casali `------------------------------------------------------------------ `This code shows how to use multiple joypads in Dark Basic Pro. `Feel free to use it in your programs, and please give me and Marcus `Geelnard some credit. The code requires GLFW.DLL, wich is a part of the `great... `------------------------------------------------------------------------ `GLFW OpenGL framework `http://glfw.sourceforge.net `Copyright (c) 2002-2004 Marcus Geelnard `This software is provided 'as-is', without any express or implied `warranty. In no event will the authors be held liable for any damages `arising from the use of this software. `Permission is granted to anyone to use this software for any purpose, `including commercial applications, and to alter it and redistribute it `freely, subject to the following restrictions: `1. The origin of this software must not be misrepresented; you must not ` claim that you wrote the original software. If you use this software ` in a product, an acknowledgment in the product documentation would ` be appreciated but is not required. `2. Altered source versions must be plainly marked as such, and must not ` be misrepresented as being the original software. `3. This notice may not be removed or altered from any source ` distribution. `Marcus Geelnard `marcus.geelnard at home.se `------------------------------------------------------------------------ `My functions require glfw.dll (pollmethod=0) to poll the devices. Using `this pollmethod you can poll up to 16 control devices in your game or `application. :) `Using pollmethod=1 will poll the current dbpro controller using a fix I `have created for the Sega Genesis 6-button pad + DirectPadPro combo. The `joyid and lastbutton parameters will be ignored. `Any other value for pollmethod will poll the current control device from `dbpro, using its defaults, and the joyid parameter will be ignored. `If you're going to use method 0 you must define the constants below and `then call StartJoy(). To use my functions, you will have to dim the `JoyState() array. Call JoyPoll() every time you want to update the given `joypad's information, let's say at every frame. When JoyPoll() is called, `all joypad polled data will be stored on a given index position in the `JoyState() array. Then you can retrieve the data stored in JoyState() in `your program, like you do with keystate(). `JoyPoll() parameters: ` `JoyStatepos : the position of the joypad data in JoyState() `joyid : the ID number of the polled device (for method 0 only) `lastbutton : the number of buttons of the device `pollmethod : 0=GLFW.DLL 1=Sega Genesis 6b+DBPRO any_other=DBPRO `Copyright (c) 2004 Cleber de Mattos Casali `http://darkphear.cjb.net `---------------------------------- `SAMPLE PROGRAM - POLLING 3 JOYPADS `---------------------------------- `enable sync sync on sync rate 0 `GLFW required constants #constant _glfwdll 1 #constant _joymemblock 1 `array to store joypad data dim JoyState(16,34) `JoyPad (device index position,axis/buttons index) `initialise glfw.dll StartJoy() do `poll joypad 0, store at JoyState(0,x), 8 buttons, using meth.0 (glfw.dll) PollJoy(0,0,8,0) `poll joypad 1, store at JoyState(1,x), 8 buttons, using meth.0 (glfw.dll) PollJoy(1,1,8,0) `poll joypad 2, store at JoyState(2,x), 6 buttons, using meth.0 (glfw.dll) PollJoy(2,2,6,0) `let's clear the screen and print some joypad readings :) cls 0 for j=0 to 2 for i=0 to 9 print str$(JoyState(j,i)); next i print next j print screen fps() sync if inkey$()<>"" then goto quit loop quit: end function StartJoy() load dll "glfw.dll",_glfwdll call dll _glfwdll,"glfwInit" make memblock _joymemblock,44 endfunction function PollJoy(JoyStatepos,joyid,lastbutton,pollmethod) select pollmethod case 0 `poll a device using glfw.dll call dll _glfwdll,"glfwGetJoystickPos",joyid,get memblock ptr(_joymemblock),2 call dll _glfwdll,"glfwGetJoystickButtons",joyid,get memblock ptr(_joymemblock)+8,lastbutton JoyState(JoyStatepos,0)=(memblock float(_joymemblock,0)>.9)-(memblock float(_joymemblock,0)<-.9) JoyState(JoyStatepos,1)=(memblock float(_joymemblock,4)<-.9)-(memblock float(_joymemblock,4)>.9) for i=0 to lastbutton JoyState(JoyStatepos,i+2)=memblock byte(_joymemblock,i+8) next i endcase case 1 `dbpro current device + sega genesis 6b fix if timer()<>JoyState(JoyStatepos,10) inc JoyState(JoyStatepos,11) if JoyState(JoyStatepos,11)>4 then JoyState(JoyStatepos,11)=0 if JoyState(JoyStatepos,11)=3 then JoyState(JoyStatepos,11)=4 JoyState(JoyStatepos,JoyState(JoyStatepos,11)+5)=joystick fire x(JoyState(JoyStatepos,11)+3) endif i=joystick x() JoyState(JoyStatepos,0)=(i>900)-(i<-900) i=joystick y() JoyState(JoyStatepos,1)=(i>900)-(i<-900) for i=0 to 7 select i case 0,1,2,6:JoyState(JoyStatepos,i+2)=joystick fire x(i):endcase endselect next i JoyState(JoyStatepos,10)=timer() endcase case default `dbpro current device i=joystick x() JoyState(JoyStatepos,0)=(i>900)-(i<-900) i=joystick y() JoyState(JoyStatepos,1)=(i>900)-(i<-900) for i=0 to lastbutton-1 JoyState(JoyStatepos,i+2)=joystick fire x(i) next i endcase endselect endfunction |