00001 #ifndef SPRITE_H
00002 #define SPRITE_H
00003 #include "SDL.h"
00004 #include "SDL_opengl.h"
00005 #include <string>
00006 #include <iostream>
00007 #include <map>
00008
00009 typedef enum { LEFT = -1, RIGHT = 1 } xDirection;
00010 typedef enum { UP = -1, MIDDLE = 0, DOWN = 1 } yDirection;
00011
00012 class Sprite
00013 {
00014 public:
00015 Sprite(){;}
00016
00017
00018
00019 Sprite(std::string filename);
00020 Sprite(std::string filename, int width, int height);
00021 Sprite(Sprite *sprite);
00022
00023
00024
00025
00026 virtual Sprite* instance();
00027 virtual void draw(int x, int y, bool origin = LEVEL);
00028
00029 virtual void clean(){;};
00030
00031
00032 virtual void drawBox(int x, int y, SDL_Rect drawBox);
00033
00034 int width(){return _rect.w;}
00035 int height(){return _rect.h;}
00036 void setHeight( int h ){ _rect.h = h; };
00037 void setWidth( int w ){ _rect.w = w; };
00038 virtual SDL_Rect rect(){return _rect;}
00039 virtual SDL_Rect box(){return _box;}
00040 void setRect( SDL_Rect r ){ _rect = r; };
00041 void setBox( SDL_Rect b ){ _box = b; };
00042 std::string filename() {return _filename;}
00043 int getTexture() {return _hTexture;}
00044
00045 virtual void update(){;}
00046 virtual void reset(){;}
00047
00048 static Sprite* loadSprite( std::string filename );
00049 static Sprite* loadText( std::string filename );
00050 static void cleanSprites();
00051
00052
00053 xDirection getDirection() {return _direction;}
00054 void setDirection(xDirection direction) {_direction = direction;}
00055
00056
00057
00058 static const bool LEVEL = true;
00059 static const bool SCREEN = false;
00060
00061 protected:
00062
00063 static std::map<std::string,Sprite *> SPRITES;
00064
00065
00066 std::string _filename;
00067 unsigned int _hTexture;
00068 GLfloat _coords[4];
00069 SDL_Rect _rect;
00070 SDL_Rect _box;
00071 xDirection _direction;
00072 };
00073
00074 #endif