Made statistics to keep track of also: bad guys squished, shots, time needed and...
authorRicardo Cruz <rick2@aeiou.pt>
Wed, 15 Sep 2004 11:50:31 +0000 (11:50 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Wed, 15 Sep 2004 11:50:31 +0000 (11:50 +0000)
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

src/badguy.cpp
src/gameloop.cpp
src/player.cpp
src/sector.cpp
src/statistics.cpp
src/statistics.h
src/worldmap.cpp

index 65133b3..ac0e59b 100644 (file)
@@ -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++;
index a8ab4fc..4431f16 100644 (file)
@@ -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())
     {
index d055a1e..f5bfcda 100644 (file)
@@ -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 {
index 35faf64..c0c86f3 100644 (file)
@@ -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;
index ab97add..0083f55 100644 (file)
@@ -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 <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();
@@ -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];
 }
index d22c773..37567ed 100644 (file)
@@ -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 <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
@@ -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;
index fb1bad6..65d45d4 100644 (file)
@@ -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 */