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. // diamond at bottom of tiles
  20. #define RHOMBUSWIDTH  24 //32 // 64
  21. #define RHOMBUSHEIGHT 24    
  22. #define HEIGHTOVERLAPPING (RHOMBUSHEIGHT/2)+1
  23.  
  24. // unit logic
  25. // range (in pixels) to check for player as target
  26. #define SIGHT_RANGE 200
  27.  
  28. typedef enum
  29. { // matches the order of sprites in sprite sheets now //
  30.     EAST    = 1,
  31.     NORTH   = 2,
  32.     NE      = 3,
  33.     NW      = 4,
  34.     SOUTH   = 5,
  35.     SE      = 6,
  36.     SW      = 7,
  37.     WEST    = 8
  38. } DIRS;
  39.  
  40. // these are used to define the unit states
  41. typedef enum
  42. {
  43.     INACTIVE    = 0,
  44.     ACTIVE      = 1,        // moving
  45.     CASTING     = 2,
  46.     ATTACKING   = 3,
  47.     APPEARING   = 4,
  48.     DYING       = 6,
  49.     DEAD        = 9
  50. } STATEtype;
  51.  
  52. typedef enum
  53. {
  54.     STRENGTH       = 1, // strength
  55.     DEXTERITY      = 2, // dexterity
  56.     CONSTITUTION   = 3,  // constitution
  57.     WISDOM         = 4, // wisdom
  58.     INTELLIGENCE   = 5, // intelligence
  59.     LUCK           = 6  // luck
  60. } STATISTIC;
  61.  
  62. class CCombatInfo
  63. {
  64. public:
  65.     int getOffense(); // returns offensive value (attack)
  66.     int getDefense(); // returns defensive modifier (armor)
  67.  
  68.     void setHP(int newHP);
  69.     void modHP(int mod);
  70.      int curHP();
  71.  
  72.     void setOffense(int newOff);
  73.     void setDefense(int newDef);
  74.     void modOff(int mod);
  75.     void modDef(int mod);
  76.  
  77.     CCombatInfo(int Offense, int Defense, int Health); // constructor
  78.  
  79. private:
  80.     int offense;
  81.     int defense;
  82.     int health; // current health
  83. };
  84.  
  85.  
  86. class CUnitStats // physical statistics of units
  87. {
  88. public:
  89.  
  90.     int fullHP();       // returns full health
  91.     int fullMana();     // returns full mana
  92.  
  93.     int getOff();       // returns offense skill
  94.     int getDef();       // returns defense skill
  95.  
  96.     int getValue(int Stat);             // returns value of given statistic
  97.     void setStat(int Stat, int Value);  // sets stat to given value
  98.     void modStat(int Stat, int Change); // to permanently increase or decrease a statistic
  99.     void setMaxHP(int newMax);          // changes the max HP
  100.  
  101.     CUnitStats();   // default constructor, assigns random values to each stat                 
  102.     CUnitStats(int s, int d, int c, int w, int i, int l); // alternate constructor
  103.  
  104. private:
  105.     int Str, Dex, Con, Wis, Int, Lck, maxHealth, maxMana;
  106. };
  107.  
  108.  
  109. // CUSTOM SPRITE CLASS //
  110. class CSprite
  111. {
  112. public:
  113.  
  114.     // Public - so their functions can be used outside
  115.     CUnitStats  *Stats; // abilties and such
  116.     CCombatInfo *Combat; // using random defaults
  117.  
  118.     // fully heals unit
  119.     void Heal();
  120.     // changes the units current and max HP value
  121.     void setHP(int newHP);
  122.     // returns current mana
  123.     int curMana();     
  124.     // add/sub from mana pool ... returns false if not enough mana to do it
  125.     bool modMana(int modifier);
  126.  
  127.     // applies damage to the unit
  128.     // returns 0 if still alive, 1 if dying/dead
  129.     bool doDamage(int damage);
  130.  
  131.      int nextFrame();                // increments frame and returns 1 if its reached the end
  132.      int getFrame();                 // returns current frame
  133.     void setFrame(int newFrame);     // sets current frame to new value
  134.  
  135.     void setLastFrame(int newLastFrame); // sets the last frame of animation sequence
  136.     int getLastFrame();                  // returns current "last" frame
  137.  
  138.     void setDelay(int newDelay);        // sets the delay used for animations
  139.      int getDelay();                    // returns current value
  140.  
  141.     void setupAnim(int numFrames, DIRS newDir, int perRow);
  142.  
  143.     void setXY(int newX, int newY);
  144.      int getX();
  145.      int getY();
  146.     void setX(int newX);
  147.     void setY(int newY);
  148.     void addX(int addtoX);
  149.     void addY(int addtoY);
  150.  
  151.     void setMoveXY(int moveX, int moveY);
  152.     void setMoveX(int newX);
  153.     void setMoveY(int newY);
  154.      int getMoveY();
  155.      int getMoveX();
  156.  
  157.      int getHeight();
  158.      int getWidth();
  159.  
  160.     // check movement keys
  161.     void checkArrowsKeys();
  162.     void doMove(bool SAFE);
  163.  
  164.     // holds the units sprite sheet
  165.     LPDIRECT3DTEXTURE9 getImage();
  166.  
  167.     // returns a rect pointing to the sprites current frame
  168.     RECT getRect();
  169.  
  170.     // returns current facing of sprite
  171.     DIRS getFacing();
  172.     // sets the facing of sprite
  173.     void setFacing(DIRS newFacing , bool changeMoveXY);
  174.  
  175.     // sets new facing and movexy at same time, using int
  176.     void setNewDIR(int newDIR);
  177.  
  178.     bool isMoving();                // returns true if sprite is moving
  179.     void setMoving(bool newState);  // sets if sprite is moving
  180.  
  181.     void setRhombus();      // creates / sets the sprites rectangle/rhombus
  182.     RECT getRhombus();      // this will return the "iso diamond" at the bottom of the sprite
  183.    
  184.     POINT getScreenPT();    // returns current screen xy of sprite as POINT
  185.  
  186.     // defines the screen walkable/collision border for this sprite
  187.     void setBorder(int left, int right, int top, int bottom);
  188.  
  189.     // returns TRUE if sprite is within its defined border, FALSE otherwise
  190.     bool hitBorder();
  191.  
  192.     // sets the sprites current STATE
  193.     void setSTATE(STATEtype newS);
  194.  
  195.     // returns the curren STATE of sprite
  196.     int getSTATE();
  197. //  INACTIVE    = 0,
  198. //  ACTIVE      = 1,        // moving
  199. //  CASTING     = 2,
  200. //  ATTACKING   = 3,
  201. //  DYING       = 6
  202. //  STATEtype STATE;
  203.  
  204.     // returns the anchor point, which is in center of the sprite collision rectangle
  205.     POINT getAnchor();
  206.  
  207.     // constructor for new sprites ... curFrame will always be (1) .. scale and rotation not currently implemented
  208.     // and this is for non-animated sprites
  209.     CSprite(int X, int Y, int Width, int Height, char *Filename);
  210.  
  211.     // destructor
  212.     ~CSprite(void);
  213.  
  214. private:
  215.     STATEtype STATE;
  216.  
  217.     RECT border;
  218.     RECT rhombus;
  219.  
  220.     DIRS facingDir;       // direction sprite is facing, used for choosing correct sprite from sprite sheet
  221.     DIRS lastDir;
  222.  
  223.     bool moving;
  224.  
  225.     int x,y;
  226.     int width,height;
  227.     int mana; // current mana
  228.  
  229.     int movex,movey;
  230.     int curframe,lastframe;
  231.     int animdelay,animcount;
  232.     int columns;         // used to grabs sprites from sprite map
  233.     int frames_per_anim; // using sprite sheet, will need this
  234.  
  235.     LPDIRECT3DTEXTURE9 _image;
  236.  
  237.     void LoadImage(char *Filename);
  238.  
  239. }; // end of CSprite class
  240.  
  241. #endif