+ 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(datadir + "/levels/" + level->name,
+ ST_GL_LOAD_LEVEL_FILE, level->vertical_flip,
+ &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 (session.get_current_sector()->player->got_power !=
+ session.get_current_sector()->player->NONE_POWER)
+ player_status.bonus = PlayerStatus::FLOWER_BONUS;
+ else if (session.get_current_sector()->player->size == BIG)
+ player_status.bonus = PlayerStatus::GROWUP_BONUS;
+ else
+ player_status.bonus = PlayerStatus::NO_BONUS;
+
+ 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;
+
+ 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;
+ }
+ }
+
+ 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 = player_status.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);