Also print in the worldmap a message to show the maximum level's score. This is temporary and will be replaced with a better info text.
SVN-Revision: 1916
#include "level.h"
#include "sector.h"
#include "tilemap.h"
+#include "statistics.h"
Sprite* img_mriceblock_flat_left;
Sprite* img_mriceblock_flat_right;
Sector::current()->add_score(Vector(base.x, base.y),
25 * player_status.score_multiplier);
SoundManager::get()->play_sound(IDToSound(SND_SQUISH), get_pos(), Sector::current()->player->get_pos());
+
+ global_stats.add_points(BADGUYS_SQUISHED_STAT, 1);
player_status.score_multiplier++;
return;
Sector::current()->add_score(Vector(base.x, base.y),
25 * player_status.score_multiplier);
+
+ global_stats.add_points(BADGUYS_SQUISHED_STAT, 1);
player_status.score_multiplier++;
// simply remove the fish...
player->bounce(this);
base.y += 66 - base.height;
-
+
+ global_stats.add_points(BADGUYS_SQUISHED_STAT, 1);
Sector::current()->add_score(Vector(base.x, base.y),
25 * player_status.score_multiplier);
player_status.score_multiplier++;
SoundManager::get()->play_music(level_end_song, 0);
endsequence_timer.start(7000); // 5 seconds until we finish the map
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());
}
else if (!end_sequence && tux->is_dead())
{
#include "resources.h"
#include "interactive_object.h"
#include "video/screen.h"
+#include "statistics.h"
// behavior definitions:
#define TILES_FOR_BUTTJUMP 3
// Press jump key
if(input.up == DOWN && can_jump && on_ground())
{
+ global_stats.add_points(JUMPS_STAT, 1);
+
if(duck) { // only jump a little bit when in duck mode {
physic.set_velocity_y(3);
} else {
else
throw std::runtime_error("wrong bullet type.");
add_object(new_bullet);
-
+
+ global_stats.add_points(SHOTS_STAT, 1);
SoundManager::get()->play_sound(IDToSound(SND_SHOOT));
return true;
-// SuperTux
-// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details
+//
+// SuperTux - A Jump'n Run
+// Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
#include "utils/lispreader.h"
#include "utils/lispwriter.h"
#include "statistics.h"
+#include "video/drawing_context.h"
+#include "resources.h"
Statistics global_stats;
+std::string
+stat_name_to_string(int stat_enum)
+{
+ switch(stat_enum)
+ {
+ case SCORE_STAT:
+ return "score";
+ case BADGUYS_SQUISHED_STAT:
+ return "badguys-squished";
+ case SHOTS_STAT:
+ return "shots";
+ case TIME_NEEDED_STAT:
+ return "time-needed";
+ case JUMPS_STAT:
+ return "jumps";
+ }
+}
+
Statistics::Statistics()
{
reset();
void
Statistics::parse(LispReader& reader)
{
- reader.read_int("score", stats[SCORE_STAT]);
+ for(int i = 0; i < NUM_STATS; i++)
+ reader.read_int(stat_name_to_string(i).c_str(), stats[i]);
}
void
Statistics::write(LispWriter& writer)
{
- writer.write_int("score", stats[SCORE_STAT]);
+ for(int i = 0; i < NUM_STATS; i++)
+ writer.write_int(stat_name_to_string(i), stats[i]);
+}
+
+void
+Statistics::draw_worldmap_info(DrawingContext& context)
+{
+ 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);
+}
+
+void
+Statistics::draw_message_info(DrawingContext& context)
+{
+ // TODO
}
void
}
void
+Statistics::set_points(int stat, int points)
+{
+ stats[stat] = points;
+}
+
+void
Statistics::reset()
{
- for(int i = 0; i < MAX_STATS; i++)
+ for(int i = 0; i < NUM_STATS; i++)
stats[i] = 0;
}
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]);
+ 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[TIME_NEEDED_STAT] =
+ std::min(stats[TIME_NEEDED_STAT], stats_.stats[TIME_NEEDED_STAT]);
}
void
Statistics::operator+=(const Statistics& stats_)
{
- stats[SCORE_STAT] += stats_.stats[SCORE_STAT];
+ for(int i = 0; i < NUM_STATS; i++)
+ stats[i] += stats_.stats[i];
}
-// SuperTux
-// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details
+//
+// SuperTux - A Jump'n Run
+// Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
namespace SuperTux {
class LispReader;
class LispWriter;
+class DrawingContext;
}
enum {
SCORE_STAT,
- MAX_STATS
+ BADGUYS_SQUISHED_STAT,
+ SHOTS_STAT,
+ TIME_NEEDED_STAT,
+ JUMPS_STAT,
+ NUM_STATS
};
/** This class is a layer between level and worldmap to keep
/// write statistics to lisp file
void write(LispWriter& writer);
- // TODO: add drawing functions to draw stats on WorldMap
+ /* 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 add_points(int stat, int points);
int get_points(int stat);
+ void set_points(int stat, int points);
+
void reset();
/* Give another Statistics object, find the best of each one */
void operator+=(const Statistics& o);
private:
- int stats[MAX_STATS];
+ int stats[NUM_STATS];
};
extern Statistics global_stats;
context.draw_text_center(white_text, i->title,
Vector(0, screen->h - white_text->get_height() - 30),
LAYER_FOREGROUND1);
+
+ i->statistics.draw_worldmap_info(context);
}
/* Display an in-map message in the map, if any as been selected */