+// $Id: textscroller.cpp 4981 2007-04-15 15:41:27Z sommer $
+//
+// SuperTux -- LevelIntro screen
+// Copyright (C) 2008 Christoph Sommer <christoph.sommer@2008.expires.deltadevelopment.de>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+#include <config.h>
+
+#include "levelintro.hpp"
+
+#include <stdexcept>
+#include "log.hpp"
+#include "mainloop.hpp"
+#include "gettext.hpp"
+#include "resources.hpp"
+#include "video/font.hpp"
+#include "video/drawing_context.hpp"
+#include "gui/menu.hpp"
+#include "main.hpp"
+#include "fadeout.hpp"
+#include "control/joystickkeyboardcontroller.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "random_generator.hpp"
+
+
+static const float DEFAULT_SPEED = 20;
+static const float LEFT_BORDER = 50;
+static const float SCROLL = 60;
+static const float ITEMS_SPACE = 4;
+
+LevelIntro::LevelIntro(const Level* level, const Statistics* best_level_statistics)
+ : level(level), best_level_statistics(best_level_statistics), player_sprite_py(0), player_sprite_vy(0)
+{
+ player_sprite.reset(sprite_manager->create("images/creatures/tux/tux.sprite"));
+ player_sprite->set_action("small-walk-right");
+ player_sprite_jump_timer.start(systemRandom.randf(5,10));
+}
+
+LevelIntro::~LevelIntro()
+{
+}
+
+void
+LevelIntro::setup()
+{
+ Menu::set_current(NULL);
+}
+
+void
+LevelIntro::update(float elapsed_time)
+{
+
+ // Check if it's time to exit the screen
+ if(main_controller->pressed(Controller::JUMP)
+ || main_controller->pressed(Controller::ACTION)
+ || main_controller->pressed(Controller::MENU_SELECT)
+ || main_controller->pressed(Controller::PAUSE_MENU)) {
+ main_loop->exit_screen(new FadeOut(0.1));
+ }
+
+ player_sprite_py += player_sprite_vy * elapsed_time;
+ player_sprite_vy += 1000 * elapsed_time;
+ if (player_sprite_py >= 0) {
+ player_sprite_py = 0;
+ player_sprite_vy = 0;
+ }
+ if (player_sprite_jump_timer.check()) {
+ player_sprite_vy = -300;
+ player_sprite_jump_timer.start(systemRandom.randf(2,3));
+ }
+
+}
+
+void
+LevelIntro::draw(DrawingContext& context)
+{
+ const Statistics& stats = level->stats;
+ int py = SCREEN_HEIGHT / 2 - gold_text->get_height() / 2;
+
+ context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), Color(0.0f, 0.0f, 0.0f, 1.0f), 0);
+
+ {
+ context.draw_center_text(gold_text, level->get_name(), Vector(0, py), LAYER_FOREGROUND1);
+ py += gold_text->get_height();
+ }
+
+ std::string author = level->get_author();
+ if ((author != "") && (author != "SuperTux Team")) {
+ std::string author_text = std::string(_("contributed by ")) + author;
+ context.draw_center_text(white_small_text, author_text, Vector(0, py), LAYER_FOREGROUND1);
+ py += white_small_text->get_height();
+ }
+
+ py += 32;
+
+ {
+ player_sprite->draw(context, Vector((SCREEN_WIDTH - player_sprite->get_current_hitbox_width()) / 2, py + player_sprite_py), LAYER_FOREGROUND1);
+ py += player_sprite->get_current_hitbox_height();
+ }
+
+ py += 32;
+
+ {
+ context.draw_center_text(blue_text, std::string("- ") + _("Best Level Statistics") + std::string(" -"), Vector(0, py), LAYER_FOREGROUND1);
+ py += blue_text->get_height();
+ }
+
+ {
+ std::stringstream ss;
+ ss << _("Coins") << ": " << Statistics::coins_to_string((best_level_statistics && (best_level_statistics->coins >= 0)) ? best_level_statistics->coins : 0, stats.total_coins);
+ context.draw_center_text(white_text, ss.str(), Vector(0, py), LAYER_FOREGROUND1);
+ py += white_text->get_height();
+ }
+
+ {
+ std::stringstream ss;
+ ss << _("Secrets") << ": " << Statistics::secrets_to_string((best_level_statistics && (best_level_statistics->coins >= 0)) ? best_level_statistics->secrets : 0, stats.total_secrets);
+ context.draw_center_text(white_text, ss.str(), Vector(0, py), LAYER_FOREGROUND1);
+ py += white_text->get_height();
+ }
+
+ {
+ std::stringstream ss;
+ ss << _("Time") << ": " << Statistics::time_to_string((best_level_statistics && (best_level_statistics->coins >= 0)) ? best_level_statistics->time : 0);
+ context.draw_center_text(white_text, ss.str(), Vector(0, py), LAYER_FOREGROUND1);
+ py += white_text->get_height();
+ }
+
+ py += 32;
+
+
+}