fix cr/lfs and remove trailing whitespaces...
[supertux.git] / src / object / moving_sprite.cpp
index 3b3e7d7..953d556 100644 (file)
@@ -18,6 +18,7 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <config.h>
+#include <stdexcept>
 
 #include "moving_sprite.hpp"
 #include "video/drawing_context.hpp"
@@ -80,7 +81,7 @@ MovingSprite::MovingSprite(const MovingSprite& other)
   sprite = new Sprite(*other.sprite);
 }
 
-MovingSprite& 
+MovingSprite&
 MovingSprite::operator=(const MovingSprite& other)
 {
   if (this == &other) return *this;
@@ -104,9 +105,23 @@ MovingSprite::draw(DrawingContext& context)
   sprite->draw(context, get_pos(), layer);
 }
 
-void 
+void
 MovingSprite::update(float )
 {
 }
 
+void
+MovingSprite::set_action(const std::string& action, int loops)
+{
+  sprite->set_action(action, loops);
+  set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
+}
 
+void
+MovingSprite::set_action_centered(const std::string& action, int loops)
+{
+  Vector old_size = bbox.get_size();
+  sprite->set_action(action, loops);
+  set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
+  set_pos(get_pos() - (bbox.get_size() - old_size) / 2);
+}