src/sprite/sprite.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_SPRITE_SPRITE_HPP
00018 #define HEADER_SUPERTUX_SPRITE_SPRITE_HPP
00019 
00020 #include "sprite/sprite_data.hpp"
00021 #include "sprite/sprite_ptr.hpp"
00022 #include "video/drawing_context.hpp"
00023 
00024 class Surface;
00025 class DrawingContext;
00026 class Blend;
00027 
00028 class Sprite
00029 {
00030 public:
00031   Sprite(SpriteData& data);
00032   ~Sprite();
00033 
00034   SpritePtr clone() const;
00035 
00037   void draw(DrawingContext& context, const Vector& pos, int layer,
00038       DrawingEffect effect = NO_EFFECT);
00039 
00040   void draw_part(DrawingContext& context, const Vector& source,
00041                  const Vector& size, const Vector& pos, int layer);
00042 
00044   void set_action(const std::string& name, int loops = -1);
00045 
00047   void set_action_continued(const std::string& name);
00048 
00050   void set_animation_loops(int loops = -1)
00051   { animation_loops = loops; }
00052 
00053   /* Stop animation */
00054   void stop_animation()
00055   { animation_loops = 0; }
00057   bool animation_done();
00058 
00059   float get_fps() const
00060   { return action->fps; }
00062   unsigned int get_frames() const
00063   { return action->surfaces.size(); }
00065   const std::string& get_name() const
00066   { return data.name; }
00068   const std::string& get_action() const
00069   { return action->name; }
00070 
00071   int get_width() const;
00072   int get_height() const;
00073 
00075   float get_current_hitbox_x_offset() const;
00077   float get_current_hitbox_y_offset() const;
00079   float get_current_hitbox_width() const;
00081   float get_current_hitbox_height() const;
00083   Rectf get_current_hitbox() const;
00084 
00086   void set_angle(float angle);
00087 
00089   float get_angle() const;
00090 
00091   void set_color(const Color& color);
00092 
00093   Color get_color() const;
00094 
00095   void set_blend(const Blend& blend);
00096 
00097   Blend get_blend() const;
00098 
00100   unsigned int get_frame() const
00101   { return frameidx; }
00103   void set_frame(int frame_)
00104   {
00105     this->frame = 0;
00106     this->frameidx = frame_ % get_frames();
00107   }
00108   SurfacePtr get_frame(unsigned int frame_)
00109   {
00110     assert(frame_ < action->surfaces.size());
00111     return action->surfaces[frame_];
00112   }
00113 
00114   bool has_action (const std::string& name)
00115   {
00116     return (data.get_action(name) != NULL);
00117   }
00118 
00119 private:
00120   void update();
00121 
00122   SpriteData& data;
00123 
00124   // between 0 and 1
00125   float frame;
00126   // between 0 and get_frames()
00127   unsigned int frameidx;
00128   int   animation_loops;
00129   float last_ticks;
00130   float angle;
00131   Color color;
00132   Blend blend;
00133 
00134   const SpriteData::Action* action;
00135 
00136 private:
00137   Sprite(const Sprite& other);
00138   Sprite& operator=(const Sprite&);
00139 };
00140 
00141 #endif
00142 
00143 /* EOF */

Generated on Mon Jun 9 03:38:21 2014 for SuperTux by  doxygen 1.5.1