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 enum REFPIXEL_POSITIONING{
00034 REFPIXEL_POS_TOPLEFT = 0,
00035 REFPIXEL_POS_PIXEL
00036 };
00037
00039 class Sprite : public Layer{
00040 public:
00042 Sprite();
00044 virtual ~Sprite();
00045
00051 void SetImage(Image* image, u32 frameWidth = 0, u32 frameHeight = 0);
00054 const Image* GetImage() const;
00057 void SetTransform(u8 transform);
00060 u8 GetTransform() const;
00061
00064 void SetRotation(f32 rotation);
00067 f32 GetRotation() const;
00068
00071 void SetZoom(f32 zoom);
00074 f32 GetZoom() const;
00077 void SetStretchWidth(f32 stretchWidth);
00080 void SetStretchHeight(f32 stretchHeight);
00083 f32 GetStretchWidth() const;
00086 f32 GetStretchHeight() const;
00087
00090 void SetTransparency(u8 alpha);
00093 u8 GetTransparency() const;
00094
00100 void SetRefPixelPosition(f32 x, f32 y);
00103 void SetRefPixelX(f32 x);
00106 void SetRefPixelY(f32 y);
00109 f32 GetRefPixelX() const;
00112 f32 GetRefPixelY() const;
00115 void SetRefPixelPositioning(REFPIXEL_POSITIONING positioning);
00118 REFPIXEL_POSITIONING GetRefPixelPositioning() const;
00119
00125 void DefineCollisionRectangle(f32 x, f32 y, f32 width, f32 height);
00128 const Rectangle* GetCollisionRectangle() const;
00134 bool CollidesWith(const Rectangle* rect, f32 x = 0, f32 y = 0) const;
00139 bool CollidesWith(const Sprite* sprite, bool complete = false) const;
00143 bool CollidesWith(const TiledLayer* tiledlayer) const;
00144
00148 u32 GetFrame() const;
00153 u32 GetFrameSequencePos() const;
00157 u32 GetFrameSequenceLength() const;
00160 u32 GetRawFrameCount() const;
00164 void SetFrame(u32 sequenceIndex);
00167 void NextFrame();
00170 void PrevFrame();
00175 void SetFrameSequence(u32* sequence, u32 length);
00176
00178 void Draw(f32 offsetX = 0, f32 offsetY = 0) const;
00179 protected:
00180 private:
00181 void _CalcFrame();
00182
00183 f32 _rotation, _stretchWidth, _stretchHeight;
00184 u8 _alpha;
00185 Image* _image;
00186 u8 _trans;
00187
00188 Rectangle* _colRect;
00189
00190 u32 _frame, _frameRawCount;
00191 u32* _frameSeq; u32 _frameSeqLength, _frameSeqPos;
00192 f32 _txCoords[4];
00193 f32 _refPixelX, _refPixelY, _refWidth, _refHeight;
00194 REFPIXEL_POSITIONING _positioning;
00195 };
00196 };
00197
00229 #endif