From: Ricardo Cruz Date: Wed, 15 Sep 2004 11:50:31 +0000 (+0000) Subject: Made statistics to keep track of also: bad guys squished, shots, time needed and... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=03bc45b5d64e7295cb64a30116c9dbf90c0a0c7a;p=supertux.git Made statistics to keep track of also: bad guys squished, shots, time needed and jumps number. 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 --- diff --git a/src/badguy.cpp b/src/badguy.cpp index 65133b3c9..ac0e59b0e 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -34,6 +34,7 @@ #include "level.h" #include "sector.h" #include "tilemap.h" +#include "statistics.h" Sprite* img_mriceblock_flat_left; Sprite* img_mriceblock_flat_right; @@ -1070,6 +1071,8 @@ BadGuy::squish(Player* player) 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; @@ -1121,6 +1124,8 @@ BadGuy::squish(Player* player) 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... @@ -1156,7 +1161,8 @@ BadGuy::squish(Player* player) 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++; diff --git a/src/gameloop.cpp b/src/gameloop.cpp index a8ab4fce7..4431f16f1 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -535,6 +535,9 @@ GameSession::check_end_conditions() 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()) { diff --git a/src/player.cpp b/src/player.cpp index d055a1e59..f5bfcda85 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -35,6 +35,7 @@ #include "resources.h" #include "interactive_object.h" #include "video/screen.h" +#include "statistics.h" // behavior definitions: #define TILES_FOR_BUTTJUMP 3 @@ -517,6 +518,8 @@ Player::handle_vertical_input() // 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 { diff --git a/src/sector.cpp b/src/sector.cpp index 35faf64fe..c0c86f3ee 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -724,7 +724,8 @@ Sector::add_bullet(const Vector& pos, float xm, Direction dir) 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; diff --git a/src/statistics.cpp b/src/statistics.cpp index ab97add20..0083f556d 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -1,5 +1,6 @@ -// SuperTux -// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Ricardo Cruz // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -19,9 +20,29 @@ #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(); @@ -34,13 +55,31 @@ Statistics::~Statistics() 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 @@ -56,9 +95,15 @@ Statistics::get_points(int stat) } 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; } @@ -66,10 +111,17 @@ 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]); + 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]; } diff --git a/src/statistics.h b/src/statistics.h index d22c77349..37567ed72 100644 --- a/src/statistics.h +++ b/src/statistics.h @@ -1,5 +1,6 @@ -// SuperTux -// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Ricardo Cruz // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -24,11 +25,16 @@ using namespace SuperTux; 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 @@ -46,11 +52,16 @@ public: /// 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 */ @@ -60,7 +71,7 @@ public: void operator+=(const Statistics& o); private: - int stats[MAX_STATS]; + int stats[NUM_STATS]; }; extern Statistics global_stats; diff --git a/src/worldmap.cpp b/src/worldmap.cpp index fb1bad6b9..65d45d45e 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -1109,6 +1109,8 @@ WorldMap::draw_status(DrawingContext& context) 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 */