00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "supertux/title_screen.hpp"
00019
00020 #include "audio/sound_manager.hpp"
00021 #include "gui/menu_manager.hpp"
00022 #include "lisp/parser.hpp"
00023 #include "object/camera.hpp"
00024 #include "object/player.hpp"
00025 #include "supertux/fadeout.hpp"
00026 #include "supertux/gameconfig.hpp"
00027 #include "supertux/globals.hpp"
00028 #include "supertux/screen_manager.hpp"
00029 #include "supertux/menu/addon_menu.hpp"
00030 #include "supertux/menu/contrib_world_menu.hpp"
00031 #include "supertux/menu/contrib_menu.hpp"
00032 #include "supertux/menu/main_menu.hpp"
00033 #include "supertux/resources.hpp"
00034 #include "supertux/sector.hpp"
00035 #include "supertux/textscroller.hpp"
00036 #include "supertux/world.hpp"
00037 #include "util/file_system.hpp"
00038 #include "util/gettext.hpp"
00039 #include "util/reader.hpp"
00040 #include "video/drawing_context.hpp"
00041
00042 #include <sstream>
00043 #include <version.h>
00044
00045 TitleScreen::TitleScreen(PlayerStatus* player_status) :
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);
00057
00058 frame = Surface::create("images/engine/menu/frame.png");
00059 }
00060
00061 std::string
00062 TitleScreen::get_level_name(const std::string& filename)
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 }
00081
00082 void
00083 TitleScreen::make_tux_jump()
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
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
00104 if(sector->get_width() - 320 < tux->get_pos().x) {
00105 sector->activate("main");
00106 sector->camera->reset(tux->get_pos());
00107 }
00108 }
00109
00110 TitleScreen::~TitleScreen()
00111 {
00112 }
00113
00114 void
00115 TitleScreen::setup()
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 }
00125
00126 void
00127 TitleScreen::leave()
00128 {
00129 Sector* sector = titlesession->get_current_sector();
00130 sector->deactivate();
00131 MenuManager::set_current(NULL);
00132 }
00133
00134 void
00135 TitleScreen::draw(DrawingContext& context)
00136 {
00137 Sector* sector = titlesession->get_current_sector();
00138 sector->draw(context);
00139
00140
00141
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 }
00154
00155 void
00156 TitleScreen::update(float elapsed_time)
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
00170
00171 if(MenuManager::current() == 0 && g_screen_manager->has_no_pending_fadeout())
00172 {
00173 MenuManager::set_current(main_menu.get());
00174 }
00175 }
00176
00177 void
00178 TitleScreen::start_game(World* world)
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 }
00199
00200