X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgameloop.cpp;h=3b593f955e95d12961ecde83c8e8385aea9850e7;hb=db7e44a2f93bd7c0e7477690e7cc30b6d5273b06;hp=3a33cdbbcf217609c33705eff02a55cd4533720b;hpb=9599042661b468aae7bd34dca05441c0ebc93ad7;p=supertux.git diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 3a33cdbbc..3b593f955 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -91,9 +91,6 @@ GameSession::GameSession(const std::string& levelfile_, int mode, context = new DrawingContext(); - last_swap_point = Vector(-1, -1); - last_swap_stats.reset(); - restart_level(); } @@ -126,40 +123,23 @@ GameSession::restart_level() global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys()); global_stats.set_total_points(TIME_NEEDED_STAT, level->timelimit); - currentsector = level->get_sector("main"); - if(!currentsector) - Termination::abort("Level has no main sector.", ""); - currentsector->activate("main"); - -#if 0 - // Set Tux to the nearest reset point - if(tux_pos.x != -1) - { - tux_pos = currentsector->get_best_spawn_point(tux_pos); - - if(last_swap_point.x > tux_pos.x) - tux_pos = last_swap_point; - else // new swap point - { - last_swap_point = tux_pos; - - last_swap_stats += global_stats; - } - - currentsector->player->base.x = tux_pos.x; - currentsector->player->base.y = tux_pos.y; - - // has to reset camera on swapping - currentsector->camera->reset(Vector(currentsector->player->base.x, - currentsector->player->base.y)); - } -#endif - - if (st_gl_mode != ST_GL_DEMO_GAME) - { - if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE) - levelintro(); + 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()); } + currentsector->activate(reset_pos); + } else { + currentsector = level->get_sector("main"); + if(!currentsector) + throw std::runtime_error("Couldn't find main sector"); + currentsector->activate("main"); + } + + if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE) + levelintro(); start_timers(); currentsector->play_music(LEVEL_MUSIC); @@ -172,7 +152,7 @@ GameSession::~GameSession() } void -GameSession::levelintro(void) +GameSession::levelintro() { SoundManager::get()->halt_music(); @@ -383,13 +363,13 @@ GameSession::process_events() } } - /* Check if chacrater is ASCII */ - char ch[2]; - if((event.key.keysym.unicode & 0xFF80) == 0) - { - ch[0] = event.key.keysym.unicode & 0x7F; - ch[1] = '\0'; - } + /* Check if chacrater is ASCII */ + char ch[2]; + if((event.key.keysym.unicode & 0xFF80) == 0) + { + ch[0] = event.key.keysym.unicode & 0x7F; + ch[1] = '\0'; + } last_keys.append(ch); // add to cheat keys handle_cheats(); break; @@ -572,9 +552,8 @@ GameSession::check_end_conditions() /* End of level? */ if(end_sequence && endsequence_timer.check()) { - exit_status = ES_LEVEL_FINISHED; - global_stats += last_swap_stats; // add swap points stats - return; + exit_status = ES_LEVEL_FINISHED; + return; } else if (!end_sequence && tux->is_dead()) { player_status.bonus = PlayerStatus::NO_BONUS; @@ -795,6 +774,13 @@ GameSession::respawn(const std::string& sector, const std::string& spawnpoint) } void +GameSession::set_reset_point(const std::string& sector, const Vector& pos) +{ + reset_sector = sector; + reset_pos = pos; +} + +void GameSession::start_sequence(const std::string& sequencename) { if(sequencename == "endsequence" || sequencename == "fireworks") { @@ -814,6 +800,8 @@ GameSession::start_sequence(const std::string& sequencename) if(sequencename == "fireworks") { currentsector->add_object(new Fireworks()); } + } else if(sequencename == "stoptux") { + end_sequence = ENDSEQUENCE_WAITING; } else { std::cout << "Unknown sequence '" << sequencename << "'.\n"; }