[Super-tux-commit] supertux/src badguy.h,1.30,1.31 gameloop.cpp,1.89,1.90 gameloop.h,1.43,1.44 level
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-21 12:46:07
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16778 Modified Files: badguy.h gameloop.cpp gameloop.h level.cpp sprite.cpp Log Message: - added end-sequence code Index: badguy.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- badguy.h 20 Apr 2004 20:10:47 -0000 1.30 +++ badguy.h 21 Apr 2004 12:44:52 -0000 1.31 @@ -24,6 +24,7 @@ #define SUPERTUX_BADGUY_H #include "SDL.h" +#include "defines.h" #include "bitmask.h" #include "type.h" #include "timer.h" Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- gameloop.h 20 Apr 2004 11:09:33 -0000 1.43 +++ gameloop.h 21 Apr 2004 12:45:05 -0000 1.44 @@ -55,6 +55,11 @@ unsigned int update_time; int pause_menu_frame; int debug_fps; + + /** If true the end_sequence will be played, user input will be + ignored while doing that */ + bool end_sequenze; + bool game_pause; // FIXME: Hack for restarting the level @@ -97,6 +102,7 @@ private: void on_escape_press(); + void process_menu(); }; std::string slotinfo(int slot); Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- level.cpp 20 Apr 2004 20:10:48 -0000 1.43 +++ level.cpp 21 Apr 2004 12:45:06 -0000 1.44 @@ -484,7 +484,7 @@ // Mark the end position of this level! // FIXME: -10 is a rather random value, we still need some kind of // real levelend gola - endpos = 32*(width-10); + endpos = 32*(width-20); fclose(fi); return 0; Index: sprite.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sprite.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- sprite.cpp 17 Apr 2004 22:22:35 -0000 1.4 +++ sprite.cpp 21 Apr 2004 12:45:07 -0000 1.5 @@ -18,6 +18,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <iostream> +#include <math.h> #include "globals.h" #include "sprite.h" Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.89 retrieving revision 1.90 diff -u -d -r1.89 -r1.90 --- gameloop.cpp 20 Apr 2004 18:46:57 -0000 1.89 +++ gameloop.cpp 21 Apr 2004 12:44:52 -0000 1.90 @@ -66,8 +66,9 @@ void GameSession::restart_level() { - game_pause = false; - exit_status = NONE; + game_pause = false; + exit_status = NONE; + end_sequenze = false; fps_timer.init(true); frame_timer.init(true); @@ -176,8 +177,6 @@ void GameSession::process_events() { - Player& tux = *world->get_tux(); - SDL_Event event; while (SDL_PollEvent(&event)) { @@ -187,8 +186,18 @@ Menu::current()->event(event); st_pause_ticks_start(); } + else if (end_sequenze) + { + Player& tux = *world->get_tux(); + tux.input.left = UP; + tux.input.right = DOWN; + tux.input.up = UP; + tux.input.down = UP; + } else { + Player& tux = *world->get_tux(); + st_pause_ticks_stop(); switch(event.type) @@ -340,11 +349,15 @@ Player* tux = world->get_tux(); /* End of level? */ - if (tux->base.x >= World::current()->get_level()->endpos - && World::current()->get_level()->endpos != 0) + if (tux->base.x >= World::current()->get_level()->endpos + 320) { exit_status = LEVEL_FINISHED; } + else if (tux->base.x >= World::current()->get_level()->endpos) + { + end_sequenze = true; + halt_music(); + } else { // Check End conditions @@ -405,6 +418,37 @@ updatescreen(); } +void +GameSession::process_menu() +{ + Menu* menu = Menu::current(); + if(menu) + { + menu->action(); + + if(menu == game_menu) + { + switch (game_menu->check()) + { + case 2: + st_pause_ticks_stop(); + break; + case 5: + st_pause_ticks_stop(); + exit_status = LEVEL_ABORT; + break; + } + } + else if(menu == options_menu) + { + process_options_menu(); + } + else if(menu == load_game_menu ) + { + process_load_game_menu(); + } + } +} GameSession::ExitStatus GameSession::run() @@ -453,43 +497,22 @@ tux->input.old_fire = tux->input.fire; process_events(); - - Menu* menu = Menu::current(); - if(menu) - { - menu->action(); + process_menu(); - if(menu == game_menu) - { - switch (game_menu->check()) - { - case 2: - st_pause_ticks_stop(); - break; - case 5: - st_pause_ticks_stop(); - exit_status = LEVEL_ABORT; - break; - } - } - else if(menu == options_menu) - { - process_options_menu(); - } - else if(menu == load_game_menu ) - { - process_load_game_menu(); - } - } - - // Handle actions: + // Update the world state and all objects in the world + // Do that with a constante time-delta so that the game will run + // determistic and not different on different machines if(!game_pause && !Menu::current()) { frame_ratio *= game_speed; frame_ratio += overlap; while (frame_ratio > 0) { - action(1.0f); + // Update the world + if (end_sequenze) + action(.5f); + else + action(1.0f); frame_ratio -= 1.0f; } overlap = frame_ratio; @@ -500,17 +523,6 @@ SDL_Delay(50); } - if(debug_mode && debug_fps) - SDL_Delay(60); - - /*Draw the current scene to the screen */ - /*If the machine running the game is too slow - skip the drawing of the frame (so the calculations are more precise and - the FPS aren't affected).*/ - /*if( ! fps_fps < 50.0 ) - game_draw(); - else - jump = true;*/ /*FIXME: Implement this tweak right.*/ draw(); /* Time stops in pause mode */ @@ -521,17 +533,16 @@ /* Set the time of the last update and the time of the current update */ last_update_time = update_time; - update_time = st_get_ticks(); + update_time = st_get_ticks(); /* Pause till next frame, if the machine running the game is too fast: */ /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */ - if(last_update_time >= update_time - 12) { - SDL_Delay(10); - update_time = st_get_ticks(); - } - /*if((update_time - last_update_time) < 10) - SDL_Delay((11 - (update_time - last_update_time))/2);*/ + if(last_update_time >= update_time - 12) + { + SDL_Delay(10); + update_time = st_get_ticks(); + } /* Handle time: */ if (time_left.check()) @@ -545,7 +556,9 @@ } } else if(tux->dying == DYING_NOT) - tux->kill(KILL); + { + tux->kill(KILL); + } /* Calculate frames per second */ if(show_fps) |