bool update_game() { int in = get_input(get_map_window()); if(in == INPUT_ACTION && get_last_action() == ACTION_QUIT) return false; else if(in == INPUT_ACTION && (get_last_action() == ACTION_SCROLL_UP || get_last_action() == ACTION_SCROLL_DOWN)) { log_scroll(get_last_action() == ACTION_SCROLL_UP); draw_log(); } else if(!dead) { update_player(); if(get_current_floor() != current_level) { set_current_map(world[get_current_floor()], current_level < get_current_floor(), current_level > get_current_floor()); current_level = get_current_floor(); } update_map(1, world[current_level]); if(is_dead()) { add_message(COLOR_HP_CRIT, "Oh dear, you've died!"); add_message(COLOR_DEFAULT, "Press q to return to the main menu"); dead = true; } if(game_won()) dead = true; draw_log(); } return true; }
/** * @brief Creates a game. * @param solarus the application object * @param savegame the saved data of this game (the specified object will be copied and stored into the game) */ Game::Game(Solarus &solarus, Savegame &savegame): Screen(solarus), savegame(savegame), pause_key_available(true), pause_menu(NULL), gameover_sequence(NULL), reseting(false), restarting(false), keys_effect(NULL), current_map(NULL), next_map(NULL), previous_map_surface(NULL), transition_style(Transition::IMMEDIATE), transition(NULL), dungeon(NULL), crystal_switch_state(false), hud(NULL), hud_enabled(true), dialog_box(NULL) { // notify objects get_equipment().set_game(*this); solarus.get_debug_keys().set_game(this); // initialize members controls = new GameControls(*this); dialog_box = new DialogBox(*this); hero = new Hero(get_equipment()); keys_effect = new KeysEffect(); hud = new HUD(*this); // launch the starting map set_current_map(savegame.get_integer(Savegame::STARTING_MAP), "", Transition::FADE); }
/** * \brief Creates a game. * \param main_loop The Solarus root object. * \param savegame The saved data of this game. Will be deleted in the * destructor unless someone is still using it (the refcount info is used). */ Game::Game(MainLoop& main_loop, Savegame* savegame): main_loop(main_loop), savegame(savegame), pause_allowed(true), paused(false), dialog_box(*this), showing_game_over(false), started(false), restarting(false), keys_effect(NULL), current_map(NULL), next_map(NULL), previous_map_surface(NULL), transition_style(Transition::IMMEDIATE), transition(NULL), crystal_state(false) { // notify objects RefCountable::ref(savegame); savegame->set_game(this); // initialize members commands = new GameCommands(*this); hero = new Hero(get_equipment()); RefCountable::ref(hero); keys_effect = new KeysEffect(); update_keys_effect(); // Maybe we are restarting after a game-over sequence. if (get_equipment().get_life() <= 0) { get_equipment().restore_all_life(); } // Launch the starting map. std::string starting_map_id = savegame->get_string(Savegame::KEY_STARTING_MAP); std::string starting_destination_name = savegame->get_string(Savegame::KEY_STARTING_POINT); bool valid_map_saved = false; if (!starting_map_id.empty()) { if (QuestResourceList::exists(QuestResourceList::RESOURCE_MAP, starting_map_id)) { // We are okay: the savegame file refers to an existing map. valid_map_saved = true; } else { // The savegame refers to a map that no longer exists. // Maybe the quest is in an intermediate development phase. // Show an error and fallback to the default map. Debug::error(std::string("The savegame refers to a non-existing map: '") + starting_map_id + "'"); } } if (!valid_map_saved) { // When no valid starting map is set, use the first one declared in the // resource list file. const std::vector<QuestResourceList::Element>& maps = QuestResourceList::get_elements(QuestResourceList::RESOURCE_MAP); if (maps.empty()) { Debug::die("This quest has no map"); } starting_map_id = maps[0].first; starting_destination_name = ""; // Default destination. } set_current_map(starting_map_id, starting_destination_name, Transition::FADE); }