X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftitle.cpp;h=ebaf5b78aa031a072324573ae1cc36e33d8a0e4e;hb=864c93e01ec366f730b3ebad08d5c52d6a9363b6;hp=12c58e2ae9cf23b75c1b4d3131a78cbedbc75019;hpb=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git diff --git a/src/title.cpp b/src/title.cpp index 12c58e2ae..ebaf5b78a 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -37,14 +37,11 @@ #include #endif -#include "app/globals.h" #include "title.h" #include "video/screen.h" #include "video/surface.h" #include "gui/menu.h" #include "timer.h" -#include "special/frame_rate.h" -#include "app/setup.h" #include "lisp/lisp.h" #include "lisp/parser.h" #include "level.h" @@ -59,9 +56,10 @@ #include "object/camera.h" #include "object/player.h" #include "resources.h" -#include "app/gettext.h" +#include "gettext.h" #include "misc.h" #include "textscroller.h" +#include "file_system.h" #include "control/joystickkeyboardcontroller.h" #include "control/codecontroller.h" #include "main.h" @@ -71,7 +69,7 @@ static Surface* logo; static Surface* img_choose_subset; static bool walking; -static Timer2 random_timer; +static Timer random_timer; static int frame; @@ -81,8 +79,6 @@ static CodeController* controller; static std::vector contrib_subsets; static LevelSubset* current_contrib_subset = 0; -static FrameRate frame_rate(100); - /* If the demo was stopped - because game started, level editor was excuted, etc - call this when you get back to the title code. @@ -93,7 +89,7 @@ void resume_demo() titlesession->get_current_sector()->activate("main"); titlesession->set_current(); - frame_rate.update(); + //frame_rate.update(); } void update_load_save_game_menu(Menu* menu) @@ -136,7 +132,7 @@ void generate_contrib_menu() delete subset; continue; } - contrib_menu->add_submenu(subset->title, contrib_subset_menu); + contrib_menu->add_submenu(subset->title, contrib_subset_menu, i); contrib_subsets.push_back(subset); ++i; } @@ -225,25 +221,22 @@ void check_levels_contrib_menu() void check_contrib_subset_menu() { int index = contrib_subset_menu->check(); - if (index != -1) - { - if (contrib_subset_menu->get_item_by_id(index).kind == MN_ACTION) - { - std::cout << "Starting level: " << index << std::endl; - - GameSession session( - current_contrib_subset->get_level_filename(index), ST_GL_PLAY); - session.run(); - player_status.reset(); - Menu::set_current(main_menu); - resume_demo(); - } - } + if (index != -1) { + if (contrib_subset_menu->get_item_by_id(index).kind == MN_ACTION) { + GameSession session( + current_contrib_subset->get_level_filename(index), ST_GL_PLAY); + session.run(); + player_status.reset(); + Menu::set_current(main_menu); + resume_demo(); + } + } } void draw_demo(float elapsed_time) { static float last_tux_x_pos = -1; + static float last_tux_y_pos = -1; Sector* sector = titlesession->get_current_sector(); Player* tux = sector->player; @@ -252,14 +245,19 @@ void draw_demo(float elapsed_time) controller->update(); controller->press(Controller::RIGHT); - if(random_timer.check() || (int) last_tux_x_pos == (int) tux->get_pos().x) { - random_timer.start(float(rand() % 3000 + 3000) / 1000.); - walking = !walking; + if(random_timer.check() || + (walking && (int) last_tux_x_pos == (int) tux->get_pos().x)) { + walking = false; } else { - if(!walking) - controller->press(Controller::JUMP); + if(!walking && (int) tux->get_pos().y == (int) last_tux_y_pos) { + random_timer.start(float(rand() % 3000 + 3000) / 1000.); + walking = true; + } } + if(!walking) + controller->press(Controller::JUMP); last_tux_x_pos = tux->get_pos().x; + last_tux_y_pos = tux->get_pos().y; // Wrap around at the end of the level back to the beginnig if(sector->solids->get_width() * 32 - 320 < tux->get_pos().x) { @@ -275,12 +273,10 @@ void draw_demo(float elapsed_time) void title() { walking = true; - LevelEditor* leveleditor; + //LevelEditor* leveleditor; MusicRef credits_music; controller = new CodeController(); - Ticks::pause_init(); - titlesession = new GameSession(get_resource_filename("levels/misc/menu.stl"), ST_GL_DEMO_GAME); @@ -304,7 +300,8 @@ void title() Menu::set_current(main_menu); DrawingContext& context = *titlesession->context; - while (Menu::current()) + bool running = true; + while (running) { // Calculate the movement-factor Uint32 ticks = SDL_GetTicks(); @@ -326,7 +323,6 @@ void title() Menu::current()->event(event); } main_controller->process_event(event); - // FIXME: QUIT signal should be handled more generic, not locally if (event.type == SDL_QUIT) throw std::runtime_error("Received window close"); } @@ -366,17 +362,17 @@ void title() break; case MNID_LEVELS_CONTRIB: // Contrib Menu - puts("Entering contrib menu"); generate_contrib_menu(); break; #if 0 - case MNID_LEVELEDITOR: - leveleditor = new LevelEditor(); + case MNID_LEVELEDITOR: { + LevelEdtiro* leveleditor = new LevelEditor(); leveleditor->run(); delete leveleditor; Menu::set_current(main_menu); resume_demo(); break; + } #endif case MNID_CREDITS: fadeout(500); @@ -388,7 +384,7 @@ void title() Menu::set_current(main_menu); break; case MNID_QUITMAINMENU: - Menu::set_current(0); + running = false; break; } } @@ -431,11 +427,17 @@ void title() } } + // reopen menu of user closed it (so that the app doesn't close when user + // accidently hit ESC) + if(Menu::current() == 0) { + Menu::set_current(main_menu); + } + mouse_cursor->draw(context); context.do_drawing(); - frame_rate.update(); + //frame_rate.update(); /* Pause: */ frame++;