Added GameManager class to keep track of the World objects, should fix the crashing...
[supertux.git] / src / supertux / player_status.cpp
index 0f322ca..6980414 100644 (file)
@@ -16,6 +16,7 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <math.h>
+#include <sstream>
 
 #include "audio/sound_manager.hpp"
 #include "util/writer.hpp"
 static const int START_COINS = 100;
 static const int MAX_COINS = 9999;
 
+static const int DISPLAYED_COINS_UNSET = -1;
+
 PlayerStatus* player_status = 0;
 
 PlayerStatus::PlayerStatus() :
+  /* Do we really want -Weffc++ to bully us into duplicating code from "reset" here? */
   coins(START_COINS),
   bonus(NO_BONUS),
   max_fire_bullets(0),
   max_ice_bullets(0),
+  displayed_coins(DISPLAYED_COINS_UNSET),
+  displayed_coins_frame(0),
   coin_surface()
 {
   reset();
@@ -53,6 +59,7 @@ void PlayerStatus::reset()
 {
   coins = START_COINS;
   bonus = NO_BONUS;
+  displayed_coins = DISPLAYED_COINS_UNSET;
 }
 
 void
@@ -125,14 +132,15 @@ PlayerStatus::read(const Reader& lisp)
 void
 PlayerStatus::draw(DrawingContext& context)
 {
-  static int displayed_coins = -1;
-  static int next_count = 0;
+  int player_id = 0;
 
-  if ((displayed_coins == -1) || (fabsf(displayed_coins - coins) > 100)) {
+  if ((displayed_coins == DISPLAYED_COINS_UNSET) ||
+      (fabsf(displayed_coins - coins) > 100)) {
     displayed_coins = coins;
+    displayed_coins_frame = 0;
   }
-  if (++next_count > 2) {
-    next_count = 0;
+  if (++displayed_coins_frame > 2) {
+    displayed_coins_frame = 0;
     if (displayed_coins < coins) displayed_coins++;
     if (displayed_coins > coins) displayed_coins--;
   }
@@ -149,10 +157,16 @@ PlayerStatus::draw(DrawingContext& context)
   {
     context.draw_surface(coin_surface, 
                          Vector(SCREEN_WIDTH - BORDER_X - coin_surface->get_width() - Resources::fixed_font->get_text_width(coins_text), 
-                                BORDER_Y + 1),
+                                BORDER_Y + 1 + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
                          LAYER_HUD);
   }
-  context.draw_text(Resources::fixed_font, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), ALIGN_RIGHT, LAYER_HUD, PlayerStatus::text_color);
+  context.draw_text(Resources::fixed_font, 
+                    coins_text, 
+                    Vector(SCREEN_WIDTH - BORDER_X - Resources::fixed_font->get_text_width(coins_text),
+                           BORDER_Y + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
+                    ALIGN_LEFT,
+                    LAYER_HUD,
+                    PlayerStatus::text_color);
 
   context.pop_transform();
 }