static void print_joystick_info(ALLEGRO_JOYSTICK *joy)
{
   int i, n, a;

   if (!joy)
      return;

   log_printf("Joystick: '%s'\n", al_get_joystick_name(joy));

   log_printf("  Buttons:");
   n = al_get_joystick_num_buttons(joy);
   for (i = 0; i < n; i++) {
      log_printf(" '%s'", al_get_joystick_button_name(joy, i));
   }
   log_printf("\n");

   n = al_get_joystick_num_sticks(joy);
   for (i = 0; i < n; i++) {
      log_printf("  Stick %d: '%s'\n", i, al_get_joystick_stick_name(joy, i));

      for (a = 0; a < al_get_joystick_num_axes(joy, i); a++) {
         log_printf("    Axis %d: '%s'\n",
            a, al_get_joystick_axis_name(joy, i, a));
      }
   }
}
Ejemplo n.º 2
0
GameSequence *IntroSequence::doTick(ALLEGRO_BITMAP *screen_buffer,
                                    bool key_pressed[ALLEGRO_KEY_MAX],
                                    bool key_down[ALLEGRO_KEY_MAX],
                                    bool *exit_game, double dt) {
  iZoom = (iZoom - iZoomSpeed);
  if (iZoom < 1.0) {
    iZoom = 1;
    isRunning = false;
  }

  clear_bitmap(iDoublebuffer);
  DrawZoomedLogoInCenter(mini, maxi);
  // draw 2 horizontal lines
  hline(iDoublebuffer, 0, 0, width, al_map_rgb(255, 255, 255));
  hline(iDoublebuffer, 0, IntroSequence::maxi - IntroSequence::mini - 1, width,
        al_map_rgb(255, 255, 255));

  // blit to the screen
  blit(iDoublebuffer, screen_buffer, 0, 0, 0, mini, width, maxi - mini);

  if (key_pressed[ALLEGRO_KEY_ESCAPE] && canQuickExit) {
    quickExit = true;
    isRunning = false;
  }

  if (joystick_action_timer.is_running())
    joystick_action_timer.tick();

  bool startgame = false;
  bool exit = false;
  bool reload = false;

  if (!quickExit && !isRunning) {
    black = al_map_rgb(0, 0, 0);
    red = al_map_rgb(255, 0, 0);
    lightred = al_map_rgb(255, 75, 75);

    handle_key_presses(key_pressed, &reload, &startgame, &exit);

    char layout_str[1000];
    auto font = GameManager::font;

    MenuHandler mh;

    mh.reset();
    mh.selected_idx = menuselected;
    mh.maxi = maxi;
    mh.width = width;
    mh.max_visible_lines = 25;

    mh.addline("Start game");
    mh.addline("Options:", false, 15);

    snprintf(menutext, sizeof(menutext), "   Players - %d   ", playerschoice);
    mh.addline(menutext);

    snprintf(menutext, sizeof(menutext), "   Level - %d   ", levelchoice + 1);
    mh.addline(menutext);

    snprintf(menutext, sizeof(menutext), "   Lives - %d   ", liveschoice);
    mh.addline(menutext);

    snprintf(menutext, sizeof(menutext), "   Use DCA - %s   ",
             ((dcachoice) ? "yes" : "no"));
    mh.addline(menutext);

    snprintf(menutext, sizeof(menutext), "   Wall Collision - %s   ",
             ((wallchoice) ? "yes" : "no"));
    mh.addline(menutext);

    mh.addline("Controls:", false, 15);

    snprintf(menutext, sizeof(menutext), "   Player 1 - %s",
             get_control_id_as_string(playercontrols[0]));
    mh.addline(menutext);

    snprintf(menutext, sizeof(menutext), "   Player 2 - %s",
             get_control_id_as_string(playercontrols[1]));
    mh.addline(menutext);

    snprintf(menutext, sizeof(menutext), "   Player 3 - %s",
             get_control_id_as_string(playercontrols[2]));
    mh.addline(menutext);

    snprintf(menutext, sizeof(menutext), "   Player 4 - %s",
             get_control_id_as_string(playercontrols[3]));
    mh.addline(menutext);

    mh.addline("Controller layouts:", false, 15);
    
    menu_joy_kbd_idx = 10;
  
    menu_kbd_layout1_idx = 0;
    menu_kbd_layout2_idx = 0;
    menu_kbd_layout3_idx = 0;
    menu_kbd_layout4_idx = 0;
    menu_kbd_layout_end = 0;
  
    menu_joy_layout1_idx = 0;
    menu_joy_layout2_idx = 0;
    menu_joy_layout3_idx = 0;
    menu_joy_layout4_idx = 0;
    menu_joy_layout_end = 0;
    
    if (GameManager::num_joysticks_loaded > 0) {
      for (int i = 0; i < GameManager::num_joysticks_loaded; i++) {
        switch (i) {
          case 0:
            menu_joy_layout1_idx = menu_joy_kbd_idx;
            break;
          case 1:
            menu_joy_layout2_idx = menu_joy_kbd_idx;
            break;
          case 2:
            menu_joy_layout3_idx = menu_joy_kbd_idx;
            break;
          case 3:
            menu_joy_layout4_idx = menu_joy_kbd_idx;
            break;
        }
        snprintf(menutext, sizeof(menutext), "   Joystick %d %s", (i + 1), al_get_joystick_name(GameManager::joysticks[i]->joy));
        mh.addline(menutext, false, 10);
        snprintf(menutext, sizeof(menutext), "      Left   - %s",
                 button_to_str(mapping_joy::btn_sets[i][0]));
        mh.addline(menutext);
        snprintf(menutext, sizeof(menutext), "      Right  - %s",
                 button_to_str(mapping_joy::btn_sets[i][1]));
        mh.addline(menutext);
        snprintf(menutext, sizeof(menutext), "      Thrust - %s",
                 button_to_str(mapping_joy::btn_sets[i][2]));
        mh.addline(menutext);
        snprintf(menutext, sizeof(menutext), "      Shield - %s",
                 button_to_str(mapping_joy::btn_sets[i][3]));
        mh.addline(menutext);
        snprintf(menutext, sizeof(menutext), "      Fire   - %s",
                 button_to_str(mapping_joy::btn_sets[i][4]));
        mh.addline(menutext);
        menu_joy_kbd_idx = menu_joy_kbd_idx + 5;
        menu_joy_layout_end = menu_joy_kbd_idx;
      }
    }

    for (int i = 0; i < 4; i++) {
      switch (i) {
        case 0:
          menu_kbd_layout1_idx = menu_joy_kbd_idx;
          break;
        case 1:
          menu_kbd_layout2_idx = menu_joy_kbd_idx;
          break;
        case 2:
          menu_kbd_layout3_idx = menu_joy_kbd_idx;
          break;
        case 3:
          menu_kbd_layout4_idx = menu_joy_kbd_idx;
          break;
      }
      
      snprintf(menutext, sizeof(menutext), "   Keyboard %d", (i + 1));
      mh.addline(menutext, false, 10);
      snprintf(menutext, sizeof(menutext), "      Left   - %s",
               key_to_str(mapping_key::key_sets[i][0]));
      mh.addline(menutext);
      snprintf(menutext, sizeof(menutext), "      Right  - %s",
               key_to_str(mapping_key::key_sets[i][1]));
      mh.addline(menutext);
      snprintf(menutext, sizeof(menutext), "      Thrust - %s",
               key_to_str(mapping_key::key_sets[i][2]));
      mh.addline(menutext);
      snprintf(menutext, sizeof(menutext), "      Shield - %s",
               key_to_str(mapping_key::key_sets[i][3]));
      mh.addline(menutext);
      snprintf(menutext, sizeof(menutext), "      Fire   - %s",
               key_to_str(mapping_key::key_sets[i][4]));
      mh.addline(menutext);
      menu_joy_kbd_idx = menu_joy_kbd_idx + 5;
      menu_kbd_layout_end = menu_joy_kbd_idx;
    }

    snprintf(menutext, sizeof(menutext), "Resolution (%ix%i):   ", width,
             height);
    mh.addline(menutext, false, 15);

    menu_resolution_idx = menu_joy_kbd_idx;
    menu_exit_idx = menu_resolution_idx + 1;
    menuitems = menu_exit_idx + 1;

    if (width == GameManager::native_width &&
        height == GameManager::native_height)
      snprintf(menutext, sizeof(menutext), "   Switch to Low - 1024x768   ");
    else
      snprintf(menutext, sizeof(menutext), "   Switch to Native - %ix%i   ",
               GameManager::native_width, GameManager::native_height);
    mh.addline(menutext);

    mh.addline("Exit", true, 15);

    mh.draw(screen_buffer, font);
  }

  *exit_game = exit;

  GameSequence *seq = nullptr;
  if (startgame) {
    iZoom = iZoomMax;
    seq = new BattleSequence(this, playerschoice, playerschoice, liveschoice,
                             levelchoice, dcachoice, wallchoice, width, height,
                             playercontrols);
  } else if (reload)
    seq = new IntroSequence(NULL, 10.0, 0.5, playerschoice, levelchoice,
                            liveschoice, dcachoice, wallchoice);
  else
    seq = ReturnScreen();

  return seq;
}