Let’s see
I have had my input handled for a midp1 game more or less like…
protected void keyPressed(int keycode) {//TODO poner en funcion de controles definidos
switch(keycode){
case -1:
joy_map = joy_map | 1;
break;
case -2:
joy_map = joy_map | 2;
break;
case -3:
joy_map = joy_map | 4;
break;
case -4:
joy_map = joy_map | 8;
break;
}
}
but with larger switch blocks.
I want to make the controls customizable, so the player can define his own way to interact with the game and to bypass the odd keycode changes for the cursor / joystick / whatever depending on the manufacturer of the handset.
I used to define an int[] teclas with the mapping of all the keys, but as long as case expressions can only contain final + static values i had to rely on long if-else blocks, which are slower than switch ones:
protected void keyPressed(int keycode) {
if(Juego.teclas[Juego.CUR_UP] == keycode){
joystick = joystick | 1;
}else if(Juego.teclas[Juego.CUR_DWN] == keycode){
joystick = joystick | 2;
}else if(Juego.teclas[Juego.CUR_LFT] == keycode){
joystick = joystick | 4;
}else if(Juego.teclas[Juego.CUR_RGT] == keycode){
joystick = joystick | 8;
}else if(Juego.teclas[Juego.CUR_CEN] == keycode){
joystick = joystick | 16;
}
etc...
}
Is there a way to map the control to constant values or will i have to rely on if-else blocks?
thanks