new better improved and "GE" styled version - see last post. please let me know if it works or not..
the attached example uses the cursor keys to emulate joystick controls using a function
EDIT - old versions/notes removed .. now redundant
feral wrote:note2: currently stops if both left and right are pressed and then up or down are pressed as well.. I will fix that soon
GetJoyState(4);
if (joy[JOY_RIGHT]==1)
{
x=x+2;
}
int joy[255];
#define JOY_RIGHT 2
#define JOY_LEFT 4
#define JOY_UP 8
#define JOY_DOWN 16
#define JOY_UP_LEFT 12
#define JOY_UP_RIGHT 10
#define JOY_DOWN_LEFT 20
#define JOY_DOWN_RIGHT 18
// following defines are not needed but are defined to allow mismatching
#define JOY_LEFT_UP 12
#define JOY_RIGHT_UP 10
#define JOY_LEFT_DOWN 20
#define JOY_RIGHT_DOWN 18
void GetJoyState(int type)
{
char *key = GetKeyState(); //Get entire keyboard state
char combox=0;
char comboy=0;
char lastXkey;
char lastYkey;
joy[2]=joy[4]=joy[8]=joy[16]=joy[10]=joy[12]=joy[18]=joy[20]=0;
if(key[KEY_RIGHT] == 1 && key[KEY_LEFT]==0) //Test if right key is pressed
{
joy[JOY_RIGHT]=1;
joy[JOY_LEFT]=0;
lastXkey=4;
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0) //Test if left key is pressed
{
joy[JOY_RIGHT]=0;
joy[JOY_LEFT]=1;
lastXkey=2;
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1) //Test if left key is pressed
{
joy[JOY_RIGHT]=0;
joy[JOY_LEFT]=0;
joy[lastXkey]=1;
}
if(key[KEY_UP] == 1 && key[KEY_DOWN]==0) //Test if right key is pressed
{
joy[JOY_UP]=1;
joy[JOY_DOWN]=0;
lastYkey=16;
}
if(key[KEY_DOWN] == 1 && key[KEY_UP] == 0) //Test if left key is pressed
{
joy[JOY_UP]=0;
joy[JOY_DOWN]=1;
lastYkey=8;
}
if(key[KEY_UP] == 1 && key[KEY_DOWN] == 1) //Test if left key is pressed
{
joy[JOY_UP]=0;
joy[JOY_DOWN]=0;
joy[lastYkey]=1;
}
if (type==8)
{
if (joy[JOY_UP]==1 && joy[JOY_RIGHT]==1)
{
joy[JOY_UP]=0;
joy[JOY_RIGHT]=0;
joy[JOY_UP_RIGHT]=1;
}
if (joy[JOY_UP]==1 && joy[JOY_LEFT]==1)
{
joy[JOY_UP]=0;
joy[JOY_LEFT]=0;
joy[JOY_UP_LEFT]=1;
}
if (joy[JOY_DOWN]==1 && joy[JOY_RIGHT]==1)
{
joy[JOY_DOWN]=0;
joy[JOY_RIGHT]=0;
joy[JOY_DOWN_RIGHT]=1;
}
if (joy[JOY_DOWN]==1 && joy[JOY_LEFT]==1)
{
joy[JOY_DOWN]=0;
joy[JOY_LEFT]=0;
joy[JOY_DOWN_LEFT]=1;
}
} //end if type
} //end function
Users browsing this forum: No registered users and 1 guest