X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgameloop.cpp;h=4c2bfd2ccbea99a759cbfd8d1349317ad5168939;hb=6e85c29076267d353d426427bdb64c0684297d01;hp=d0368f01630d4f5145efbc68a693debda26caa41;hpb=b56d18cd12b1892a7588b1fe620b1df26f7e7d4f;p=supertux.git diff --git a/src/gameloop.cpp b/src/gameloop.cpp index d0368f016..4c2bfd2cc 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -10,6 +10,7 @@ April 11, 2000 - March 15, 2004 */ +#include #include #include #include @@ -62,6 +63,8 @@ GameSession::restart_level() fps_timer.init(true); frame_timer.init(true); + delete world; + if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) { world = new World(subset); @@ -126,6 +129,28 @@ GameSession::start_timers() } void +GameSession::on_escape_press() +{ + if(!game_pause) + { + if(st_gl_mode == ST_GL_TEST) + { + exit_status = LEVEL_ABORT; + } + else if (!Menu::current()) + { + Menu::set_current(game_menu); + st_pause_ticks_stop(); + } + else + { + Menu::set_current(NULL); + st_pause_ticks_start(); + } + } +} + +void GameSession::process_events() { Player& tux = *world->get_tux(); @@ -134,7 +159,8 @@ GameSession::process_events() while (SDL_PollEvent(&event)) { /* Check for menu-events, if the menu is shown */ - current_menu->event(event); + if (Menu::current()) + Menu::current()->event(event); switch(event.type) { @@ -152,25 +178,7 @@ GameSession::process_events() switch(key) { case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ - if(!game_pause) - { - if(st_gl_mode == ST_GL_TEST) - { - exit_status = LEVEL_ABORT; - } - else if(!show_menu) - { - Menu::set_current(game_menu); - show_menu = 0; - st_pause_ticks_stop(); - } - else - { - Menu::set_current(game_menu); - show_menu = 1; - st_pause_ticks_start(); - } - } + on_escape_press(); break; default: break; @@ -187,7 +195,7 @@ GameSession::process_events() switch(key) { case SDLK_p: - if(!show_menu) + if(!Menu::current()) { if(game_pause) { @@ -282,13 +290,14 @@ GameSession::process_events() tux.input.up = DOWN; else if (event.jbutton.button == JOY_B) tux.input.fire = DOWN; + else if (event.jbutton.button == JOY_START) + on_escape_press(); break; case SDL_JOYBUTTONUP: if (event.jbutton.button == JOY_A) tux.input.up = UP; else if (event.jbutton.button == JOY_B) tux.input.fire = UP; - break; default: @@ -316,7 +325,8 @@ GameSession::check_end_conditions() // Check End conditions if (tux->is_dead()) { - + player_status.lives -= 1; + if (player_status.lives < 0) { // No more lives!? if(st_gl_mode != ST_GL_TEST) @@ -324,8 +334,10 @@ GameSession::check_end_conditions() if(st_gl_mode != ST_GL_TEST) { - if (player_status.score > hs_score) - save_hs(player_status.score); + // FIXME: highscore soving doesn't make sense in its + // current form + //if (player_status.score > hs_score) + //save_hs(player_status.score); } exit_status = GAME_OVER; @@ -345,10 +357,7 @@ GameSession::action(double frame_ratio) if (exit_status == NONE) { - Player* tux = world->get_tux(); - // Update Tux and the World - tux->action(frame_ratio); world->action(frame_ratio); } } @@ -370,9 +379,10 @@ GameSession::draw() blue_text->drawf("PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1); } - if(show_menu) + if(Menu::current()) { - menu_process_current(); + Menu::current()->action(); + Menu::current()->draw(); mouse_cursor->draw(); } @@ -410,12 +420,11 @@ GameSession::run() draw(); + float overlap = 0.0f; while (exit_status == NONE) { /* Calculate the movement-factor */ double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); - if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */ - frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85; if(!frame_timer.check()) { @@ -428,42 +437,43 @@ GameSession::run() process_events(); - if(show_menu) + if(Menu::current()) { - if(current_menu == game_menu) + if(Menu::current() == game_menu) { switch (game_menu->check()) { case 2: st_pause_ticks_stop(); break; - case 3: - // FIXME: - //update_load_save_game_menu(save_game_menu); - break; - case 4: - update_load_save_game_menu(load_game_menu); - break; - case 7: + case 5: st_pause_ticks_stop(); exit_status = LEVEL_ABORT; break; } } - else if(current_menu == options_menu) + else if(Menu::current() == options_menu) { process_options_menu(); } - else if(current_menu == load_game_menu ) + else if(Menu::current() == load_game_menu ) { process_load_game_menu(); } } // Handle actions: - if(!game_pause && !show_menu) + if(!game_pause && !Menu::current()) { - action(frame_ratio); + frame_ratio *= game_speed; + frame_ratio += overlap; + while (frame_ratio > 0) + { + action(1.0f); + frame_ratio -= 1.0f; + } + overlap = frame_ratio; + if (exit_status != NONE) return exit_status; } @@ -487,7 +497,7 @@ GameSession::run() draw(); /* Time stops in pause mode */ - if(game_pause || show_menu ) + if(game_pause || Menu::current()) { continue; }