LevelIntro Class Reference

Screen that welcomes the player to a level. More...

#include <levelintro.hpp>

Inherits Screen.

List of all members.

Public Member Functions

 LevelIntro (const Level *level, const Statistics *best_level_statistics)
virtual ~LevelIntro ()
void setup ()
 gets called before this screen gets activated (which is at least once before the first draw or update call
void draw (DrawingContext &context)
 gets called once per frame.
void update (float elapsed_time)
 gets called for once (per logical) frame.

Private Member Functions

 LevelIntro (const LevelIntro &)
LevelIntrooperator= (const LevelIntro &)

Private Attributes

const Levellevel
 The level of which this is the intro screen.
const Statisticsbest_level_statistics
 Best level statistics of the level of which is the intro screen.
SpritePtr player_sprite
 Sprite representing the player.
float player_sprite_py
 Position (y axis) for the player sprite.
float player_sprite_vy
 Velocity (y axis) for the player sprite.
Timer player_sprite_jump_timer
 When timer fires, the player sprite will "jump".

Static Private Attributes

static Color header_color
static Color author_color
static Color stat_hdr_color
static Color stat_color


Detailed Description

Screen that welcomes the player to a level.

Definition at line 31 of file levelintro.hpp.


Constructor & Destructor Documentation

LevelIntro::LevelIntro ( const Level level,
const Statistics best_level_statistics 
)

Definition at line 31 of file levelintro.cpp.

References SpriteManager::create(), graphicsRandom, player_sprite, player_sprite_jump_timer, RandomGenerator::randf(), sprite_manager, and Timer::start().

00031                                                                                   :
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 }

LevelIntro::~LevelIntro (  )  [virtual]

Definition at line 44 of file levelintro.cpp.

00045 {
00046 }

LevelIntro::LevelIntro ( const LevelIntro  )  [private]


Member Function Documentation

void LevelIntro::setup (  )  [virtual]

gets called before this screen gets activated (which is at least once before the first draw or update call

Reimplemented from Screen.

Definition at line 49 of file levelintro.cpp.

00050 {
00051 }

void LevelIntro::draw ( DrawingContext context  )  [virtual]

gets called once per frame.

The screen should draw itself in this function. State changes should not be done in this function, but rather in update

Implements Screen.

Definition at line 80 of file levelintro.cpp.

References _(), author_color, best_level_statistics, Statistics::coins, Statistics::coins_to_string(), DrawingContext::draw_center_text(), DrawingContext::draw_filled_rect(), Level::get_author(), Level::get_name(), header_color, LAYER_FOREGROUND1, level, Resources::normal_font, player_sprite, player_sprite_py, SCREEN_HEIGHT, SCREEN_WIDTH, Statistics::secrets, Statistics::secrets_to_string(), Resources::small_font, stat_color, stat_hdr_color, Level::stats, Statistics::time, Statistics::time_to_string(), Statistics::total_coins, and Statistics::total_secrets.

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 }

void LevelIntro::update ( float  elapsed_time  )  [virtual]

gets called for once (per logical) frame.

Screens should do their state updates and logic here

Implements Screen.

Definition at line 54 of file levelintro.cpp.

References Controller::ACTION, Timer::check(), ScreenManager::exit_screen(), g_jk_controller, g_screen_manager, JoystickKeyboardController::get_main_controller(), graphicsRandom, Controller::JUMP, Controller::MENU_SELECT, Controller::PAUSE_MENU, player_sprite_jump_timer, player_sprite_py, player_sprite_vy, Controller::pressed(), RandomGenerator::randf(), and Timer::start().

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 }

LevelIntro& LevelIntro::operator= ( const LevelIntro  )  [private]


Member Data Documentation

Color LevelIntro::header_color [static, private]

Definition at line 34 of file levelintro.hpp.

Referenced by draw().

Color LevelIntro::author_color [static, private]

Definition at line 35 of file levelintro.hpp.

Referenced by draw().

Color LevelIntro::stat_hdr_color [static, private]

Definition at line 36 of file levelintro.hpp.

Referenced by draw().

Color LevelIntro::stat_color [static, private]

Definition at line 37 of file levelintro.hpp.

Referenced by draw().

const Level* LevelIntro::level [private]

The level of which this is the intro screen.

Definition at line 48 of file levelintro.hpp.

Referenced by draw().

const Statistics* LevelIntro::best_level_statistics [private]

Best level statistics of the level of which is the intro screen.

Definition at line 49 of file levelintro.hpp.

Referenced by draw().

SpritePtr LevelIntro::player_sprite [private]

Sprite representing the player.

Definition at line 50 of file levelintro.hpp.

Referenced by draw(), and LevelIntro().

float LevelIntro::player_sprite_py [private]

Position (y axis) for the player sprite.

Definition at line 51 of file levelintro.hpp.

Referenced by draw(), and update().

float LevelIntro::player_sprite_vy [private]

Velocity (y axis) for the player sprite.

Definition at line 52 of file levelintro.hpp.

Referenced by update().

Timer LevelIntro::player_sprite_jump_timer [private]

When timer fires, the player sprite will "jump".

Definition at line 53 of file levelintro.hpp.

Referenced by LevelIntro(), and update().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:32 2014 for SuperTux by  doxygen 1.5.1