X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgame_session.cpp;h=a5f00763e08c63319a90b90556b018645e7c28d2;hb=fb8cef6efacc0dff5faaff6dc4aa638289285099;hp=e918a09750480a582ae028648096efe7e32f6b1c;hpb=d0d05bbf22ee54ca293254a02901e395622974b4;p=supertux.git diff --git a/src/game_session.cpp b/src/game_session.cpp index e918a0975..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 @@ -378,9 +317,14 @@ 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) { @@ -444,7 +388,7 @@ GameSession::draw_pause(DrawingContext& context) { context.draw_filled_rect( Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), - Color(.2f, .2f, .2f, .5f), LAYER_FOREGROUND1); + Color(0.0f, 0.0f, 0.0f, .25f), LAYER_FOREGROUND1); } void @@ -476,7 +420,7 @@ GameSession::setup() current_ = this; if(currentsector != Sector::current()) { - currentsector->activate(currentsector->player->get_pos()); + currentsector->activate(currentsector->player->get_pos()); } currentsector->play_music(LEVEL_MUSIC); @@ -484,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 @@ -496,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? @@ -507,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 = ""; } @@ -605,7 +563,7 @@ GameSession::start_sequence(const std::string& sequencename) // abort if a sequence is already playing if (end_sequence) - return; + return; if (sequencename == "endsequence") { if (currentsector->get_players()[0]->physic.get_velocity_x() < 0) { @@ -631,7 +589,7 @@ GameSession::start_sequence(const std::string& sequencename) // Stop all clocks. for(std::vector::iterator i = currentsector->gameobjects.begin(); - i != currentsector->gameobjects.end(); ++i) + i != currentsector->gameobjects.end(); ++i) { GameObject* obj = *i;