+ if(num_joysticks) {
+ SDL_JoystickUpdate();
+ if(opt_joystick_enabled) {
+ x_move = SDL_JoystickGetAxis(joysticks[opt_joystick_number], opt_joystick_x_axis);
+ y_move = SDL_JoystickGetAxis(joysticks[opt_joystick_number], opt_joystick_y_axis);
+ button_pressed = 0;
+ for(i = 1; i <= SDL_JoystickNumButtons(joysticks[opt_joystick_number]); i++)
+ {
+ if(SDL_JoystickGetButton(joysticks[opt_joystick_number], i) == 1)
+ {
+ button_pressed = 1;
+ break;
+ }
+ }
+ } else { // there is at least one joystick, but it hasn't been enabled yet
+ // if any joystick has a button down, enable that joystick
+ for(j = 0; j <= num_joysticks; j++) {
+ for(i = 1; i <= SDL_JoystickNumButtons(joysticks[j]); i++)
+ {
+ if(SDL_JoystickGetButton(joysticks[j], i) == 1)
+ {
+ opt_joystick_enabled = 1;
+ opt_joystick_number = j;
+printf("enabled joystick #%i\n", opt_joystick_number);
+ if(state != GAMEPLAY) {
+ // first (enabling) press of the joystick
+ // button should start a game, but should
+ // not pause a running game
+ button_pressed = 1;
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+