Let's see
I have had my input handled for a midp1 game more or less like...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| protected void keyPressed(int keycode) { 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| 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
