[Super-tux-commit] supertux/src statistics.cpp,1.2,1.3 statistics.h,1.2,1.3
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-15 18:49:33
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9304/src Modified Files: statistics.cpp statistics.h Log Message: Added a Jump 'n Bump like way to show statistics. It won't work on SDL mode, cause of a bug in draw_part(). I'll have a look at this. Index: statistics.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/statistics.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- statistics.cpp 15 Sep 2004 11:50:31 -0000 1.2 +++ statistics.cpp 15 Sep 2004 18:49:24 -0000 1.3 @@ -21,6 +21,7 @@ #include "utils/lispwriter.h" #include "statistics.h" #include "video/drawing_context.h" +#include "app/gettext.h" #include "resources.h" Statistics global_stats; @@ -45,7 +46,11 @@ Statistics::Statistics() { - reset(); + timer.init(true); + display_stat = 1; + + for(int i = 0; i < NUM_STATS; i++) + stats[i] = -1; } Statistics::~Statistics() @@ -66,14 +71,45 @@ writer.write_int(stat_name_to_string(i), stats[i]); } +#define TOTAL_DISPLAY_TIME 3400 +#define FADING_TIME 600 + void Statistics::draw_worldmap_info(DrawingContext& context) { + if(!timer.check()) + { + timer.start(TOTAL_DISPLAY_TIME); + display_stat++; + if(display_stat >= NUM_STATS) + display_stat = 1; + } + + int alpha; + if(timer.get_gone() < FADING_TIME) + alpha = timer.get_gone() * 255 / FADING_TIME; + else if(timer.get_left() < FADING_TIME) + alpha = timer.get_left() * 255 / FADING_TIME; + else + alpha = 255; + char str[128]; - //TODO: this is just a simple message, will be imporved - sprintf(str, "Level Max Score: %d", stats[SCORE_STAT]); - context.draw_text(white_small_text, str, Vector(580, 580), LAYER_GUI); + context.draw_text(white_small_text, _("Level Statistics"), Vector(550, 490), LAYER_GUI); + + sprintf(str, _("Max score: %d"), stats[SCORE_STAT]); + context.draw_text(white_small_text, str, Vector(560, 506), LAYER_GUI); + + if(display_stat == BADGUYS_SQUISHED_STAT) + sprintf(str, _("Max fragging: %d"), stats[BADGUYS_SQUISHED_STAT]); + else if(display_stat == SHOTS_STAT) + sprintf(str, _("Min shots: %d"), stats[SHOTS_STAT]); + else if(display_stat == TIME_NEEDED_STAT) + sprintf(str, _("Min time needed: %d"), stats[TIME_NEEDED_STAT]); + else// if(display_stat == JUMPS_STAT) + sprintf(str, _("Min jumps: %d"), stats[JUMPS_STAT]); + + context.draw_text(white_small_text, str, Vector(560, 522), LAYER_GUI, NONE_EFFECT, alpha); } void Index: statistics.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/statistics.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- statistics.h 15 Sep 2004 11:50:31 -0000 1.2 +++ statistics.h 15 Sep 2004 18:49:24 -0000 1.3 @@ -20,6 +20,8 @@ #ifndef SUPERTUX_STATISTICS_H #define SUPERTUX_STATISTICS_H +#include "special/timer.h" + using namespace SuperTux; namespace SuperTux { @@ -57,11 +59,12 @@ void draw_worldmap_info(DrawingContext& context); void draw_message_info(DrawingContext& context); + /* Add / Set / Get points to/from one of the stats this can keep track of */ void add_points(int stat, int points); - int get_points(int stat); - void set_points(int stat, int points); + int get_points(int stat); + /* Reset statistics */ void reset(); /* Give another Statistics object, find the best of each one */ @@ -72,6 +75,9 @@ private: int stats[NUM_STATS]; + + Timer timer; + int display_stat; }; extern Statistics global_stats; |