00001 #ifndef LIBWIISPRITE_SPRITE 00002 #define LIBWIISPRITE_SPRITE 00003 00004 #include <stdlib.h> 00005 #include <gccore.h> 00006 #include "image.h" 00007 #include "layer.h" 00008 #include "tiledlayer.h" 00009 00011 namespace wsp{ 00013 struct Rectangle{ 00014 f32 x, 00015 y; 00016 f32 width, 00017 height; 00018 }; 00019 00021 enum TRANSFORM{ 00022 TRANS_NONE = 0, 00023 TRANS_MIRROR, 00024 TRANS_BILINEAR_OFF 00025 }; 00026 00028 class Sprite : public Layer{ 00029 public: 00031 Sprite(); 00033 virtual ~Sprite(); 00034 00040 void SetImage(Image* image, u32 frameWidth = 0, u32 frameHeight = 0); 00043 const Image* GetImage() const; 00046 void SetTransform(TRANSFORM transform); 00049 TRANSFORM GetTransform() const; 00050 00053 void SetRotation(f32 rotation); 00056 f32 GetRotation() const; 00057 00060 void SetZoom(f32 zoom); 00063 f32 GetZoom() const; 00066 void SetStretchWidth(f32 stretchWidth); 00069 void SetStretchHeight(f32 stretchHeight); 00072 f32 GetStretchWidth() const; 00075 f32 GetStretchHeight() const; 00076 00079 void SetTransparency(u8 alpha); 00082 u8 GetTransparency() const; 00083 00089 void DefineCollisionRectangle(f32 x, f32 y, f32 width, f32 height); 00092 const Rectangle* GetCollisionRectangle() const; 00098 bool CollidesWith(const Rectangle* rect, f32 x = 0, f32 y = 0) const; 00102 bool CollidesWith(const Sprite* sprite) const; 00106 bool CollidesWith(const TiledLayer* tiledlayer) const; 00107 00111 u32 GetFrame() const; 00116 u32 GetFrameSequencePos() const; 00120 u32 GetFrameSequenceLength() const; 00123 u32 GetRawFrameCount() const; 00127 void SetFrame(u32 sequenceIndex); 00130 void NextFrame(); 00133 void PrevFrame(); 00138 void SetFrameSequence(u32* sequence, u32 length); 00139 00141 void Draw(f32 offsetX = 0, f32 offsetY = 0) const; 00142 protected: 00143 private: 00144 void _CalcFrame(); 00145 00146 f32 _rotation, _stretchWidth, _stretchHeight; 00147 u8 _alpha; 00148 Image* _image; 00149 TRANSFORM _trans; 00150 00151 Rectangle* _colRect; 00152 00153 u32 _frame, _frameRawCount; 00154 u32* _frameSeq; u32 _frameSeqLength, _frameSeqPos; 00155 f32 _frameX, _frameY; 00156 }; 00157 }; 00158 00190 #endif