1. // CSprite class header
  2.  
  3. #ifndef CSPRITE_H
  4. #define CSPRITE_H
  5.  
  6. //windows/directx headers
  7. #include <d3d9.h>
  8. #include <d3dx9.h>
  9. #include <assert.h>
  10.  
  11. //framework-specific headers
  12. #include "dxgraphics.h"
  13.  
  14.  
  15. // diamond at bottom of tiles
  16. #define TILEWIDTH  32
  17. #define TILEHEIGHT 32    
  18.  
  19. // unit logic
  20. // range (in pixels) to check for player as target
  21. #define SIGHT_RANGE 200
  22.  
  23. typedef enum
  24. { // matches the order of sprites in sprite sheets now //
  25.      EAST        = 1,
  26.      NORTH  = 2,
  27.      SOUTH  = 3,
  28.      WEST        = 4,
  29.      DYING     = 5
  30. } DIRS;
  31.  
  32. // these are used to define the unit states
  33. typedef enum
  34. {
  35.      SPAWN     = 1,
  36.      CHASE     = 2,
  37.      EVADE     = 3,
  38.      DEAD      = 4,
  39.      ALIVE     = 5
  40. } STATEtype;
  41.  
  42. // CUSTOM SPRITE CLASS //
  43. class CSprite
  44. {
  45. public:
  46.      int nextFrame();                    // increments frame and returns 1 if its reached the end
  47.      int getFrame();                     // returns current frame
  48.      void setFrame(int newFrame);             // sets current frame to new value
  49.  
  50.      void setLastFrame(int newLastFrame);    // sets the last frame of animation sequence
  51.      int getLastFrame();                     // returns current "last" frame
  52.  
  53.      void setDelay(int newDelay);            // sets the delay used for animations
  54.      int getDelay();                    // returns current value
  55.  
  56.      void setupAnim(int numFrames, DIRS newDir, int perRow);
  57.  
  58.      void setTileXY(int tileX, int tileY);
  59.  
  60.      void setXY(int newX, int newY);
  61.      int getX();
  62.      int getY();
  63.      void setX(int newX);
  64.      void setY(int newY);
  65.      void addX(int addtoX);
  66.      void addY(int addtoY);
  67.  
  68.      void setMoveXY(int moveX, int moveY);
  69.      void setMoveX(int newX);
  70.      void setMoveY(int newY);
  71.      int getMoveY();
  72.      int getMoveX();
  73.  
  74.      int getHeight();
  75.      int getWidth();
  76.  
  77.      void doMove();
  78.      void setSpeed(int newSpd);
  79.  
  80.      // holds the units sprite sheet
  81.      LPDIRECT3DTEXTURE9 getImage();
  82.  
  83.      // returns a rect pointing to the sprites current frame
  84.      RECT getRect();
  85.  
  86.      // returns a rectangle in Window coordinates, of sprites current location
  87.      RECT getWindowRect();
  88.  
  89.      // returns current facing of sprite
  90.      DIRS getFacing();
  91.  
  92.      // sets the facing of sprite
  93.      void setFacing(DIRS newFacing);
  94.  
  95.      // move towards tile
  96.      void gotoTile(int tileX, int tileY);
  97.  
  98.      // returns true if curr location equals destination tile
  99.      bool atDest();
  100.  
  101.      // returns current x,y tile occupying
  102.      POINT getTile();
  103.  
  104.      // checks if the sprite is moving between tiles
  105.      bool isBetweenTiles();
  106.  
  107.      void setTarget(int tX, int tY);
  108.      POINT getTarget();
  109.  
  110.      // sets new facing and movexy at same time, using int
  111.      void setNewDIR(int newDIR);
  112.  
  113.      bool isMoving();               // returns true if sprite is moving
  114.      void setMoving(bool newState); // sets if sprite is moving
  115.  
  116.      POINT getWindowPT();   // returns current Window xy of sprite as POINT
  117.  
  118.      // sets the sprites current STATE
  119.      void setSTATE(STATEtype newS);
  120.  
  121.      // returns the curren STATE of sprite
  122.      int getSTATE();
  123.  
  124.      // constructor for new sprites ... curFrame will always be (1) .. scale and rotation not currently implemented
  125.      // and this is for non-animated sprites
  126.      CSprite(int X, int Y, int Width, int Height, char *Filename);
  127.  
  128.      // destructor
  129.      ~CSprite(void);
  130.  
  131.      void setHome(int x, int y);
  132.      POINT getHome();
  133.      void goHome(); // sets target to home location
  134.  
  135.      void setHasBody(bool newVal);
  136.      bool getHasBody();
  137.  
  138. private:
  139.      STATEtype STATE;
  140.  
  141.      DIRS facingDir;       // direction sprite is facing, used for choosing correct sprite from sprite sheet
  142.  
  143.      bool moving;
  144.  
  145.      POINT destTile;
  146.      POINT targetTile; // tile location to try to get to
  147.      POINT home; // location it returns to when SPAWN'ing, etc.
  148.  
  149.      int windowX,windowY;
  150.      int width,height;
  151.      int speed;
  152.  
  153.      bool hasBody;
  154.  
  155.      int movex,movey;
  156.      int curframe,lastframe;
  157.      int animdelay,animcount;
  158.      int columns;         // used to grabs sprites from sprite map
  159.      int frames_per_anim; // using sprite sheet, will need this
  160.  
  161.      LPDIRECT3DTEXTURE9 _image;
  162.  
  163.      void LoadImage(char *Filename);
  164.  
  165. }; // end of CSprite class
  166.  
  167. #endif