00001
00002
00003
00004
00005 #ifndef LIBWIISPRITE_SPRITE
00006 #define LIBWIISPRITE_SPRITE
00007
00008 #include <stdlib.h>
00009 #include <gccore.h>
00010 #include "image.h"
00011 #include "layer.h"
00012 #include "tiledlayer.h"
00013
00015 namespace wsp{
00017 struct Rectangle{
00018 f32 x,
00019 y;
00020 f32 width,
00021 height;
00022 };
00023
00025 enum TRANSFORM{
00026 TRANS_NONE = 0,
00027 TRANS_MIRROR = 1,
00028 TRANS_BILINEAR_OFF = 2,
00029 TRANS_ADDITIVE_BLENDING = 4
00030 };
00031
00033 class Sprite : public Layer{
00034 public:
00036 Sprite();
00038 virtual ~Sprite();
00039
00045 void SetImage(Image* image, u32 frameWidth = 0, u32 frameHeight = 0);
00048 const Image* GetImage() const;
00051 void SetTransform(u8 transform);
00054 u8 GetTransform() const;
00055
00058 void SetRotation(f32 rotation);
00061 f32 GetRotation() const;
00062
00065 void SetZoom(f32 zoom);
00068 f32 GetZoom() const;
00071 void SetStretchWidth(f32 stretchWidth);
00074 void SetStretchHeight(f32 stretchHeight);
00077 f32 GetStretchWidth() const;
00080 f32 GetStretchHeight() const;
00081
00084 void SetTransparency(u8 alpha);
00087 u8 GetTransparency() const;
00088
00094 void DefineCollisionRectangle(f32 x, f32 y, f32 width, f32 height);
00097 const Rectangle* GetCollisionRectangle() const;
00103 bool CollidesWith(const Rectangle* rect, f32 x = 0, f32 y = 0) const;
00108 bool CollidesWith(const Sprite* sprite, bool complete = false) const;
00112 bool CollidesWith(const TiledLayer* tiledlayer) const;
00113
00117 u32 GetFrame() const;
00122 u32 GetFrameSequencePos() const;
00126 u32 GetFrameSequenceLength() const;
00129 u32 GetRawFrameCount() const;
00133 void SetFrame(u32 sequenceIndex);
00136 void NextFrame();
00139 void PrevFrame();
00144 void SetFrameSequence(u32* sequence, u32 length);
00145
00147 void Draw(f32 offsetX = 0, f32 offsetY = 0) const;
00148 protected:
00149 private:
00150 void _CalcFrame();
00151
00152 f32 _rotation, _stretchWidth, _stretchHeight;
00153 u8 _alpha;
00154 Image* _image;
00155 u8 _trans;
00156
00157 Rectangle* _colRect;
00158
00159 u32 _frame, _frameRawCount;
00160 u32* _frameSeq; u32 _frameSeqLength, _frameSeqPos;
00161 f32 _frameX, _frameY;
00162 };
00163 };
00164
00196 #endif