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 "dxinput.h"
  13. #include "dxgraphics.h"
  14.  
  15. //macros to read the keyboard asynchronously
  16. #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  17. #define KEY_UP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  18.  
  19. // unit logic
  20. // range (in pixels) to check for player as target
  21. #define SIGHT_RANGE 500
  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.     SW      = 5,
  30.     NW      = 6,
  31.     NE      = 7,
  32.     SE      = 8
  33. } DIRS;
  34. //      case EAST:  setAngle(  0); break;
  35. //      case SE:    setAngle( 45); break;
  36. //      case SOUTH: setAngle( 90); break;
  37. //      case SW:    setAngle(135); break;
  38. //      case WEST:  setAngle(180); break;
  39. //      case NW:    setAngle(225); break;
  40. //      case NORTH: setAngle(270); break;
  41. //      case NE:    setAngle(315); break;
  42.  
  43. // these are used to define the unit states
  44. typedef enum
  45. {
  46.     INACTIVE    = 0,
  47.     ACTIVE      = 1,        // moving
  48.     ATTACKING   = 3,
  49.     SPAWNING    = 4,
  50.     FLEEING     = 6,
  51.     SEARCHING   = 7,
  52.     DYING       = 8,
  53.     DEAD        = 9
  54. } STATEtype;
  55.  
  56. #define PI 3.1415926535897932384626433832795
  57.  
  58.  
  59. // GLOBALS //
  60. double find_x(int degree);
  61. double find_y(int degree);
  62. POINT find_OrbitXY(int degree, float distance, POINT startPT);
  63. POINT calcXY(int degree, float distance, POINT startPT);
  64.  
  65.  
  66. // CUSTOM SPRITE CLASS //
  67. class CSprite
  68. {
  69. public:
  70.     void setPT(POINT tPT);
  71.  
  72.      int nextFrame();                // increments frame and returns 1 if its reached the end
  73.      int getFrame();                 // returns current frame
  74.     void setFrame(int newFrame);     // sets current frame to new value
  75.  
  76.     void setLastFrame(int newLastFrame); // sets the last frame of animation sequence
  77.     int getLastFrame();                  // returns current "last" frame
  78.  
  79.     void setDelay(int newDelay);        // sets the delay used for animations
  80.      int getDelay();                    // returns current value
  81.  
  82.     void setupAnim(int numFrames, DIRS newDir, int perRow);
  83.  
  84.     void setXY(int newX, int newY);
  85.      int getX();
  86.      int getY();
  87.     void setX(int newX);
  88.     void setY(int newY);
  89.     void addX(int addtoX);
  90.     void addY(int addtoY);
  91.  
  92.     void setMoveXY(int moveX, int moveY);
  93.     void setMoveX(int newX);
  94.     void setMoveY(int newY);
  95.      int getMoveY();
  96.      int getMoveX();
  97.  
  98.      int getHeight();
  99.      int getWidth();
  100.  
  101.     // holds the units sprite sheet
  102.     LPDIRECT3DTEXTURE9 getImage();
  103.  
  104.     // returns a rect pointing to the sprites current frame
  105.     RECT getRect();
  106.  
  107.     // returns a collision rect, using GAMEWORLD coordinates
  108.     RECT collisionRect(int ScrollX,int ScrollY);
  109.     RECT scaledRect(int ScrollX,int ScrollY, float scaleX, float scaleY);
  110.  
  111.     DIRS getFacing();                   // returns current facing of sprite
  112.     void setFacing(DIRS newFacing);     // sets the facing of sprite
  113.     void setNewDIR(int newDIR);         // sets new facing and movexy at same time, using int
  114.  
  115.     bool isMoving();                    // returns true if sprite is moving
  116.     void setMoving(bool newState);      // sets if sprite is moving
  117.    
  118.     POINT getPT();  // returns current screen xy of sprite as POINT
  119.  
  120.     void setBorder(int left, int right, int top, int bottom);   // defines the screen walkable/collision border for this sprite
  121.     bool inBorder();                                            // returns TRUE if sprite is within its defined border, FALSE otherwise
  122.     bool checkBorder();                                         // checks and corrects xy inside border, returns true if fixed something
  123.    
  124.     void setSTATE(STATEtype newS);          // sets the sprites current STATE  
  125.     STATEtype getSTATE();                           // returns the curren STATE of sprite
  126.    
  127.     POINT getAnchor();  // returns the anchor point, which is in center of the sprite collision rectangle
  128.  
  129.      int getAngle();            // current angle used for rotating sprite
  130.     void addAngle(int newA);    // adds to current angle, wrapping around at 360 to 0
  131.     void setAngle(int newA);    // sets new angle
  132.  
  133.  
  134.     void doMove();
  135.  
  136.     LPCSTR getFilename();
  137.  
  138.     // constructor for new sprites ... curFrame will always be (1) .. scale and rotation not currently implemented
  139.     // and this is for non-animated sprites
  140.     CSprite(int X, int Y, int Width, int Height, LPCSTR Filename);
  141.  
  142.     // destructor
  143.     ~CSprite(void);
  144.  
  145.     void setAnimate(bool value);
  146.  
  147. private:
  148.     int angle;
  149.  
  150.     STATEtype STATE;
  151.  
  152.     DIRS facingDir;       // direction sprite is facing, used for choosing correct sprite from sprite sheet
  153.     DIRS lastDir;
  154.  
  155.     RECT border;
  156.  
  157.     bool moving;
  158.  
  159.     int x,y;
  160.     int width,height;
  161.  
  162.     LPCSTR filename;
  163.  
  164.     int movex,movey;
  165.     int curframe,lastframe;
  166.     int animdelay,animcount;
  167.     int columns;         // used to grabs sprites from sprite map
  168.     int frames_per_anim; // using sprite sheet, will need this
  169.  
  170.     LPDIRECT3DTEXTURE9 _image;
  171.  
  172.     void LoadImage(LPCSTR Filename);
  173.  
  174.     bool doANIM;
  175. }; // end of CSprite class
  176.  
  177. #endif
  178.