Enable the keyboard and controller all in 1
- Code: Select all
//Generate Definitions
#define true 1
#define false 0
#define Joy1 BUTTON[0]
#define Joy2 BUTTON[2]
#define Joy3 BUTTON[3]
#define Joy4 BUTTON[4]
#define Joy5 BUTTON[5]
#define Joy6 BUTTON[6]
#define Joy7 BUTTON[7]
#define Joy8 BUTTON[8]
#define Joy9 BUTTON[9]
#define xaxis JoyX
#define yaxis JoyY
//Code Variables
char *key;
int BUTTON[10];
double JOYX, JOYY;
//Enable Controls
void EnableControls(int JOY, int KBD) {
int i;
JOYX=GetJoystick1Axis(0);
JOYY=GetJoystick1Axis(1);
switch(JOY) {
case 0:
break; case 1:
for (i=0;i<9;i++) {
BUTTON[i]=GetJoystick1Button(i);
}
break; }
switch(KBD) {
case 0:
break; case 1:
key=GetKeyState();
break; }
}
Usage:
- Code: Select all
EnableControls(true, true);
The first true is the joystick, to disable the joystick simply put false. The second one is they keyboard.
Extra config for easier access to controls:
- Code: Select all
//Create easy name for variables
#define var int
//Offset Variable for joystick
var Offset=10000;
//Define Controls for keyboard
#define KeyRight key[KEY_d]
#define KeyLeft key[KEY_a]
#define KeyUp key[KEY_w]
#define KeyDown key[KEY_s]
#define KeyB1 key[KEY_i]
#define KeyB2 key[KEY_l]
#define KeyB3 key[KEY_k]
#define KeyB4 key[KEY_j]
#define KeyB5 key[KEY_q]
#define KeyB6 key[KEY_e]
#define KeyB7 key[KEY_u]
#define KeyB8 key[KEY_o]
#define KeyB9 key[KEY_f]
#define KeyB10 key[KEY_g]
#define Press_DOWN (KeyDown==1 || yaxis>Offset)
#define Press_UP (KeyUp==1 || yaxis<-Offset)
#define Press_LEFT (KeyLeft==1 || yaxis<-Offset)
#define Press_RIGHT (KeyRight==1 || yaxis<-Offset)
#define Press_B1 (KeyB1==1 || BUTTON[0]==1)
#define Press_B2 (KeyB2==1 || BUTTON[1]==1)
#define Press_B3 (KeyB3==1 || BUTTON[2]==1)
#define Press_B4 (KeyB4==1 || BUTTON[3]==1)
#define Press_B5 (KeyB5==1 || BUTTON[4]==1)
#define Press_B6 (KeyB6==1 || BUTTON[5]==1)
#define Press_B7 (KeyB7==1 || BUTTON[6]==1)
#define Press_B8 (KeyB8==1 || BUTTON[7]==1)
#define Press_B9 (KeyB9==1 || BUTTON[8]==1)
#define Press_B10 (KeyB10==1 || BUTTON[9]==1)
usage of combined codes:
- Code: Select all
EnableControls(true, true);
if (Press_DOWN) {
y+=5; }
else if (Press_UP) {
y-=5; }
With that you can do just about anything :3