📄 sprite.h
字号:
// 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; //第一帧图案在整个集合图像中的位置(x,y)
long m_nNoOfFrames; //帧的总数
long m_nDelay; //帧延时
RECT m_rcBounding; //碰撞检测用的包络矩形
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; //SSTATE 结构的列表
};
#endif // !defined(AFX_SPRITE_H__C64EA3C5_9B4C_4633_8C96_9D84A5EF475B__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -