src/supertux/levelintro.cpp

Go to the documentation of this file.
00001 //  SuperTux -- LevelIntro screen
00002 //  Copyright (C) 2008 Christoph Sommer <christoph.sommer@2008.expires.deltadevelopment.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "supertux/levelintro.hpp"
00018 
00019 #include "control/joystickkeyboardcontroller.hpp"
00020 #include "math/random_generator.hpp"
00021 #include "sprite/sprite_manager.hpp"
00022 #include "supertux/fadeout.hpp"
00023 #include "supertux/globals.hpp"
00024 #include "supertux/screen_manager.hpp"
00025 #include "supertux/resources.hpp"
00026 #include "util/gettext.hpp"
00027 
00028 #include <sstream>
00029 #include <boost/format.hpp>
00030 
00031 LevelIntro::LevelIntro(const Level* level, const Statistics* best_level_statistics) :
00032   level(level), 
00033   best_level_statistics(best_level_statistics), 
00034   player_sprite(),
00035   player_sprite_py(0), 
00036   player_sprite_vy(0),
00037   player_sprite_jump_timer()
00038 {
00039   player_sprite = sprite_manager->create("images/creatures/tux/tux.sprite");
00040   player_sprite->set_action("small-walk-right");
00041   player_sprite_jump_timer.start(graphicsRandom.randf(5,10));
00042 }
00043 
00044 LevelIntro::~LevelIntro()
00045 {
00046 }
00047 
00048 void
00049 LevelIntro::setup()
00050 {
00051 }
00052 
00053 void
00054 LevelIntro::update(float elapsed_time)
00055 {
00056   Controller *controller = g_jk_controller->get_main_controller();
00057 
00058   // Check if it's time to exit the screen
00059   if(controller->pressed(Controller::JUMP)
00060      || controller->pressed(Controller::ACTION)
00061      || controller->pressed(Controller::MENU_SELECT)
00062      || controller->pressed(Controller::PAUSE_MENU)) {
00063     g_screen_manager->exit_screen(new FadeOut(0.1));
00064   }
00065 
00066   player_sprite_py += player_sprite_vy * elapsed_time;
00067   player_sprite_vy += 1000 * elapsed_time;
00068   if (player_sprite_py >= 0) {
00069     player_sprite_py = 0;
00070     player_sprite_vy = 0;
00071   }
00072   if (player_sprite_jump_timer.check()) {
00073     player_sprite_vy = -300;
00074     player_sprite_jump_timer.start(graphicsRandom.randf(2,3));
00075   }
00076   
00077 }
00078 
00079 void
00080 LevelIntro::draw(DrawingContext& context)
00081 {
00082   const Statistics& stats = level->stats;
00083   int py = static_cast<int>(SCREEN_HEIGHT / 2 - Resources::normal_font->get_height() / 2);
00084 
00085   context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), Color(0.0f, 0.0f, 0.0f, 1.0f), 0);
00086 
00087   {
00088     context.draw_center_text(Resources::normal_font, level->get_name(), Vector(0, py), LAYER_FOREGROUND1, LevelIntro::header_color);
00089     py += static_cast<int>(Resources::normal_font->get_height());
00090   }
00091 
00092   std::string author = level->get_author();
00093   if ((author != "") && (author != "SuperTux Team")) {
00094     std::string author_text = str(boost::format(_("contributed by %s")) % author);
00095     context.draw_center_text(Resources::small_font, author_text, Vector(0, py), LAYER_FOREGROUND1, LevelIntro::author_color);
00096     py += static_cast<int>(Resources::small_font->get_height());
00097   }
00098 
00099   py += 32;
00100 
00101   {
00102     player_sprite->draw(context, Vector((SCREEN_WIDTH - player_sprite->get_current_hitbox_width()) / 2, py + player_sprite_py), LAYER_FOREGROUND1);
00103     py += static_cast<int>(player_sprite->get_current_hitbox_height());
00104   }
00105 
00106   py += 32;
00107 
00108   {
00109     context.draw_center_text(Resources::normal_font, std::string("- ") + _("Best Level Statistics") + std::string(" -"), Vector(0, py), LAYER_FOREGROUND1, LevelIntro::stat_hdr_color);
00110     py += static_cast<int>(Resources::normal_font->get_height());
00111   }
00112 
00113   {
00114     std::stringstream ss;
00115     ss << _("Coins") << ": " << Statistics::coins_to_string((best_level_statistics && (best_level_statistics->coins >= 0)) ? best_level_statistics->coins : 0, stats.total_coins);
00116     context.draw_center_text(Resources::normal_font, ss.str(), Vector(0, py), LAYER_FOREGROUND1, LevelIntro::stat_color);
00117     py += static_cast<int>(Resources::normal_font->get_height());
00118   }
00119   
00120   {
00121     std::stringstream ss;
00122     ss << _("Secrets") << ": " << Statistics::secrets_to_string((best_level_statistics && (best_level_statistics->coins >= 0)) ? best_level_statistics->secrets : 0, stats.total_secrets);
00123     context.draw_center_text(Resources::normal_font, ss.str(), Vector(0, py), LAYER_FOREGROUND1,LevelIntro::stat_color);
00124     py += static_cast<int>(Resources::normal_font->get_height());
00125   }
00126 
00127   {
00128     std::stringstream ss;
00129     ss << _("Time") << ": " << Statistics::time_to_string((best_level_statistics && (best_level_statistics->coins >= 0)) ? best_level_statistics->time : 0);
00130     context.draw_center_text(Resources::normal_font, ss.str(), Vector(0, py), LAYER_FOREGROUND1,LevelIntro::stat_color);
00131     py += static_cast<int>(Resources::normal_font->get_height());
00132   }
00133 
00134 }
00135 
00136 /* EOF */

Generated on Mon Apr 21 03:38:17 2014 for SuperTux by  doxygen 1.5.1