00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SPRITE_H
00026 #define _SPRITE_H
00027
00028 #include <SDL.h>
00029 #include <vector>
00030 #include "spriteframe.h"
00031 #include "spritecache.h"
00032 #include "spriteanimation.h"
00033 #include "include/base.h"
00034
00035 typedef enum {
00036 top_left,
00037 top_center,
00038 top_right,
00039 left_center,
00040 center,
00041 right_center,
00042 bottom_left,
00043 bottom_center,
00044 bottom_right,
00045 user_defined
00046 } Rotation_HotSpot;
00047
00048 class Sprite
00049 {
00050 public:
00051 SpriteCache cache;
00052 SpriteAnimation animation;
00053
00054 public:
00055 explicit Sprite();
00056 explicit Sprite( Surface surface);
00057 Sprite(const Sprite &other);
00058
00059 void Init(Surface& surface, const Point2i &frameSize, int nb_frames_x, int nb_frames_y);
00060 Surface GetSurface();
00061
00062
00063 unsigned int GetCurrentFrame() const;
00064 void SetCurrentFrame( unsigned int frame_no);
00065 unsigned int GetFrameCount();
00066
00067
00068 unsigned int GetWidth() const;
00069 unsigned int GetWidthMax() const;
00070
00071 unsigned int GetHeight() const;
00072 unsigned int GetHeightMax() const;
00073
00074 Point2i GetSize() const;
00075 Point2i GetSizeMax() const;
00076
00077 void GetScaleFactors( float &scale_x, float &scale_y);
00078 void SetSize(unsigned int w, unsigned int h);
00079 void SetSize(const Point2i &size);
00080 void Scale( float scale_x, float scale_y);
00081 void ScaleSize(int width, int height);
00082 void ScaleSize(Point2i size);
00083
00084
00085 void SetRotation_rad( double angle_rad);
00086 const double &GetRotation_rad();
00087 void SetRotation_HotSpot( const Point2i new_hotspot);
00088 void SetRotation_HotSpot( const Rotation_HotSpot rhs) { rot_hotspot = rhs; };
00089 const Point2i& GetRotationPoint() { return rotation_point; };
00090
00091 SpriteFrame& operator[] (unsigned int frame_no);
00092 const SpriteFrame& operator[] (unsigned int frame_no) const;
00093 const SpriteFrame& GetCurrentFrameObject() const;
00094
00095
00096 void AddFrame( const Surface& surf, unsigned int delay = 100);
00097 void SetFrameSpeed(unsigned int nv_fs);
00098
00099
00100 void Start();
00101 void Update();
00102 void Finish();
00103 bool IsFinished() const;
00104
00105
00106 void SetAlpha( float alpha);
00107 float GetAlpha();
00108
00109
00110 void EnableRotationCache(unsigned int cache_size);
00111 void EnableFlippingCache();
00112
00113
00114 void Show();
00115 void Hide();
00116
00117
00118 void Blit(Surface &dest, uint pox_x, uint pos_y);
00119 void Blit(Surface &dest, const Point2i &pos);
00120 void Blit(Surface &dest, const Rectanglei &srcRect, const Point2i &destPos);
00121 void Blit(Surface &dest, int pox_x, int pos_y, int src_x, int src_y, uint w, uint h);
00122 void Draw(const Point2i &pos);
00123 void DrawXY(const Point2i &pos);
00124
00125 void RefreshSurface();
00126
00127 private:
00128 Surface current_surface;
00129 bool show;
00130
00131 unsigned int current_frame;
00132 int frame_width_pix,frame_height_pix;
00133 std::vector<SpriteFrame> frames;
00134
00135
00136 float alpha;
00137 float scale_x,scale_y;
00138 double rotation_rad;
00139 Point2i rhs_pos;
00140 Rotation_HotSpot rot_hotspot;
00141 Point2i rotation_point;
00142
00143 private:
00144 void Constructor();
00145 void Calculate_Rotation_Offset(Surface& tmp_surface);
00146 };
00147
00148 #endif