Also fixed a couple of things on statistics.
SVN-Revision: 1921
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;
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)
_("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;
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())
{
class Level;
class Sector;
+class Statistics;
namespace SuperTux {
class DrawingContext;
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 */
void on_escape_press();
void process_menu();
+
+ Statistics* best_level_statistics;
};
std::string slotinfo(int slot);
}
}
+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);
void
Statistics::draw_worldmap_info(DrawingContext& context)
{
+ if(stats[SCORE_STAT] == -1) // not initialized yet
+ return;
+
if(!timer.check())
{
timer.start(TOTAL_DISPLAY_TIME);
}
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
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
/* 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);
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())
{
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();