X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgame_session.cpp;h=058c14b7734833b983c7f8814d22549d9f0cead5;hb=75acd4b141f45e851a492f089aa9ad24a9552409;hp=707d597adc531bf198944b51fe55456cc7c8bbf4;hpb=d83146487eca3bb987302662f9acd0af13572ce5;p=supertux.git diff --git a/src/game_session.cpp b/src/game_session.cpp index 707d597ad..058c14b77 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -18,6 +18,8 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#include "game_session.hpp" + #include #include #include @@ -29,57 +31,36 @@ #include #include #include +#include #include -#include "game_session.hpp" +#include "file_system.hpp" +#include "gameconfig.hpp" +#include "gettext.hpp" +#include "level.hpp" +#include "levelintro.hpp" #include "log.hpp" -#include "console.hpp" -#include "worldmap/worldmap.hpp" +#include "main.hpp" #include "mainloop.hpp" -#include "audio/sound_manager.hpp" -#include "gui/menu.hpp" -#include "sector.hpp" -#include "level.hpp" -#include "tile.hpp" #include "player_status.hpp" -#include "object/particlesystem.hpp" -#include "object/background.hpp" -#include "object/gradient.hpp" -#include "object/tilemap.hpp" -#include "object/camera.hpp" -#include "object/player.hpp" -#include "object/level_time.hpp" -#include "lisp/lisp.hpp" -#include "lisp/parser.hpp" -#include "resources.hpp" +#include "options_menu.hpp" +#include "random_generator.hpp" +#include "sector.hpp" #include "statistics.hpp" #include "timer.hpp" -#include "options_menu.hpp" -#include "textscroller.hpp" +#include "audio/sound_manager.hpp" #include "control/codecontroller.hpp" #include "control/joystickkeyboardcontroller.hpp" -#include "main.hpp" -#include "file_system.hpp" -#include "gameconfig.hpp" -#include "gettext.hpp" -#include "console.hpp" -#include "flip_level_transformer.hpp" -#include "trigger/secretarea_trigger.hpp" -#include "trigger/sequence_trigger.hpp" -#include "random_generator.hpp" -#include "scripting/squirrel_util.hpp" -#include "object/endsequence_walkright.hpp" -#include "object/endsequence_walkleft.hpp" +#include "gui/menu.hpp" +#include "object/camera.hpp" #include "object/endsequence_fireworks.hpp" -#include "direction.hpp" -#include "scripting/time_scheduler.hpp" -#include "levelintro.hpp" - -// the engine will be run with a logical framerate of 64fps. -// We chose 64fps here because it is a power of 2, so 1/64 gives an "even" -// binary fraction... -static const float LOGICAL_FPS = 64.0; +#include "object/endsequence_walkleft.hpp" +#include "object/endsequence_walkright.hpp" +#include "object/level_time.hpp" +#include "object/player.hpp" +#include "scripting/squirrel_util.hpp" +#include "worldmap/worldmap.hpp" enum GameMenuIDs { MNID_CONTINUE, @@ -106,7 +87,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) restart_level(); game_menu.reset(new Menu()); - game_menu->add_label(_("Pause")); + game_menu->add_label(level->name); game_menu->add_hl(); game_menu->add_entry(MNID_CONTINUE, _("Continue")); game_menu->add_submenu(_("Options"), get_options_menu()); @@ -131,31 +112,34 @@ GameSession::restart_level() currentsector = 0; level.reset(new Level); - level->load(levelfile); - level->stats.total_coins = level->get_total_coins(); - level->stats.total_badguys = level->get_total_badguys(); - level->stats.total_secrets = level->get_total_count(); - level->stats.reset(); - - if(reset_sector != "") { - currentsector = level->get_sector(reset_sector); - if(!currentsector) { - std::stringstream msg; - msg << "Couldn't find sector '" << reset_sector << "' for resetting tux."; - throw std::runtime_error(msg.str()); + try { + level->load(levelfile); + level->stats.total_coins = level->get_total_coins(); + level->stats.total_badguys = level->get_total_badguys(); + level->stats.total_secrets = level->get_total_secrets(); + level->stats.reset(); + + if(reset_sector != "") { + currentsector = level->get_sector(reset_sector); + if(!currentsector) { + std::stringstream msg; + msg << "Couldn't find sector '" << reset_sector << "' for resetting tux."; + throw std::runtime_error(msg.str()); + } + level->stats.declare_invalid(); + currentsector->activate(reset_pos); + } else { + currentsector = level->get_sector("main"); + if(!currentsector) + throw std::runtime_error("Couldn't find main sector"); + play_time = 0; + currentsector->activate("main"); } - level->stats.declare_invalid(); - currentsector->activate(reset_pos); - } else { - currentsector = level->get_sector("main"); - if(!currentsector) - throw std::runtime_error("Couldn't find main sector"); - play_time = 0; - currentsector->activate("main"); + } catch(std::exception& e) { + log_fatal << "Couldn't start level: " << e.what() << std::endl; + main_loop->exit_screen(); } - //levelintro(); - sound_manager->stop_music(); currentsector->play_music(LEVEL_MUSIC); @@ -244,45 +228,6 @@ GameSession::play_demo(const std::string& filename) } void -GameSession::levelintro() -{ - sound_manager->stop_music(); - - DrawingContext context; - for(Sector::GameObjects::iterator i = currentsector->gameobjects.begin(); - i != currentsector->gameobjects.end(); ++i) { - Background* background = dynamic_cast (*i); - if(background) { - background->draw(context); - } - Gradient* gradient = dynamic_cast (*i); - if(gradient) { - gradient->draw(context); - } - } - -// context.draw_text(gold_text, level->get_name(), Vector(SCREEN_WIDTH/2, 160), -// ALIGN_CENTER, LAYER_FOREGROUND1); - context.draw_center_text(gold_text, level->get_name(), Vector(0, 160), - LAYER_FOREGROUND1); - - std::stringstream ss_coins; - ss_coins << _("Coins") << ": " << player_status->coins; - context.draw_text(white_text, ss_coins.str(), Vector(SCREEN_WIDTH/2, 210), - ALIGN_CENTER, LAYER_FOREGROUND1); - - if((level->get_author().size()) && (level->get_author() != "SuperTux Team")) - context.draw_text(white_small_text, - std::string(_("contributed by ")) + level->get_author(), - Vector(SCREEN_WIDTH/2, 350), ALIGN_CENTER, LAYER_FOREGROUND1); - - if(best_level_statistics != NULL) - best_level_statistics->draw_message_info(context, _("Best Level Statistics")); - - wait_for_event(1.0, 3.0); -} - -void GameSession::on_escape_press() { if(currentsector->player->is_dying() || end_sequence) @@ -457,8 +402,6 @@ GameSession::process_menu() { Menu* menu = Menu::current(); if(menu) { - menu->update(); - if(menu == game_menu.get()) { switch (game_menu->check()) { case MNID_CONTINUE: @@ -477,7 +420,6 @@ GameSession::process_menu() void GameSession::setup() { - Menu::set_current(NULL); current_ = this; if(currentsector != Sector::current()) { @@ -519,10 +461,14 @@ GameSession::update(float elapsed_time) Sector* sector = level->get_sector(newsector); if(sector == 0) { log_warning << "Sector '" << newsector << "' not found" << std::endl; + sector = level->get_sector("main"); } sector->activate(newspawnpoint); sector->play_music(LEVEL_MUSIC); currentsector = sector; + //Keep persistent across sectors + if(edit_mode) + currentsector->get_players()[0]->set_edit_mode(edit_mode); newsector = ""; newspawnpoint = ""; } @@ -642,7 +588,7 @@ GameSession::start_sequence(const std::string& sequencename) currentsector->add_object(end_sequence); end_sequence->start(); - sound_manager->play_music("music/leveldone.ogg", false); + sound_manager->play_music("music/leveldone.music", false); currentsector->player->invincible_timer.start(10000.0f); // Stop all clocks.