TitleScreen Class Reference

Screen that displays the SuperTux logo, lets players start a new game, etc. More...

#include <title_screen.hpp>

Inherits Screen.

List of all members.

Public Member Functions

 TitleScreen (PlayerStatus *player_status)
virtual ~TitleScreen ()
virtual void setup ()
 gets called before this screen gets activated (which is at least once before the first draw or update call
virtual void leave ()
 gets called when the current screen is temporarily suspended
virtual void draw (DrawingContext &context)
 gets called once per frame.
virtual void update (float elapsed_time)
 gets called for once (per logical) frame.

Static Public Member Functions

static std::string get_level_name (const std::string &levelfile)
static void start_game (World *world)

Private Member Functions

void make_tux_jump ()
void generate_main_menu ()
 TitleScreen (const TitleScreen &)
TitleScreenoperator= (const TitleScreen &)

Private Attributes

std::auto_ptr< MainMenumain_menu
SurfacePtr frame
std::auto_ptr< CodeControllercontroller
std::auto_ptr< GameSessiontitlesession


Detailed Description

Screen that displays the SuperTux logo, lets players start a new game, etc.

Definition at line 35 of file title_screen.hpp.


Constructor & Destructor Documentation

TitleScreen::TitleScreen ( PlayerStatus player_status  ) 

Definition at line 45 of file title_screen.cpp.

References controller, Surface::create(), frame, player_status, Player::set_controller(), Player::set_speedlimit(), and titlesession.

00045                                                     :
00046   main_menu(new MainMenu()),
00047   frame(),
00048   controller(),
00049   titlesession()
00050 {
00051   controller.reset(new CodeController());
00052   titlesession.reset(new GameSession("levels/misc/menu.stl", player_status));
00053 
00054   Player* player = titlesession->get_current_sector()->player;
00055   player->set_controller(controller.get());
00056   player->set_speedlimit(230); //MAX_WALK_XM
00057 
00058   frame = Surface::create("images/engine/menu/frame.png");
00059 }

TitleScreen::~TitleScreen (  )  [virtual]

Definition at line 110 of file title_screen.cpp.

00111 {
00112 }

TitleScreen::TitleScreen ( const TitleScreen  )  [private]


Member Function Documentation

std::string TitleScreen::get_level_name ( const std::string &  levelfile  )  [static]

Definition at line 62 of file title_screen.cpp.

References lisp::Lisp::get(), lisp::Lisp::get_lisp(), log_warning, and lisp::Parser::parse().

Referenced by ContribWorldMenu::ContribWorldMenu().

00063 {
00064   try {
00065     lisp::Parser parser;
00066     const lisp::Lisp* root = parser.parse(filename);
00067 
00068     const lisp::Lisp* level = root->get_lisp("supertux-level");
00069     if(!level)
00070       return "";
00071 
00072     std::string name;
00073     level->get("name", name);
00074     return name;
00075   } catch(std::exception& e) {
00076     log_warning << "Problem getting name of '" << filename << "': "
00077                 << e.what() << std::endl;
00078     return "";
00079   }
00080 }

void TitleScreen::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 115 of file title_screen.cpp.

References Sector::activate(), Sector::current(), MovingObject::get_pos(), LEVEL_MUSIC, main_menu, Sector::play_music(), Sector::player, MenuManager::set_current(), and titlesession.

00116 {
00117   Sector* sector = titlesession->get_current_sector();
00118   if(Sector::current() != sector) {
00119     sector->play_music(LEVEL_MUSIC);
00120     sector->activate(sector->player->get_pos());
00121   }
00122 
00123   MenuManager::set_current(main_menu.get());
00124 }

void TitleScreen::leave (  )  [virtual]

gets called when the current screen is temporarily suspended

Reimplemented from Screen.

Definition at line 127 of file title_screen.cpp.

References Sector::deactivate(), MenuManager::set_current(), and titlesession.

00128 {
00129   Sector* sector = titlesession->get_current_sector();
00130   sector->deactivate();
00131   MenuManager::set_current(NULL);
00132 }

void TitleScreen::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 135 of file title_screen.cpp.

References _(), ALIGN_LEFT, Sector::draw(), DrawingContext::draw_text(), LAYER_FOREGROUND1, SCREEN_HEIGHT, Resources::small_font, and titlesession.

00136 {
00137   Sector* sector  = titlesession->get_current_sector();
00138   sector->draw(context);
00139 
00140   // FIXME: Add something to scale the frame to the resolution of the screen
00141   //context.draw_surface(frame, Vector(0,0),LAYER_FOREGROUND1);
00142 
00143   context.draw_text(Resources::small_font, "SuperTux " PACKAGE_VERSION "\n",
00144                     Vector(5, SCREEN_HEIGHT - 50), ALIGN_LEFT, LAYER_FOREGROUND1);
00145   context.draw_text(Resources::small_font,
00146                     _(
00147                       "Copyright (c) 2003-2010 SuperTux Devel Team\n"
00148                       "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to\n"
00149                       "redistribute it under certain conditions; see the file COPYING for details.\n"
00150                       ),
00151                     Vector(5, SCREEN_HEIGHT - 50 + Resources::small_font->get_height() + 5),
00152                     ALIGN_LEFT, LAYER_FOREGROUND1);
00153 }

void TitleScreen::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 156 of file title_screen.cpp.

References MenuManager::current(), g_screen_manager, ScreenManager::has_no_pending_fadeout(), main_menu, make_tux_jump(), MenuManager::set_current(), ScreenManager::set_speed(), titlesession, and Sector::update().

00157 {
00158   g_screen_manager->set_speed(0.6f);
00159   Sector* sector  = titlesession->get_current_sector();
00160   sector->update(elapsed_time);
00161 
00162   make_tux_jump();
00163 
00164   if (Menu* menu = MenuManager::current())
00165   {
00166     menu->check_menu();
00167   }
00168 
00169   // reopen menu if user closed it (so that the app doesn't close when user
00170   // accidently hit ESC)
00171   if(MenuManager::current() == 0 && g_screen_manager->has_no_pending_fadeout()) 
00172   {
00173     MenuManager::set_current(main_menu.get());
00174   }
00175 }

void TitleScreen::start_game ( World world  )  [static]

Definition at line 178 of file title_screen.cpp.

References FileSystem::basename(), g_config, World::get_basedir(), log_fatal, Config::profile, World::run(), MenuManager::set_current(), and World::set_savegame_filename().

Referenced by MainMenu::check_menu(), and ContribMenu::check_menu().

00179 {
00180   MenuManager::set_current(NULL);
00181 
00182   std::string basename = world->get_basedir();
00183   basename = basename.substr(0, basename.length()-1);
00184   std::string worlddirname = FileSystem::basename(basename);
00185   std::ostringstream stream;
00186   stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg";
00187   std::string slotfile = stream.str();
00188 
00189   try 
00190   {
00191     world->set_savegame_filename(slotfile);
00192     world->run();
00193   } 
00194   catch(std::exception& e) 
00195   {
00196     log_fatal << "Couldn't start world: " << e.what() << std::endl;
00197   }
00198 }

void TitleScreen::make_tux_jump (  )  [private]

Definition at line 83 of file title_screen.cpp.

References Sector::activate(), Sector::camera, controller, MovingObject::get_bbox(), MovingObject::get_pos(), Sector::get_width(), Sector::is_free_of_statics(), Controller::JUMP, Player::on_ground(), Rectf::p2, Sector::player, Camera::reset(), Controller::RIGHT, titlesession, and Vector::x.

Referenced by update().

00084 {
00085   static bool jumpWasReleased = true;
00086   Sector* sector  = titlesession->get_current_sector();
00087   Player* tux = sector->player;
00088 
00089   controller->update();
00090   controller->press(Controller::RIGHT);
00091 
00092   // Check if we should press the jump button
00093   Rectf lookahead = tux->get_bbox();
00094   lookahead.p2.x += 96;
00095   bool pathBlocked = !sector->is_free_of_statics(lookahead);
00096   if ((pathBlocked && jumpWasReleased) || !tux->on_ground()) {
00097     controller->press(Controller::JUMP);
00098     jumpWasReleased = false;
00099   } else {
00100     jumpWasReleased = true;
00101   }
00102 
00103   // Wrap around at the end of the level back to the beginning
00104   if(sector->get_width() - 320 < tux->get_pos().x) {
00105     sector->activate("main");
00106     sector->camera->reset(tux->get_pos());
00107   }
00108 }

void TitleScreen::generate_main_menu (  )  [private]

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


Member Data Documentation

std::auto_ptr<MainMenu> TitleScreen::main_menu [private]

Definition at line 59 of file title_screen.hpp.

Referenced by setup(), and update().

SurfacePtr TitleScreen::frame [private]

Definition at line 60 of file title_screen.hpp.

Referenced by TitleScreen().

std::auto_ptr<CodeController> TitleScreen::controller [private]

Definition at line 61 of file title_screen.hpp.

Referenced by make_tux_jump(), and TitleScreen().

std::auto_ptr<GameSession> TitleScreen::titlesession [private]

Definition at line 62 of file title_screen.hpp.

Referenced by draw(), leave(), make_tux_jump(), setup(), TitleScreen(), and update().


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