Example #1
0
static az_mode_t run_title_mode(void) {
  az_init_title_state(&title_state, &highscore_list, last_game);

  while (true) {
    // Tick the state and redraw the screen.
    az_tick_title_state(&title_state, 1.0 / 60.0);
    az_tick_audio_mixer(&title_state.soundboard);
    az_start_screen_redraw(); {
      az_draw_title_screen(&title_state);
    } az_finish_screen_redraw();

    // Get and process GUI events.
    az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_RETURN) return PLAY_MODE;
          break;
        case AZ_EVENT_MOUSE_DOWN:
          return PLAY_MODE;
        default: break;
      }
    }
  }
}
Example #2
0
static az_mode_t run_gameover_mode(void) {
  az_init_gameover_state(&gameover_state);
  gameover_state.last_wave = play_state.current_wave;
  gameover_state.score = play_state.score;
  az_highscore_t *entry = az_submit_highscore(
      &highscore_list, gameover_state.score, gameover_state.last_wave);
  gameover_state.is_high_score = (entry != NULL);

  bool done = false;
  while (!done) {
    // Tick the state and redraw the screen.
    az_tick_audio_mixer(&gameover_state.soundboard);
    az_start_screen_redraw(); {
      az_draw_gameover_screen(&gameover_state);
    } az_finish_screen_redraw();

    // Get and process GUI events.
    az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_RETURN) done = true;
          else if (event.key.id == AZ_KEY_BACKSPACE) {
            if (gameover_state.cursor > 0) {
              gameover_state.name_buffer[--gameover_state.cursor] = '\0';
            }
          } else if (gameover_state.cursor < 20 &&
                     event.key.character > '\0' &&
                     strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "abcdefghijklmnopqrstuvwxyz"
                            "0123456789 -_.,?/!@#$%^&*()|~",
                            event.key.character) != NULL) {
            gameover_state.name_buffer[gameover_state.cursor++] =
              event.key.character;
          }
          break;
        case AZ_EVENT_MOUSE_DOWN:
          if (!gameover_state.is_high_score) done = true;
          break;
        default: break;
      }
    }
  }

  if (entry != NULL) {
    entry->name = az_strdup(gameover_state.cursor == 0 ?
                            "Mysterious Stranger" :
                            gameover_state.name_buffer);
    save_highscore_list();
  }
  last_game = entry;
  return TITLE_MODE;
}
Example #3
0
static az_mode_t run_play_mode(void) {
  az_init_play_state(&play_state);
  az_set_mouse_position(MOUSE_NEUTRAL_X, MOUSE_NEUTRAL_Y);

  while (true) {
    // Tick the state and redraw the screen.
    az_tick_play_state(&play_state, 1.0 / 60.0);
    az_tick_audio_mixer(&play_state.soundboard);
    if (play_state.num_lives < 0) return GAMEOVER_MODE;
    az_start_screen_redraw(); {
      az_draw_play_screen(&play_state);
    } az_finish_screen_redraw();

    // Get and process GUI events.
    az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (event.key.id == AZ_KEY_ESCAPE) return GAMEOVER_MODE;
          else if (event.key.id == AZ_KEY_SPACE) {
            az_play_apply_spacebar(&play_state);
          }
          break;
        case AZ_EVENT_MOUSE_DOWN:
          az_play_apply_mouse_click(&play_state);
          break;
        case AZ_EVENT_MOUSE_MOVE:
          az_play_apply_mouse_motion(&play_state,
                                     event.mouse.x - MOUSE_NEUTRAL_X,
                                     event.mouse.y - MOUSE_NEUTRAL_Y);
          az_set_mouse_position(MOUSE_NEUTRAL_X, MOUSE_NEUTRAL_Y);
          break;
        default: break;
      }
    }
  }
}
Example #4
0
az_paused_action_t az_paused_event_loop(
    const az_planet_t *planet, az_preferences_t *prefs,
    az_ship_t *ship) {
  static az_paused_state_t state;
  az_init_paused_state(&state, planet, prefs, ship);
  az_player_t *player = &ship->player;

  bool prefs_changed = false;

  while (true) {
    // Tick the state and redraw the screen.
    az_tick_paused_state(&state, 1.0/60.0);
    az_tick_audio(&state.soundboard);
    az_start_screen_redraw(); {
      az_paused_draw_screen(&state);
    } az_finish_screen_redraw();

    // Get and process GUI events.
    az_event_t event;
    while (az_poll_event(&event)) {
      switch (event.kind) {
        case AZ_EVENT_KEY_DOWN:
          if (state.do_quit) break;
          if (state.prefs_pane.selected_key_picker_index >= 0) {
            az_prefs_try_pick_key(&state.prefs_pane, event.key.id,
                                  &state.soundboard);
            break;
          }
          switch (event.key.id) {
            case AZ_KEY_RETURN: return AZ_PA_RESUME;
            case AZ_KEY_1: az_select_gun(player, AZ_GUN_CHARGE); break;
            case AZ_KEY_2: az_select_gun(player, AZ_GUN_FREEZE); break;
            case AZ_KEY_3: az_select_gun(player, AZ_GUN_TRIPLE); break;
            case AZ_KEY_4: az_select_gun(player, AZ_GUN_HOMING); break;
            case AZ_KEY_5: az_select_gun(player, AZ_GUN_PHASE);  break;
            case AZ_KEY_6: az_select_gun(player, AZ_GUN_BURST);  break;
            case AZ_KEY_7: az_select_gun(player, AZ_GUN_PIERCE); break;
            case AZ_KEY_8: az_select_gun(player, AZ_GUN_BEAM);   break;
            case AZ_KEY_9: az_select_ordnance(player, AZ_ORDN_ROCKETS); break;
            case AZ_KEY_0: az_select_ordnance(player, AZ_ORDN_BOMBS);   break;
            default:
              if (event.key.id ==
                  state.prefs->keys[AZ_PREFS_PAUSE_KEY_INDEX]) {
                return AZ_PA_RESUME;
              } else if (event.key.id ==
                         state.prefs->keys[AZ_PREFS_FIRE_KEY_INDEX]) {
                state.current_drawer = AZ_PAUSE_DRAWER_UPGRADES;
              } else if (event.key.id ==
                         state.prefs->keys[AZ_PREFS_ORDN_KEY_INDEX]) {
                state.current_drawer = AZ_PAUSE_DRAWER_MAP;
              } else if (event.key.id ==
                         state.prefs->keys[AZ_PREFS_UTIL_KEY_INDEX]) {
                state.current_drawer = AZ_PAUSE_DRAWER_OPTIONS;
              }
              break;
          }
          break;
        case AZ_EVENT_MOUSE_DOWN:
          az_paused_on_click(&state, event.mouse.x, event.mouse.y);
          break;
        case AZ_EVENT_MOUSE_MOVE:
          az_paused_on_hover(&state, event.mouse.x, event.mouse.y);
          break;
        default: break;
      }
    }

    az_update_prefefences(&state.prefs_pane, prefs, &prefs_changed);

    if (state.quitting_fade_alpha >= 1.0) {
      assert(state.do_quit);
      return AZ_PA_EXIT_TO_TITLE;
    }
  }
}