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 }; 00025 00027 class Sprite : public Layer{ 00028 public: 00030 Sprite(); 00032 virtual ~Sprite(); 00033 00039 void SetImage(Image* image, u32 frameWidth = 0, u32 frameHeight = 0); 00042 const Image* GetImage() const; 00045 void SetTransform(TRANSFORM transform); 00048 TRANSFORM GetTransform() const; 00049 00052 void SetRotation(f32 rotation); 00055 f32 GetRotation() const; 00056 00059 void SetZoom(f32 zoom); 00062 f32 GetZoom() const; 00063 00066 void SetTransparency(u8 alpha); 00069 u8 GetTransparency() const; 00070 00071 00077 void DefineCollisionRectangle(f32 x, f32 y, f32 width, f32 height); 00080 const Rectangle* GetCollisionRectangle() const; 00086 bool CollidesWith(const Rectangle* rect, f32 x = 0, f32 y = 0) const; 00090 bool CollidesWith(const Sprite* sprite) const; 00094 bool CollidesWith(const TiledLayer* tiledlayer) const; 00095 00098 u32 GetFrame() const; 00101 u32 GetFrameSequenceLength() const; 00103 u32 GetRawFrameCount() const; 00106 void SetFrame(u32 sequenceIndex); 00108 void NextFrame(); 00110 void PrevFrame(); 00114 void SetFrameSequence(u32* sequence, u32 length); 00115 00117 void Draw(f32 offsetX = 0, f32 offsetY = 0) const; 00118 protected: 00119 private: 00120 void _CalcFrame(); 00121 00122 f32 _rotation, _zoom; 00123 u8 _alpha; 00124 Image* _image; 00125 TRANSFORM _trans; 00126 00127 Rectangle* _colRect; 00128 00129 u32 _frame, _frameRawCount; 00130 u32* _frameSeq; u32 _frameSeqLength, _frameSeqPos; 00131 f32 _frameX, _frameY; 00132 }; 00133 }; 00134 00135 #endif