Example #1
0
File: Game.cpp Project: ziz/solarus
/**
 * @brief Handles the transitions.
 *
 * This functions changes the map when needed and plays the
 * transitions between the two maps. This function is called
 * by the update() function.
 * Note that the two maps can actually be the same.
 */
void Game::update_transitions() {

  if (transition != NULL) {
    transition->update();
  }

  // if the map has just changed, close the current map if any and play an out transition
  if (next_map != NULL && transition == NULL) { // the map has changed (i.e. set_current_map has been called)

    if (current_map == NULL) { // special case: no map was playing, so we don't have any out transition to do
      load_dungeon();
      current_map = next_map;
      next_map = NULL;
    }
    else { // normal case: stop the control and play an out transition before leaving the current map
      transition = Transition::create(transition_style, Transition::OUT, this);
      transition->start();
    }
  }

  Rectangle previous_map_location = current_map->get_location();

  // if a transition was playing and has just been finished
  if (transition != NULL && transition->is_finished()) {

    Transition::Direction transition_direction = transition->get_direction();
    bool needs_previous_surface = transition->needs_previous_surface();
    delete transition;
    transition = NULL;

    if (reseting) {
      current_map->unload();
      set_next_screen(new TitleScreen(solarus));
    }
    else if (restarting) {
      current_map->unload();
      set_next_screen(new Game(solarus, savegame));
    }
    else if (transition_direction == Transition::OUT) {

      if (next_map == current_map) {
        // same map
        hero->place_on_destination_point(*current_map, previous_map_location);
        transition = Transition::create(transition_style, Transition::IN, this);
        transition->start();
        next_map = NULL;
      }
      else {

        // change the map
        current_map->leave();

        // special treatments for an inside/outside transition
        if ((current_map->is_in_outside_world() && !next_map->is_in_outside_world())
            || (!current_map->is_in_outside_world() && next_map->is_in_outside_world())) {

          // reset the crystal switch blocks
          crystal_switch_state = false;

          // save the location
          savegame.set_integer(Savegame::STARTING_MAP, next_map->get_id());
          savegame.set_string(Savegame::STARTING_POINT, next_map->get_destination_point_name());
        }

        // before closing the map, draw it on a backup surface for transition effects
        // that want to display both maps at the same time
        if (needs_previous_surface) {
          previous_map_surface = new Surface(320, 240);
          current_map->display();
          current_map->get_visible_surface()->blit(previous_map_surface);
        }

        // set the next map
        load_dungeon();
        current_map->unload();
        delete current_map;
        current_map = next_map;
        next_map = NULL;
      }
    }
    else {
      current_map->notify_opening_transition_finished();

      if (previous_map_surface != NULL) {
        delete previous_map_surface;
        previous_map_surface = NULL;
      }
    }
  }

  // if a map has just been set as the current map, start it and play the in transition
  if (!current_map->is_started()) {
    transition = Transition::create(transition_style, Transition::IN, this);

    if (previous_map_surface != NULL) {
      // some transition effects need to display both maps simultaneously
      transition->set_previous_surface(previous_map_surface);
    }

    hero->place_on_destination_point(*current_map, previous_map_location);
    transition->start();
    current_map->start();
  }
}
Example #2
0
void test_load() {
	player_descr* pc = malloc(sizeof(player_descr));
	FILE* example = fopen("example.txt", "r");
	dungeon* d = load_dungeon(example, pc);
	destroy_dungeon(d);		
}