Changed FloatingScore to support text (changed name to FloatingText). I guess this...
authorRicardo Cruz <rick2@aeiou.pt>
Mon, 20 Sep 2004 19:17:29 +0000 (19:17 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Mon, 20 Sep 2004 19:17:29 +0000 (19:17 +0000)
Also made a fading animation when disapearing.

SVN-Revision: 1952

src/gameobjs.cpp
src/gameobjs.h
src/sector.cpp

index efaf543..b440b5c 100644 (file)
@@ -114,27 +114,48 @@ BouncyBrick::draw(DrawingContext& context)
     draw_tile(context, shape.id, position + Vector(0, offset), LAYER_TILES+1);
 }
 
-FloatingScore::FloatingScore(const Vector& pos, int score)
+FloatingText::FloatingText(const Vector& pos, std::string& text_)
+  : position(pos), text(text_)
+{
+  timer.start(1000);
+  position.x -= text.size() * 8;
+}
+
+FloatingText::FloatingText(const Vector& pos, int score)
   : position(pos)
 {
   timer.start(1000);
+
+  // turn int into a string
+  char str[10];
   snprintf(str, 10, "%d", score);
-  position.x -= strlen(str) * 8;
+  text = str;
+
+  position.x -= text.size() * 8;
 }
 
 void
-FloatingScore::action(float elapsed_time)
+FloatingText::action(float elapsed_time)
 {
-  position.y -= 2 * elapsed_time;
+  position.y -= 1.4 * elapsed_time;
 
   if(!timer.check())
     remove_me();
 }
 
+#define FADING_TIME 350
+
 void
-FloatingScore::draw(DrawingContext& context)
+FloatingText::draw(DrawingContext& context)
 {
-  context.draw_text(gold_text, str, position, LEFT_ALLIGN, LAYER_OBJECTS);
+  // make an alpha animation when disapearing
+  int alpha;
+  if(timer.get_left() < FADING_TIME)
+    alpha = timer.get_left() * 255 / FADING_TIME;
+  else
+    alpha = 255;
+
+  context.draw_text(gold_text, text, position, LEFT_ALLIGN, LAYER_OBJECTS, NONE_EFFECT, alpha);
 }
 
 /* Trampoline */
index 41de71a..88a8d7a 100644 (file)
@@ -91,17 +91,18 @@ private:
   TileId& shape;      
 };
 
-class FloatingScore : public GameObject
+class FloatingText : public GameObject
 {
 public:
-  FloatingScore(const Vector& pos, int s);
+  FloatingText(const Vector& pos, std::string& text_);
+  FloatingText(const Vector& pos, int s);  // use this for score, for instance
   
   virtual void action(float elapsed_time);
   virtual void draw(DrawingContext& context);
 
 private:
   Vector position;
-  char str[10];
+  std::string text;
   Timer timer;  
 };
 
index b980e8e..0cd48d8 100644 (file)
@@ -667,7 +667,7 @@ Sector::add_score(const Vector& pos, int s)
 {
   global_stats.add_points(SCORE_STAT, s);
                                                                                 
-  add_object(new FloatingScore(pos, s));
+  add_object(new FloatingText(pos, s));
 }
                                                                                 
 void