remove debug printf
[supertux.git] / lib / special / sprite.h
index f397a4b..e8b8d85 100644 (file)
 
 #include <string>
 #include <vector>
+#include <cassert>
+#include <map>
 
-#include "../utils/lispreader.h"
-#include "../video/surface.h"
-#include "../math/vector.h"
+#include "video/surface.h"
+#include "math/vector.h"
+#include "sprite_data.h"
 
 namespace SuperTux
-  {
-
+{
   class Sprite
+  {
+  public:
+    Sprite(SpriteData& data);
+    Sprite(const Sprite& other);
+    ~Sprite();
+    
+    /** Draw sprite, automatically calculates next frame */
+    void draw(DrawingContext& context, const Vector& pos, int layer,
+        Uint32 drawing_effect = NONE_EFFECT);
+
+    void draw_part(DrawingContext& context, const Vector& source,
+        const Vector& size, const Vector& pos, int layer,
+        Uint32 drawing_effect = NONE_EFFECT);
+
+    /** Set action (or state) */
+    void set_action(std::string act, int loops = -1);
+
+    /* Stop animation */
+    void stop_animation()
+    { animation_loops = 0; }
+    /** Check if animation is stopped or not */
+    bool check_animation();
+
+    float get_fps() const
+    { return action->fps; }
+    /** Get current action total frames */
+    int get_frames() const
+    { return action->surfaces.size(); }
+    /** Get sprite's name */
+    const std::string& get_name() const
+    { return data.name; }
+    /** Get current action name */
+    const std::string& get_action_name() const
+    { return action->name; }
+
+    int get_width() const;
+    int get_height() const;
+
+    /** Get current frame */
+    int get_frame() const
+    { return (int)frame; }
+    /** Set current frame */
+    void set_frame(int frame_)
+    { if(frame_ > get_frames()) frame = 0; else frame = frame_; }
+    Surface* get_frame(unsigned int frame)
     {
-    public:
-      /** cur has to be a pointer to data in the form of ((x-hotspot 5)
-          (y-hotspot 10) ...) */
-      Sprite(lisp_object_t* cur);
-      ~Sprite();
-
-      void reset();
-
-      /** Update the sprite and process to the next frame */
-      void update(float delta);
-      void draw(DrawingContext& context, const Vector& pos, int layer,
-                Uint32 drawing_effect = NONE_EFFECT);
-      int get_current_frame() const;
-
-      float get_fps()
-      {
-        return fps;
-      } ;
-      int get_frames()
-      {
-        return surfaces.size();
-      } ;
-
-      std::string get_name() const
-        {
-          return name;
-        }
-      int get_width() const;
-      int get_height() const;
-
-      Surface* get_frame(unsigned int frame)
-      {
-        if(frame < surfaces.size())
-          return surfaces[frame];
-        else
-          return surfaces[0];
-      }    
-    private:
-      std::string name;
-
-      int x_hotspot;
-      int y_hotspot;
-
-      /** Frames per second */
-      float fps;
-
-      /** Number of seconds that a frame is displayed until it is switched
-          to the next frame */
-      float frame_delay;
-
-      float time;
-
-      std::vector<Surface*> surfaces;
-
-      void init_defaults();
-    };
+      assert(frame < action->surfaces.size());
+      return action->surfaces[frame];
+    }    
+
+  private:
+    void update();
+
+    SpriteData& data;
+
+    float frame;
+    int animation_loops;
+    Uint32 last_ticks;
 
+    SpriteData::Action* action;
+  };
 } //namespace SuperTux
 
 #endif /*SUPERTUX_SPRITE_H*/