- }
-
-
- if (level->pos == tux->get_tile_pos())
- {
- PlayerStatus old_player_status = player_status;
-
- std::cout << "Enter the current level: " << level->name << std::endl;
- // do a shriking fade to the level
- shrink_fade(Vector((level->pos.x*32 + 16 + offset.x),
- (level->pos.y*32 + 16 + offset.y)), 500);
- GameSession session(get_resource_filename(levels_path + level->name),
- ST_GL_LOAD_LEVEL_FILE, &level->statistics);
-
- switch (session.run())
- {
- case GameSession::ES_LEVEL_FINISHED:
- {
- level_finished = true;
- bool old_level_state = level->solved;
- level->solved = true;
-
- // deal with statistics
- level->statistics.merge(global_stats);
- calculate_total_stats();
-
- if (old_level_state != level->solved && level->auto_path)
- { // Try to detect the next direction to which we should walk
- // FIXME: Mostly a hack
- Direction dir = D_NONE;
-
- const Tile* tile = at(tux->get_tile_pos());
-
- if (tile->getData() & Tile::WORLDMAP_NORTH
- && tux->back_direction != D_NORTH)
- dir = D_NORTH;
- else if (tile->getData() & Tile::WORLDMAP_SOUTH
- && tux->back_direction != D_SOUTH)
- dir = D_SOUTH;
- else if (tile->getData() & Tile::WORLDMAP_EAST
- && tux->back_direction != D_EAST)
- dir = D_EAST;
- else if (tile->getData() & Tile::WORLDMAP_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;
- }
- }
-
- break;
- case GameSession::ES_LEVEL_ABORT:
- level_finished = false;
- /* In case the player's abort the level, keep it using the old
- status. But the minimum lives and no bonus. */
- player_status.distros = old_player_status.distros;
- player_status.lives = std::min(old_player_status.lives, player_status.lives);
- player_status.bonus = NO_BONUS;
-
- break;
- case GameSession::ES_GAME_OVER:
- {
- level_finished = false;
- /* draw an end screen */
- /* TODO: in the future, this should make a dialog a la SuperMario, asking
- if the player wants to restart the world map with no score and from
- level 1 */
- char str[80];
-
- DrawingContext context;
- context.draw_gradient(Color (200,240,220), Color(200,200,220),
- LAYER_BACKGROUND0);
-
- context.draw_text(blue_text, _("GAMEOVER"),
- Vector(screen->w/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1);
-
- sprintf(str, _("COINS: %d"), player_status.distros);
- context.draw_text(gold_text, str,
- Vector(screen->w/2, screen->w - 32), CENTER_ALLIGN,
- LAYER_FOREGROUND1);
-
- total_stats.draw_message_info(context, _("Total Statistics"));
-
- context.do_drawing();
-
- SDL_Event event;
- wait_for_event(event,2000,6000,true);
-
- quit = true;
- player_status.reset();
- break;
- }
- case GameSession::ES_NONE:
- assert(false);
- // Should never be reached
- break;
- }
-
- SoundManager::get()->play_music(song);
- Menu::set_current(0);
- if (!savegame_file.empty())
- savegame(savegame_file);
- }
- /* The porpose of the next checking is that if the player lost
- the level (in case there is one), don't show anything */
- if(level_finished) {
- if (!level->extro_filename.empty()) {
- // Display a text file
- std::string filename = levels_path + level->extro_filename;
- display_text_file(filename);
- }