Sprite.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. // Sprite.h: interface for the CSprite class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_SPRITE_H__C64EA3C5_9B4C_4633_8C96_9D84A5EF475B__INCLUDED_)
  5. #define AFX_SPRITE_H__C64EA3C5_9B4C_4633_8C96_9D84A5EF475B__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #define ST_KILL 20000
  10. #define ST_DEAD (ST_KILL+1)      
  11. class CSprite  
  12. {
  13. public:
  14. void Destroy();
  15. const long& GetType();
  16. RECT GetBoundingRect(POINT& ptLoc);
  17. void SetAnimBiDir(bool bIsAnimBiDir = true);
  18. long m_nID;  // Used to uniquely identify each sprite in the game.
  19. long m_nPoints;
  20. void EnableBorder(bool bDraw = false);
  21. long& GetState();
  22. void MoveTo(long nX, long nY);
  23. RECT GetRect();
  24. void Draw(LPDIRECTDRAWSURFACE7 pdds);
  25. void Update();
  26. void MoveTo(POINT ptNewLoc);
  27. void SetState(long nState, bool bForceState = false);
  28. bool IsHit(RECT rcRect);
  29. void AddState(long nState, POINT ptFrame, long nNoOfFrames, long nDelay, RECT* prcBound = NULL,LPTSTR pszSound = NULL, bool bLoopSound = false );
  30. void CreateSprite(CSurface** pSurface, long nType, long nHeight, long nWidth);
  31. CSprite();
  32. virtual ~CSprite();
  33. struct SMovement {
  34. long m_dx,m_dy;
  35. long m_nMoveDelay;
  36. long m_nCurrMoveDelay;
  37. bool (*m_pfnCollision)(RECT& rcRect);
  38. long m_nInvulnerable;
  39. long m_nPathFindDelay;
  40. long m_nCurrPathFindDelay;
  41. void (*m_pfnFindPath)(CSprite* pSprite);
  42. SMovement():m_pfnFindPath(0),
  43. m_dx(0), m_dy(0),
  44. m_pfnCollision(0),
  45. m_nCurrMoveDelay(0),
  46. m_nCurrPathFindDelay(0),
  47. m_nPathFindDelay(0),
  48. m_nMoveDelay(0),m_nInvulnerable(0) {}
  49. } m_Movement;
  50. POINT m_ptLocation;
  51. void (*m_pfnDead)(CSprite* pSprite);
  52. // This function is called before Kill state is set
  53. // if this function return false, then KILL state is
  54. // not set.
  55. bool (*m_pfnKill)(CSprite* pSprite);
  56. protected:
  57. bool m_bDrawBorder;
  58. CSurface** m_ppSurface;   // This surface contains all the sprites.
  59. long m_nType;
  60. struct SSTATE {
  61. long m_nState;
  62. POINT m_ptFirstFrame;
  63. long m_nNoOfFrames;
  64. long m_nDelay;
  65. RECT m_rcBounding;            // Rect used for Collision detection
  66. CSound* m_pSound;
  67. bool m_bLoopSound;
  68. inline bool operator==(const long& nState);
  69. } m_CurrState;
  70. struct SAnim {
  71. bool m_bIsAnimBiDir;       // Sprites are animated from frames 0 to n then n to 0
  72. bool m_bIsAnimForward;     // The direction of the current animation
  73. long m_nCurrDelay;
  74. long m_nCurrFrame;
  75. long m_nHeight;
  76. long m_nWidth;
  77. } m_Anim;
  78. std::list<SSTATE> m_StateList;
  79. };
  80. #endif // !defined(AFX_SPRITE_H__C64EA3C5_9B4C_4633_8C96_9D84A5EF475B__INCLUDED_)