+
+ switch (session.run())
+ {
+ case GameSession::ES_LEVEL_FINISHED:
+ {
+ bool old_level_state = level->solved;
+ level->solved = true;
+
+ if (session.get_world()->get_tux()->got_power !=
+ session.get_world()->get_tux()->NONE_POWER)
+ player_status.bonus = PlayerStatus::FLOWER_BONUS;
+ else if (session.get_world()->get_tux()->size == BIG)
+ player_status.bonus = PlayerStatus::GROWUP_BONUS;
+ else
+ player_status.bonus = PlayerStatus::NO_BONUS;
+
+ if (old_level_state != level->solved)
+ { // Try to detect the next direction to which we should walk
+ // FIXME: Mostly a hack
+ Direction dir = D_NONE;
+
+ Tile* tile = at(tux->get_tile_pos());
+
+ if (tile->north && tux->back_direction != D_NORTH)
+ dir = D_NORTH;
+ else if (tile->south && tux->back_direction != D_SOUTH)
+ dir = D_SOUTH;
+ else if (tile->east && tux->back_direction != D_EAST)
+ dir = D_EAST;
+ else if (tile->west && tux->back_direction != D_WEST)
+ dir = D_WEST;
+
+ if (dir != D_NONE)
+ {
+ tux->set_direction(dir);
+ //tux->update(delta);
+ }
+
+ std::cout << "Walk to dir: " << dir << std::endl;
+ }
+
+ if (!level->extro_filename.empty())
+ {
+ MusicRef theme =
+ music_manager->load_music(datadir + "/music/theme.mod");
+ music_manager->play_music(theme);
+ // Display final credits and go back to the main menu
+ display_text_file(level->extro_filename,
+ "/images/background/extro.jpg", SCROLL_SPEED_MESSAGE);
+ display_text_file("CREDITS",
+ "/images/background/oiltux.jpg", SCROLL_SPEED_CREDITS);
+ quit = true;
+ }
+ }
+
+ break;
+ case GameSession::ES_LEVEL_ABORT:
+ // Reseting the player_status might be a worthy
+ // consideration, but I don't think we need it
+ // 'cause only the bad players will use it to
+ // 'cheat' a few items and that isn't necesarry a
+ // bad thing (ie. better they continue that way,
+ // then stop playing the game all together since it
+ // is to hard)
+ break;
+ case GameSession::ES_GAME_OVER:
+ quit = true;
+ player_status.reset();
+ break;
+ case GameSession::ES_NONE:
+ // Should never be reached
+ break;
+ }
+
+ music_manager->play_music(song);
+ Menu::set_current(0);
+ if (!savegame_file.empty())
+ savegame(savegame_file);