This should fix animations. (bugs in the line of bomb explosions)
[supertux.git] / lib / special / sprite.cpp
index c6a3289..8e80604 100644 (file)
@@ -79,15 +79,32 @@ Sprite::parse_action(LispReader& lispreader)
   if(!lispreader.read_string_vector("images", images))
     Termination::abort("Sprite contains no images: ", action->name.c_str());
 
-  for(std::vector<std::string>::size_type i = 0; i < images.size(); ++i)
+  for(std::vector<std::string>::size_type i = 0; i < images.size(); i++)
     {
       action->surfaces.push_back(
           new Surface(datadir + "/images/" + images[i], true));
-    }        
+    }
+
+  // TODO: add a top filter entry
+  std::vector <int> mask_color;
+  lispreader.read_int_vector("apply-mask", mask_color);
+  if(mask_color.size() == 4)
+    {
+    for(std::vector<Surface*>::iterator i = action->surfaces.begin();
+        i < action->surfaces.end(); i++)
+      {
+        (*i)->apply_mask(Color(mask_color));
+      }
+    }
 
   actions[action->name] = action;
 }
 
+/*void Sprite::parse_filter(LispReader& lispreader)
+{
+
+}*/
+
 void
 Sprite::init_defaults(Action* act)
 {
@@ -114,6 +131,9 @@ if(i == actions.end())
   return;
   }
 action = i->second;
+
+if((int)frame >= get_frames())
+  frame = 0;
 }
 
 void
@@ -185,7 +205,7 @@ if(animation_reversed)
   }
 else
   {
-  float excedent = frame - action->surfaces.size();
+  float excedent = frame - (get_frames()+1);
   if((int)excedent >= 0)
     {
     frame = 0;
@@ -213,7 +233,7 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer,
 
   if((int)frame >= get_frames() || (int)frame < 0)
     std::cerr << "Warning: frame out of range: " << (int)frame
-              << "/" << get_frames() << " at sprite: " << get_name()
+              << "/" << get_frames() << " at " << get_name()
               << "/" << get_action_name() << std::endl;
   else
     context.draw_surface(action->surfaces[(int)frame],