Sprite.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
- // Sprite.h: interface for the CSprite class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_SPRITE_H__C64EA3C5_9B4C_4633_8C96_9D84A5EF475B__INCLUDED_)
- #define AFX_SPRITE_H__C64EA3C5_9B4C_4633_8C96_9D84A5EF475B__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #define ST_KILL 20000
- #define ST_DEAD (ST_KILL+1)
- class CSprite
- {
- public:
- void Destroy();
- const long& GetType();
- RECT GetBoundingRect(POINT& ptLoc);
- void SetAnimBiDir(bool bIsAnimBiDir = true);
- long m_nID; // Used to uniquely identify each sprite in the game.
- long m_nPoints;
- void EnableBorder(bool bDraw = false);
- long& GetState();
- void MoveTo(long nX, long nY);
- RECT GetRect();
- void Draw(LPDIRECTDRAWSURFACE7 pdds);
- void Update();
- void MoveTo(POINT ptNewLoc);
- void SetState(long nState, bool bForceState = false);
- bool IsHit(RECT rcRect);
- void AddState(long nState, POINT ptFrame, long nNoOfFrames, long nDelay, RECT* prcBound = NULL,LPTSTR pszSound = NULL, bool bLoopSound = false );
- void CreateSprite(CSurface** pSurface, long nType, long nHeight, long nWidth);
- CSprite();
- virtual ~CSprite();
-
- struct SMovement {
- long m_dx,m_dy;
- long m_nMoveDelay;
- long m_nCurrMoveDelay;
- bool (*m_pfnCollision)(RECT& rcRect);
- long m_nInvulnerable;
- long m_nPathFindDelay;
- long m_nCurrPathFindDelay;
- void (*m_pfnFindPath)(CSprite* pSprite);
-
- SMovement():m_pfnFindPath(0),
- m_dx(0), m_dy(0),
- m_pfnCollision(0),
- m_nCurrMoveDelay(0),
- m_nCurrPathFindDelay(0),
- m_nPathFindDelay(0),
- m_nMoveDelay(0),m_nInvulnerable(0) {}
- } m_Movement;
- POINT m_ptLocation;
- void (*m_pfnDead)(CSprite* pSprite);
- // This function is called before Kill state is set
- // if this function return false, then KILL state is
- // not set.
- bool (*m_pfnKill)(CSprite* pSprite);
-
-
- protected:
- bool m_bDrawBorder;
- CSurface** m_ppSurface; // This surface contains all the sprites.
- long m_nType;
- struct SSTATE {
- long m_nState;
- POINT m_ptFirstFrame;
- long m_nNoOfFrames;
- long m_nDelay;
- RECT m_rcBounding; // Rect used for Collision detection
- CSound* m_pSound;
- bool m_bLoopSound;
- inline bool operator==(const long& nState);
- } m_CurrState;
- struct SAnim {
- bool m_bIsAnimBiDir; // Sprites are animated from frames 0 to n then n to 0
- bool m_bIsAnimForward; // The direction of the current animation
-
- long m_nCurrDelay;
- long m_nCurrFrame;
- long m_nHeight;
- long m_nWidth;
-
- } m_Anim;
-
- std::list<SSTATE> m_StateList;
- };
- #endif // !defined(AFX_SPRITE_H__C64EA3C5_9B4C_4633_8C96_9D84A5EF475B__INCLUDED_)