⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sprite.h

📁 Visual C++游戏开发技术与实例一书配套光盘。包含了冒险屠宰场、入侵者、赛车、网络五子棋、网络台球、对战坦克大战和面包圈7个游戏实例的完整源代码。
💻 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;
			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_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -