- if(!level->name.empty())
- {
- if (level->x == tux->get_tile_pos().x &&
- level->y == tux->get_tile_pos().y)
- {
- 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->x*32 + 16 + offset.x),(level->y*32 + 16
- + offset.y)), 500);
- GameSession session(datadir + "/levels/" + level->name,
- ST_GL_LOAD_LEVEL_FILE, level->vertical_flip);
-
- switch (session.run())
- {
- case GameSession::ES_LEVEL_FINISHED:
- {
- level_finished = true;
- bool old_level_state = level->solved;
- level->solved = true;
-
- 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)
- { // 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.score = old_player_status.score;
- 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 */
- /* 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_center(blue_text, _("GAMEOVER"),
- Vector(0, 200), LAYER_FOREGROUND1);
-
- sprintf(str, _("SCORE: %d"), player_status.score);
- context.draw_text_center(gold_text, str,
- Vector(0, 230), LAYER_FOREGROUND1);
-
- sprintf(str, _("COINS: %d"), player_status.distros);
- context.draw_text_center(gold_text, str,
- Vector(0, screen->w - 32), LAYER_FOREGROUND1);
-
- context.do_drawing();