[Super-tux-commit] supertux/src badguy.cpp,1.122,1.123 gameloop.cpp,1.175,1.176 player.cpp,1.165,1.1
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-15 11:50:43
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13781/src Modified Files: badguy.cpp gameloop.cpp player.cpp sector.cpp statistics.cpp statistics.h worldmap.cpp Log Message: 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. Index: statistics.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/statistics.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- statistics.cpp 14 Sep 2004 22:31:46 -0000 1.1 +++ statistics.cpp 15 Sep 2004 11:50:31 -0000 1.2 @@ -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 <ri...@ae...> // // 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 @@ 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 @@ } 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 @@ 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]; } Index: statistics.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/statistics.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- statistics.h 14 Sep 2004 22:31:46 -0000 1.1 +++ statistics.h 15 Sep 2004 11:50:31 -0000 1.2 @@ -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 <ri...@ae...> // // 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 @@ 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 @@ /// 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 @@ void operator+=(const Statistics& o); private: - int stats[MAX_STATS]; + int stats[NUM_STATS]; }; extern Statistics global_stats; Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- sector.cpp 14 Sep 2004 22:26:23 -0000 1.25 +++ sector.cpp 15 Sep 2004 11:50:31 -0000 1.26 @@ -724,7 +724,8 @@ 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; Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.165 retrieving revision 1.166 diff -u -d -r1.165 -r1.166 --- player.cpp 13 Sep 2004 22:45:44 -0000 1.165 +++ player.cpp 15 Sep 2004 11:50:31 -0000 1.166 @@ -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 @@ // 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 { Index: badguy.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.cpp,v retrieving revision 1.122 retrieving revision 1.123 diff -u -d -r1.122 -r1.123 --- badguy.cpp 14 Sep 2004 10:39:32 -0000 1.122 +++ badguy.cpp 15 Sep 2004 11:50:31 -0000 1.123 @@ -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 @@ 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 @@ 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 @@ 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++; Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.116 retrieving revision 1.117 diff -u -d -r1.116 -r1.117 --- worldmap.cpp 14 Sep 2004 22:26:23 -0000 1.116 +++ worldmap.cpp 15 Sep 2004 11:50:31 -0000 1.117 @@ -1109,6 +1109,8 @@ 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 */ Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.175 retrieving revision 1.176 diff -u -d -r1.175 -r1.176 --- gameloop.cpp 14 Sep 2004 22:26:08 -0000 1.175 +++ gameloop.cpp 15 Sep 2004 11:50:31 -0000 1.176 @@ -535,6 +535,9 @@ 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()) { |