- sounds are on both channels
[supertux.git] / src / sprite / sprite.cpp
index d399504..2ee515a 100644 (file)
@@ -14,7 +14,7 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <cmath>
+#include <math.h>
 
 #include "sprite/sprite.hpp"
 #include "supertux/timer.hpp"
@@ -51,13 +51,19 @@ Sprite::~Sprite()
 {
 }
 
+SpritePtr
+Sprite::clone() const
+{
+  return SpritePtr(new Sprite(*this));
+}
+
 void
 Sprite::set_action(const std::string& name, int loops)
 {
   if(action && action->name == name)
     return;
 
-  SpriteData::Action* newaction = data.get_action(name);
+  const SpriteData::Action* newaction = data.get_action(name);
   if(!newaction) {
     log_debug << "Action '" << name << "' not found." << std::endl;
     return;
@@ -74,7 +80,7 @@ Sprite::set_action_continued(const std::string& name)
   if(action && action->name == name)
     return;
 
-  SpriteData::Action* newaction = data.get_action(name);
+  const SpriteData::Action* newaction = data.get_action(name);
   if(!newaction) {
     log_debug << "Action '" << name << "' not found." << std::endl;
     return;
@@ -143,7 +149,7 @@ Sprite::draw_part(DrawingContext& context, const Vector& source,
   int frameidx = (int) frame;
 
   if(frameidx >= get_frames() || frameidx < 0) {
-#ifndef DEBUG
+#ifdef NDEBUG
     // in optimized mode we get some small rounding errors in floating point
     // number sometimes...
     log_warning << "frame out of range: " << frameidx << "/" << get_frames() << " at sprite: " << get_name() << "/" << get_action() << std::endl;
@@ -159,13 +165,29 @@ Sprite::draw_part(DrawingContext& context, const Vector& source,
 int
 Sprite::get_width() const
 {
-  return (int) action->surfaces[get_frame()]->get_width();
+  if((int)frame >= get_frames() || (int)frame < 0)
+  {
+    log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+    return 0;
+  }
+  else
+  {
+    return (int) action->surfaces[get_frame()]->get_width();
+  }
 }
 
 int
 Sprite::get_height() const
 {
+  if((int)frame >= get_frames() || (int)frame < 0)
+  {
+    log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+    return 0;
+  }
+  else
+  {
   return (int) action->surfaces[get_frame()]->get_height();
+  }
 }
 
 float
@@ -192,16 +214,10 @@ Sprite::get_current_hitbox_height() const
   return action->hitbox_h;
 }
 
-Rect
+Rectf
 Sprite::get_current_hitbox() const
 {
-  return Rect(action->x_offset, action->y_offset, action->x_offset + action->hitbox_w, action->y_offset + action->hitbox_h);
-}
-
-void
-Sprite::set_fps(float new_fps)
-{
-  action->fps = new_fps;
+  return Rectf(action->x_offset, action->y_offset, action->x_offset + action->hitbox_w, action->y_offset + action->hitbox_h);
 }
 
 void