X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fgame_session.cpp;h=69a1265ed5ea73fc7eb3f9e4ee7d0c24b890e1b4;hb=f2d345c3ccec7743e39df2f59e546ad415257b81;hp=fe24f25968598d6324525bda9f66491b5f0fe296;hpb=033c0951d4cb82136300de80b2185085369936fb;p=supertux.git diff --git a/src/game_session.cpp b/src/game_session.cpp index fe24f2596..69a1265ed 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -83,14 +83,14 @@ GameSession* GameSession::current_ = NULL; GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) : level(0), currentsector(0), - end_sequence(NO_ENDSEQUENCE), end_sequence_controller(0), + end_sequence(0), levelfile(levelfile_), best_level_statistics(statistics), capture_demo_stream(0), playback_demo_stream(0), demo_controller(0), play_time(0) { current_ = this; currentsector = NULL; - + game_pause = false; statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png")); @@ -110,7 +110,7 @@ void GameSession::restart_level(bool fromBeginning) { game_pause = false; - end_sequence = NO_ENDSEQUENCE; + end_sequence = 0; main_controller->reset(); @@ -122,7 +122,7 @@ GameSession::restart_level(bool fromBeginning) level->stats.total_badguys = level->get_total_badguys(); level->stats.total_secrets = level->get_total_count(); level->stats.reset(); - if (!fromBeginning) level->stats.declare_invalid(); + if (!fromBeginning && (reset_sector != "")) level->stats.declare_invalid(); if (fromBeginning) reset_sector=""; if(reset_sector != "") { @@ -139,7 +139,7 @@ GameSession::restart_level(bool fromBeginning) throw std::runtime_error("Couldn't find main sector"); currentsector->activate("main"); } - + //levelintro(); currentsector->play_music(LEVEL_MUSIC); @@ -160,8 +160,6 @@ GameSession::~GameSession() delete playback_demo_stream; delete demo_controller; - delete end_sequence_controller; - current_ = NULL; } @@ -169,8 +167,8 @@ void GameSession::record_demo(const std::string& filename) { delete capture_demo_stream; - - capture_demo_stream = new std::ofstream(filename.c_str()); + + capture_demo_stream = new std::ofstream(filename.c_str()); if(!capture_demo_stream->good()) { std::stringstream msg; msg << "Couldn't open demo file '" << filename << "' for writing."; @@ -208,7 +206,7 @@ GameSession::play_demo(const std::string& filename) { delete playback_demo_stream; delete demo_controller; - + playback_demo_stream = new std::ifstream(filename.c_str()); if(!playback_demo_stream->good()) { std::stringstream msg; @@ -259,7 +257,7 @@ GameSession::levelintro() if((level->get_author().size()) && (level->get_author() != "SuperTux Team")) context.draw_text(white_small_text, - std::string(_("contributed by ")) + level->get_author(), + std::string(_("contributed by ")) + level->get_author(), Vector(SCREEN_WIDTH/2, 350), CENTER_ALLIGN, LAYER_FOREGROUND1); if(best_level_statistics != NULL) @@ -271,8 +269,13 @@ GameSession::levelintro() void GameSession::on_escape_press() { - if(currentsector->player->is_dying() || end_sequence != NO_ENDSEQUENCE) + if(currentsector->player->is_dying() || end_sequence) + { + // Let the timers run out, we fast-forward them to force past a sequence + if (end_sequence) end_sequence->stop(); + currentsector->player->dying_timer.start(FLT_EPSILON); return; // don't let the player open the menu, when he is dying + } if(level->on_menukey_script != "") { std::istringstream in(level->on_menukey_script); @@ -281,7 +284,7 @@ GameSession::on_escape_press() toggle_pause(); } } - + void GameSession::toggle_pause() { @@ -328,26 +331,11 @@ GameSession::run_script(std::istream& in, const std::string& sourcename) void GameSession::process_events() { - Player& tux = *currentsector->player; - // end of pause mode? if(!Menu::current() && game_pause) { game_pause = false; } - if (end_sequence != NO_ENDSEQUENCE) { - if(end_sequence_controller == 0) { - end_sequence_controller = new CodeController(); - tux.set_controller(end_sequence_controller); - } - - end_sequence_controller->press(Controller::RIGHT); - - if (int(last_x_pos) == int(tux.get_pos().x)) - end_sequence_controller->press(Controller::JUMP); - last_x_pos = tux.get_pos().x; - } - // playback a demo? if(playback_demo_stream != 0) { demo_controller->update(); @@ -377,7 +365,7 @@ GameSession::process_events() capture_demo_stream ->put(main_controller->hold(Controller::RIGHT)); capture_demo_stream ->put(main_controller->hold(Controller::UP)); capture_demo_stream ->put(main_controller->hold(Controller::DOWN)); - capture_demo_stream ->put(main_controller->hold(Controller::JUMP)); + capture_demo_stream ->put(main_controller->hold(Controller::JUMP)); capture_demo_stream ->put(main_controller->hold(Controller::ACTION)); } } @@ -388,24 +376,24 @@ GameSession::check_end_conditions() Player* tux = currentsector->player; /* End of level? */ - if(end_sequence && endsequence_timer.check()) { + if(end_sequence && end_sequence->is_done()) { finish(true); return; } else if (!end_sequence && tux->is_dead()) { - if (player_status->coins < 0) { + if (player_status->coins < 0) { // No more coins: restart level from beginning player_status->coins = 0; restart_level(true); - } else { + } else { // Still has coins: restart level from last reset point restart_level(false); } - + return; } } -void +void GameSession::draw(DrawingContext& context) { currentsector->draw(context); @@ -422,7 +410,7 @@ GameSession::draw_pause(DrawingContext& context) Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), Color(.2, .2, .2, .5), LAYER_FOREGROUND1); } - + void GameSession::process_menu() { @@ -462,7 +450,7 @@ GameSession::update(float elapsed_time) // handle controller if(main_controller->pressed(Controller::PAUSE_MENU)) on_escape_press(); - + process_events(); process_menu(); @@ -484,13 +472,17 @@ GameSession::update(float elapsed_time) // Update the world state and all objects in the world if(!game_pause) { // Update the world - if (end_sequence == ENDSEQUENCE_RUNNING) { - currentsector->update(elapsed_time/2); - } else if(end_sequence == NO_ENDSEQUENCE) { + if (!end_sequence) { play_time += elapsed_time; //TODO: make sure we don't count cutscene time level->stats.time = play_time; currentsector->update(elapsed_time); - } + } else { + if (!end_sequence->is_tux_stopped()) { + currentsector->update(elapsed_time/2); + } else { + end_sequence->update(elapsed_time/2); + } + } } // update sounds @@ -499,7 +491,7 @@ GameSession::update(float elapsed_time) /* Handle music: */ if (end_sequence) return; - + if(currentsector->player->invincible_timer.started()) { if(currentsector->player->invincible_timer.get_timeleft() <= TUX_INVINCIBLE_TIME_WARNING) { @@ -521,7 +513,7 @@ GameSession::finish(bool win) if(WorldMap::current()) WorldMap::current()->finished_level(level.get()); } - + main_loop->exit_screen(); } @@ -552,7 +544,7 @@ GameSession::display_info_box(const std::string& text) bool running = true; DrawingContext context; - + while(running) { // TODO make a screen out of this, another mainloop is ugly @@ -589,9 +581,10 @@ GameSession::start_sequence(const std::string& sequencename) if(end_sequence) return; - end_sequence = ENDSEQUENCE_RUNNING; - endsequence_timer.start(7.3); - last_x_pos = -1; + end_sequence = new EndSequence(); + currentsector->add_object(end_sequence); + end_sequence->start(); + sound_manager->play_music("music/leveldone.ogg", false); currentsector->player->invincible_timer.start(7.3); @@ -614,7 +607,7 @@ GameSession::start_sequence(const std::string& sequencename) log_warning << "Final target reached without an active end sequence" << std::endl; this->start_sequence("endsequence"); } - end_sequence = ENDSEQUENCE_WAITING; + if (end_sequence) end_sequence->stop_tux(); } else { log_warning << "Unknown sequence '" << sequencename << "'" << std::endl; } @@ -631,4 +624,3 @@ GameSession::drawstatus(DrawingContext& context) level->stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get()); } } -