Sprite.h

00001 #ifndef _Sprite_H_
00002 #define _Sprite_H_
00003 
00004 //#include "Entity2D.h"
00005 #include "Shape.h"
00006 #include "renderer.h"
00007 #include "TextureManager.h"
00008 
00009 namespace zak {
00010 
00011 class ZAKENGINE_API Sprite;
00012 
00013 class Frame {
00014         public:
00015                 float _fU, _fV, _fUW, _fUH;
00016 };
00017 
00063 class ZAKENGINE_API Animation : protected SupportScriptReferences {
00064 public:
00070         bool Load(char *filename);
00071 
00072         static bool RegisterAnimation(char *className=NULL);
00073         
00074         //Animation(int iSize);
00075         Animation();
00076         ~Animation();
00077 
00078         friend class Sprite;
00079         friend class ScriptMgr;
00080 
00081 private:
00082         static void ConstructArray(vector<Animation> *self) {
00083                 new(self) vector<Animation>();
00084         }
00085 
00086         static void ConstructArray(int length, vector<Animation> *self) {
00087                 new(self) vector<Animation>(length);
00088         }
00089 
00090         static void DestructArray(vector<Animation> *self) {
00091                 self->~vector();
00092         }
00093 
00094 
00095         static void Constructor(Animation *spr){
00096                 new(spr) Animation();
00097         }
00098         static void Destructor(Animation *spr){
00099                 spr->~Animation();
00100         }
00101 
00102         bool Load(const string &filename);
00103 
00104         int             _iSize;
00105         float   _fAnimationSpeed;
00106         bool    _bLoop;
00107         int             *_iFrameList;
00108 
00109         void SetSize(int iSize)
00110         {
00111                 if (_iFrameList != NULL) {
00112                         delete [] _iFrameList;
00113                 }
00114                 if (iSize>0)
00115                         _iFrameList = new int [iSize];
00116                 else
00117                         _iFrameList = NULL;
00118                 _iSize = iSize;
00119         } //prevents frame array redefinition
00120 };
00121 
00178 class ZAKENGINE_API Sprite : public Shape {
00179         private:
00180         
00181         protected:
00182                 TexVertex       _sprVertex[4];
00183                 Texture         *_pTexture;
00184                 float           _fUV[2];                // UV de la textura a usar
00185                 float           _fW;                    // Ancho del tile
00186                 float           _fH;                    // Alto del tile
00187                 Frame           *_Frames;
00188                 int                     _iFramesCount;
00189                 int                     _iActualFrame;
00190                 Animation       *_Animation;
00191                 bool            _bAnimationRuning;
00192                 float           _fTime;
00193 
00194                 int                     _offsetX;
00195                 int                     _offsetY;
00196                 float           _offsetU;
00197                 float           _offsetV;
00198 
00199                 DWORD           _minFilter;
00200                 DWORD           _magFilter;
00201                 
00202                 void SetUVWH(float fU, float fV, float fW, float fH); // TEMPORAL!!!!! BORRAMEEE!
00203 
00204                 bool InitFrames(int iFramesCount, int iFrameWidth, int iFrameHeight,int iFramesCountPerWidth);
00205                 bool Load(const char *pszImageFilename, unsigned int uiColorKey, bool persist = false, DWORD filter=2, DWORD mipFilter=2);
00206                 bool Load(const string& filename) { return LoadIni((char*)filename.c_str()); }
00207 
00208                 static void Constructor(Sprite *spr){
00209                         new(spr) Sprite();
00210                 }
00211                 static void Destructor(Sprite *spr){
00212                         spr->~Sprite();
00213                 }
00214 
00215                 static void ConstructArray(vector<Sprite> *self) {
00216                         new(self) vector<Sprite>();
00217                 }
00218 
00219                 static void ConstructArray(int length, vector<Sprite> *self) {
00220                         new(self) vector<Sprite>(length);
00221                 }
00222 
00223                 static void DestructArray(vector<Sprite> *self) {
00224                         self->~vector();
00225                 }
00226 
00227 
00228         public:
00234                 bool LoadIni(const char *iniFile);
00235 
00240                 bool Unload();
00241 
00246                 void SetFrame(int iFrame);
00247 
00252                 int GetCurrentFrame(void){return _iActualFrame;}
00253 
00258                 void SetAnimation(Animation *Animation);
00259 
00264                 Animation *GetAnimation() { return _Animation; }
00265 
00270                 bool IsAnimationRunning();
00271 
00275                 virtual void Draw();
00276 
00281                 void Update(float fTimeBetweenFrames);
00282 /*
00283                 bool IsColliding(Sprite *sprite) {
00284                         return Entity2D::IsColliding((Entity2D*) sprite);
00285                 }
00286 
00287                 bool IsColliding(Shape *shape) {
00288                         return Entity2D::IsColliding((Entity2D*) shape);
00289                 }
00290 */
00291                 static bool RegisterSprite(char *className=NULL);
00292 
00296         Sprite();
00297 
00301         ~Sprite();
00302 };
00303 
00304 }
00305 
00306 #endif // _Sprite_H_

Generado el Tue May 29 14:46:15 2007 para Zak Engine v1.1.0 por  doxygen 1.5.1-p1