#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "supertux/levelintro.hpp"
+#include "supertux/levelset_screen.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/menu/options_menu.hpp"
#include "supertux/player_status.hpp"
+#include "supertux/savegame.hpp"
#include "supertux/screen_fade.hpp"
#include "supertux/screen_manager.hpp"
#include "supertux/sector.hpp"
#include "util/gettext.hpp"
#include "worldmap/worldmap.hpp"
-GameSession::GameSession(const std::string& levelfile_, PlayerStatus* player_status, Statistics* statistics) :
+GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Statistics* statistics) :
level(),
- statistics_backdrop(),
+ statistics_backdrop(Surface::create("images/engine/menu/score-backdrop.png")),
scripts(),
- currentsector(0),
+ currentsector(nullptr),
levelnb(),
pause_menu_frame(),
end_sequence(0),
- game_pause(),
- speed_before_pause(),
- levelfile(levelfile_),
+ game_pause(false),
+ speed_before_pause(g_screen_manager->get_speed()),
+ levelfile(levelfile_),
reset_sector(),
reset_pos(),
newsector(),
newspawnpoint(),
best_level_statistics(statistics),
- player_status(player_status),
- capture_demo_stream(0),
+ m_savegame(savegame),
+ capture_demo_stream(0),
capture_file(),
- playback_demo_stream(0),
+ playback_demo_stream(0),
demo_controller(0),
- play_time(0),
- edit_mode(false),
- levelintro_shown(false)
+ play_time(0),
+ edit_mode(false),
+ levelintro_shown(false),
+ coins_at_start(),
+ bonus_at_start(),
+ max_fire_bullets_at_start(),
+ max_ice_bullets_at_start()
{
- currentsector = NULL;
-
- game_pause = false;
- speed_before_pause = g_screen_manager->get_speed();
-
- statistics_backdrop = Surface::create("images/engine/menu/score-backdrop.png");
-
if (restart_level() != 0)
throw std::runtime_error ("Initializing the level failed.");
}
int
GameSession::restart_level()
{
- PlayerStatus* currentStatus = get_player_status();
+ PlayerStatus* currentStatus = m_savegame.get_player_status();
coins_at_start = currentStatus->coins;
bonus_at_start = currentStatus->bonus;
max_fire_bullets_at_start = currentStatus->max_fire_bullets;
}
} catch(std::exception& e) {
log_fatal << "Couldn't start level: " << e.what() << std::endl;
- g_screen_manager->exit_screen();
+ g_screen_manager->pop_screen();
return (-1);
}
else
log_info << "Demo file contains no random number" << std::endl;
}
+ delete test_stream;
+ test_stream = nullptr;
return 0;
}
if(!game_pause) {
speed_before_pause = g_screen_manager->get_speed();
g_screen_manager->set_speed(0);
- MenuManager::instance().set_current(MenuStorage::GAME_MENU);
+ MenuManager::instance().set_menu(MenuStorage::GAME_MENU);
game_pause = true;
}
void
GameSession::abort_level()
{
- MenuManager::instance().set_current(MenuStorage::NO_MENU);
- g_screen_manager->exit_screen();
+ MenuManager::instance().clear_menu_stack();
+ g_screen_manager->pop_screen();
currentsector->player->set_bonus(bonus_at_start);
- PlayerStatus *currentStatus = get_player_status();
+ PlayerStatus *currentStatus = m_savegame.get_player_status();
currentStatus->coins = coins_at_start;
currentStatus->max_fire_bullets = max_fire_bullets_at_start;
currentStatus->max_ice_bullets = max_ice_bullets_at_start;
void
GameSession::process_events()
{
- // end of pause mode?
- // XXX this looks like a fail-safe to unpause the game if there's no menu
- // XXX having it enabled causes some unexpected problems
- // XXX hopefully disabling it won't...
- /*
- if(!Menu::current() && game_pause) {
- game_pause = false;
- }
- */
-
// playback a demo?
if(playback_demo_stream != 0) {
demo_controller->update();
}
void
+GameSession::leave()
+{
+}
+
+void
GameSession::update(float elapsed_time)
{
// handle controller
if(g_input_manager->get_controller()->pressed(Controller::PAUSE_MENU))
+ {
on_escape_press();
+ }
+
+ if(g_input_manager->get_controller()->pressed(Controller::CHEAT_MENU))
+ {
+ game_pause = true;
+ MenuManager::instance().set_menu(MenuStorage::CHEAT_MENU);
+ }
process_events();
MenuManager::instance().check_menu();
if(win) {
if(WorldMap::current())
+ {
WorldMap::current()->finished_level(level.get());
+ }
+
+ if (LevelsetScreen::current())
+ {
+ LevelsetScreen::current()->finished_level(win);
+ }
}
- g_screen_manager->exit_screen();
+ g_screen_manager->pop_screen();
}
void
void
GameSession::drawstatus(DrawingContext& context)
{
- player_status->draw(context);
+ m_savegame.get_player_status()->draw(context);
// draw level stats while end_sequence is running
if (end_sequence) {