X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgame_session.cpp;h=a5f00763e08c63319a90b90556b018645e7c28d2;hb=aee6c4dede5a9c4fa0f7eb134fba61fef738a573;hp=84893569f462cb26b6bafff646855aabdea7494e;hpb=13c4ea0cbf0bdbadc268f49b3cbc797e4f7a746d;p=supertux.git diff --git a/src/game_session.cpp b/src/game_session.cpp index 84893569f..a5f00763e 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 @@ -32,53 +34,32 @@ #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" - -// 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, @@ -92,7 +73,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) end_sequence(0), levelfile(levelfile_), best_level_statistics(statistics), capture_demo_stream(0), playback_demo_stream(0), demo_controller(0), - play_time(0), edit_mode(false) + play_time(0), edit_mode(false), levelintro_shown(false) { current_ = this; currentsector = NULL; @@ -133,7 +114,7 @@ GameSession::restart_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.total_secrets = level->get_total_secrets(); level->stats.reset(); if(reset_sector != "") { @@ -153,8 +134,6 @@ GameSession::restart_level() currentsector->activate("main"); } - //levelintro(); - sound_manager->stop_music(); currentsector->play_music(LEVEL_MUSIC); @@ -243,45 +222,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) @@ -305,17 +245,16 @@ GameSession::on_escape_press() void GameSession::toggle_pause() { + // pause if(!game_pause) { speed_before_pause = main_loop->get_speed(); main_loop->set_speed(0); Menu::set_current(game_menu.get()); game_menu->set_active_item(MNID_CONTINUE); game_pause = true; - } else { - main_loop->set_speed(speed_before_pause); - Menu::set_current(NULL); - game_pause = false; } + + // unpause is done in update() after the menu is processed } void @@ -489,6 +428,11 @@ GameSession::setup() SDL_Event event; while(SDL_PollEvent(&event)) {} + + if (!levelintro_shown) { + levelintro_shown = true; + main_loop->push_screen(new LevelIntro(level.get(), best_level_statistics)); + } } void @@ -501,6 +445,12 @@ GameSession::update(float elapsed_time) process_events(); process_menu(); + // Unpause the game if the menu has been closed + if (game_pause && !Menu::current()) { + main_loop->set_speed(speed_before_pause); + game_pause = false; + } + check_end_conditions(); // respawning in new sector? @@ -512,6 +462,9 @@ GameSession::update(float elapsed_time) 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 = ""; }