[Super-tux-commit] supertux/src gameloop.cpp,1.177,1.178 gameloop.h,1.60,1.61 statistics.cpp,1.3,1.4
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-15 21:59:39
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24462/src Modified Files: gameloop.cpp gameloop.h statistics.cpp statistics.h worldmap.cpp Log Message: Added drawing of statistics on levels messages and game over. Also fixed a couple of things on statistics. Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.60 retrieving revision 1.61 diff -u -d -r1.60 -r1.61 --- gameloop.h 14 Sep 2004 22:26:13 -0000 1.60 +++ gameloop.h 15 Sep 2004 21:59:30 -0000 1.61 @@ -45,6 +45,7 @@ class Level; class Sector; +class Statistics; namespace SuperTux { class DrawingContext; @@ -95,7 +96,7 @@ DrawingContext* context; Timer time_left; - GameSession(const std::string& level, int mode, bool flip_level_ = false); + GameSession(const std::string& level, int mode, bool flip_level_ = false, Statistics* statistics = NULL); ~GameSession(); /** Enter the busy loop */ @@ -134,6 +135,8 @@ void on_escape_press(); void process_menu(); + + Statistics* best_level_statistics; }; std::string slotinfo(int slot); Index: statistics.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/statistics.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- statistics.cpp 15 Sep 2004 18:49:24 -0000 1.3 +++ statistics.cpp 15 Sep 2004 21:59:30 -0000 1.4 @@ -44,6 +44,16 @@ } } +int +my_min(int a, int b) +{ +if(a == -1) + return b; +if(b == -1) + return a; +return std::min(a, b); +} + Statistics::Statistics() { timer.init(true); @@ -77,6 +87,9 @@ void Statistics::draw_worldmap_info(DrawingContext& context) { + if(stats[SCORE_STAT] == -1) // not initialized yet + return; + if(!timer.check()) { timer.start(TOTAL_DISPLAY_TIME); @@ -113,9 +126,29 @@ } void -Statistics::draw_message_info(DrawingContext& context) +Statistics::draw_message_info(DrawingContext& context, std::string title) { - // TODO + if(stats[SCORE_STAT] == -1) // not initialized yet + return; + + context.draw_text_center(gold_text, title, Vector(0, 400), LAYER_GUI); + + char str[128]; + for(int i = 0; i < NUM_STATS; i++) + { + if(i == SCORE_STAT) + sprintf(str, _("Max score: %d"), stats[SCORE_STAT]); + else if(i == BADGUYS_SQUISHED_STAT) + sprintf(str, _("Max fragging: %d"), stats[BADGUYS_SQUISHED_STAT]); + else if(i == SHOTS_STAT) + sprintf(str, _("Min shots: %d"), stats[SHOTS_STAT]); + else if(i == TIME_NEEDED_STAT) + sprintf(str, _("Min time needed: %d"), stats[TIME_NEEDED_STAT]); + else// if(i == JUMPS_STAT) + sprintf(str, _("Min jumps: %d"), stats[JUMPS_STAT]); + + context.draw_text_center(white_text, str, Vector(0, 430 + i*22), LAYER_GUI); + } } void @@ -147,12 +180,13 @@ Statistics::merge(Statistics& stats_) { stats[SCORE_STAT] = std::max(stats[SCORE_STAT], stats_.stats[SCORE_STAT]); - stats[JUMPS_STAT] = std::min(stats[JUMPS_STAT], stats_.stats[JUMPS_STAT]); + if(stats[JUMPS_STAT] != -1) + stats[JUMPS_STAT] = my_min(stats[JUMPS_STAT], stats_.stats[JUMPS_STAT]); stats[BADGUYS_SQUISHED_STAT] = std::max(stats[BADGUYS_SQUISHED_STAT], stats_.stats[BADGUYS_SQUISHED_STAT]); - stats[SHOTS_STAT] = std::min(stats[SHOTS_STAT], stats_.stats[SHOTS_STAT]); + stats[SHOTS_STAT] = my_min(stats[SHOTS_STAT], stats_.stats[SHOTS_STAT]); stats[TIME_NEEDED_STAT] = - std::min(stats[TIME_NEEDED_STAT], stats_.stats[TIME_NEEDED_STAT]); + my_min(stats[TIME_NEEDED_STAT], stats_.stats[TIME_NEEDED_STAT]); } void Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.117 retrieving revision 1.118 diff -u -d -r1.117 -r1.118 --- worldmap.cpp 15 Sep 2004 11:50:31 -0000 1.117 +++ worldmap.cpp 15 Sep 2004 21:59:30 -0000 1.118 @@ -834,7 +834,8 @@ shrink_fade(Vector((special_tile->x*32 + 16 + offset.x),(special_tile->y*32 + 16 + offset.y)), 500); GameSession session(datadir + "/levels/" + special_tile->level_name, - ST_GL_LOAD_LEVEL_FILE, special_tile->vertical_flip); + ST_GL_LOAD_LEVEL_FILE, special_tile->vertical_flip, + &special_tile->statistics); switch (session.run()) { @@ -908,18 +909,20 @@ context.draw_text_center(blue_text, _("GAMEOVER"), Vector(0, 200), LAYER_FOREGROUND1); - sprintf(str, _("SCORE: %d"), total_stats.get_points(SCORE_STAT)); - context.draw_text_center(gold_text, str, - Vector(0, 230), LAYER_FOREGROUND1); +// sprintf(str, _("SCORE: %d"), total_stats.get_points(SCORE_STAT)); +// context.draw_text_center(gold_text, str, +// Vector(0, 230), LAYER_FOREGROUND1); sprintf(str, _("COINS: %d"), player_status.distros); context.draw_text_center(gold_text, str, Vector(0, screen->w - 32), LAYER_FOREGROUND1); + total_stats.draw_message_info(context, _("Total Statistics")); + context.do_drawing(); SDL_Event event; - wait_for_event(event,2000,5000,true); + wait_for_event(event,2000,6000,true); quit = true; player_status.reset(); Index: statistics.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/statistics.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- statistics.h 15 Sep 2004 18:49:24 -0000 1.3 +++ statistics.h 15 Sep 2004 21:59:30 -0000 1.4 @@ -57,7 +57,7 @@ /* Draw to the worldmap or a game message */ // TODO: make this functions working void draw_worldmap_info(DrawingContext& context); - void draw_message_info(DrawingContext& context); + void draw_message_info(DrawingContext& context, std::string title); /* Add / Set / Get points to/from one of the stats this can keep track of */ void add_points(int stat, int points); Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.177 retrieving revision 1.178 diff -u -d -r1.177 -r1.178 --- gameloop.cpp 15 Sep 2004 21:38:49 -0000 1.177 +++ gameloop.cpp 15 Sep 2004 21:59:30 -0000 1.178 @@ -78,9 +78,10 @@ return false; } -GameSession::GameSession(const std::string& levelname_, int mode, bool flip_level_) +GameSession::GameSession(const std::string& levelname_, int mode, bool flip_level_, Statistics* statistics) : level(0), currentsector(0), st_gl_mode(mode), - end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_) + end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_), + best_level_statistics(statistics) { current_ = this; @@ -184,7 +185,7 @@ if(level->get_author().size()) context.draw_text_center(white_small_text, std::string(_("by ")) + level->get_author(), - Vector(0, 400), LAYER_FOREGROUND1); + Vector(0, 360), LAYER_FOREGROUND1); if(flip_level) @@ -192,6 +193,9 @@ _("Level Vertically Flipped!"), Vector(0, 310), LAYER_FOREGROUND1); + if(best_level_statistics != NULL) + best_level_statistics->draw_message_info(context, "Best Level Statistics"); + context.do_drawing(); SDL_Event event; @@ -546,7 +550,7 @@ tux->invincible_timer.start(7000); //FIXME: Implement a winning timer for the end sequence (with special winning animation etc.) // add left time to stats - global_stats.set_points(TIME_NEEDED_STAT, time_left.get_gone()); + global_stats.set_points(TIME_NEEDED_STAT, time_left.get_gone() / 1000); } else if (!end_sequence && tux->is_dead()) { |