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

📄 cgame.h

📁 一个个人开发的rpg游戏<亚特兰蒂斯传奇>的源码
💻 H
字号:
//主游戏引擎类,几乎天天都在修改
//作者:吴振华(kylinx)(中国科大01级11系)
//E-mail:game-diy@163.com
//Created 2003/6/19 by Kylinx
#ifndef LOA_GAME_H_
#define LOA_GAME_H_
#include<windows.h>
#define LOA_GAME_INFO				"Legend of atlantis"
#define LOA_GAME_VERSION_MAJOR		1
#define LOA_GAME_VERSION_MINOR		0
//---------------------------------------------------------------------------------------------------------------
#define UM_SETGAME			WM_USER+0x100					//自己定义的消息
//---------------------------------------------------------------------------------------------------------------
#define LOA_GAME_STATE_NORMAL					0			//游戏状态——正常
#define LOA_GAME_STATE_TALKING					1			//游戏状态——交谈
#define LOA_GAME_STATE_SCRIPT_CONTROL			2			//游戏状态——脚本控制
#define LOA_GAME_STATE_BATTLE					3			//游戏状态——战斗
#define LOA_GAME_STATE_MENU						4			//游戏状态——菜单循环
#define LOA_GAME_STATE_LOGO						5			//游戏状态----显示LOGO
#define LOA_GAME_STATE_MAIN_MENU				6
#define LOA_GAME_STATE_CREDITS					10
//---------------------------------------------------------------------------------------------------------------
#include"dxlib\\dsutil.h"
#include"dxlib\\ddutil.h"
#include"dxlib\\diutil.h"
#include"dxlib\\kldshow.h"
#include"CRole.h"
#include"CRender.h"
#include"klds.h"
#include"CDataBase.h"
#include"CMap.h"
#include"CMagic.h"
#include"CGoods.h"
#include"CEffect.h"

class CGameData;											//游戏数据类
class CLog;													//日志类声明
class CRoleGraph;											//角色图像
class KGDTaskQueue;											//任务队列类
class CMessage;												//消息类
class CRole;												//角色类
class CScriptData;											//脚本数据类
class CScript;												//脚本类
class CMap;													//地图类
class CRenderMap;											//渲染地图类
class CMapSurface;											//地图表面
class CRenderRole;											//渲染角色
class CDirectInputMouse;									
struct STRenderRole;			
				
class CBattle;	

struct STGameInfo
{
	BOOL bFilled;
	char szInfo[32];
	int iVersionMajor;
	int iVersionMinor;
	SYSTEMTIME stTime;
	int bmpWidth;
	int bmpHeight;
	void*bmpData;
	int nLevel;
	char szMapName[32];
	char szCurrentMapName[128];

	STGameInfo()
	{
		bFilled=false;
		memset(szInfo,0,32);
		memset(szMapName,0,32);
		memset(szCurrentMapName,0,128);
		bmpData=NULL;
	}
};
class CGame
{
	HWND					m_hWnd;							//窗口句柄

	IDataBase<STChangeMapData>	*m_pdbChangeMap;				//切换地图的数据库
	IDataBase<STMagic>			*m_pdbMagic;					//魔法数据库
	IDataBase<STGood>			*m_pdbGoods;					//物品数据库
//	IDataBase		*m_pdbBattleRole;				//战斗角色数据库
	IDataBase<STLoadScriptData>	*m_pdbLoadScript;				//读取脚本数据库
	IDataBase<STEffect>			*m_pdbEffect;
	CLog					*m_pLog;						//日志

	CSoundManager			*m_pSoundPlayer;				//管理声音的对象
	KGDShow					*m_pDShow;						//DirectShow
	CDirectInputKeyBoard	*m_pKeyBoard;					//DirectInput
	CDirectInputMouse		*m_pMouse;						//DirectInput---Mouse
	CDisplay				*m_pDisplay;					//显示
	CGameData				*m_pGameData;					//游戏数据
	
	STRenderRole			*m_pMapRole;
	STRenderRole			*m_pPlayer;						//地图上的主角 
	STRenderRole			*m_pPlayerSave;
	KGDList<STRenderRole*>	*m_pNpcList;					//NPC链表

	KGDStack<POINT>			*m_pRoleBlock;					//角色障碍

	CRoleGraph				*m_pRoleGraph;					//角色图形数据

	CScriptData				*m_pScriptData;					//脚本事件数据
	CRenderRole				*m_pRenderRole;
	CLagQueue<STRenderRole*>*m_pRoleQueue;					//角色滞后队列(优先级高的排后面)
	CMapSurface				*m_pMapSurface;					//地图表面
	CRenderMap				*m_pRenderMap;					//显示地图
	CMap					*m_pMap;						//游戏地图
	CMessage				*m_pMsg;						//游戏消息(核心中的核心)
	CRender					*m_pRender;						//渲染场景的任务队列(流水线)
	
	CBattle					*m_pBattle;
	
	CSurface				*m_pSurfScene;

//	KGDStack<int>			*m_pStateStack;
	int						m_nCurrentGameState;			//当前游戏状态
	int						m_nCurrentSaveFileIndex;
	static char				s_szCurrentDir[1024];

	char					m_szCurrentMusicFile[128];
	char					m_szCurrentMapName[128];		//当前地图名字
	char					m_szCurrentRoleIniName[128];	//当前角色配置文件名
private:
	BOOL CreateDisplayMode(BOOL bWindowed);					//创建显示模式(窗口或者全屏幕)
	BOOL m_bActive;											//是否激活
	BOOL m_bPlayGame;										//是否游戏结束
	BOOL m_bIsNight;										//是否是晚上
	BOOL m_bShowMap;										//是否显示地图
	BOOL m_bShowFPS;										//是否显示FPS
	BOOL m_bRandomBattle;									//是否随机战斗
	BOOL m_bDitherScreen;									//是否抖动屏幕
	BOOL m_bScriptControlling;
	int m_nBattleFrequency;									//遇敌频率
	static LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
public:
	static char* GetAbsolutePath(char*szRelativePath);		//得到绝对路径
	CGame();
	virtual ~CGame();
public:
	

	BOOL InitGameDataBase();								//初始化游戏数据库
	BOOL InitDxlib(HINSTANCE hInstance);					//初始化DirectX库
	BOOL InitRoleGraphData(char*szFile);					//初始化图形数据

	void QuitGame(int ExitCode);
	
	void Release();
	void UpdateScreen();

	int NormalStateLoop();									//游戏状态——正常状态下的循环
	int BattleStateLoop();									//战斗状态的循环
	int MainLoop();
	int LogoLoop();
	int ShowCreditsLoop();

	void SetRoleBlock();
	void ClearRoleBlock();
	
	void ShowFPS();
	void LockFPS();

	void SetCurrentSaveFileIndex(int index){m_nCurrentSaveFileIndex=index;}
	void SetCurrentMap(char*str){strncpy(m_szCurrentMapName,str,128);}

	BOOL ExecuteScript(char*szFile);
	BOOL ExecuteScript(int id);

	BOOL SaveGame(int index);
	BOOL LoadGame(int index);
	BOOL GetSaveFileInfo(int index,STGameInfo*info);
	BOOL GetSaveFileHeadInfo(int index,STGameInfo*info);

	BOOL ScreenShot();

	void FadeIn();
	void FadeInRestore();
	void FadeOut();
	void FadeOutRestore();
	void ClearScreen();
	BOOL IsDither(){return m_bDitherScreen;}
	void SetDither(BOOL bDither){m_bDitherScreen=bDither;}
	BOOL IsNight(){return m_bIsNight;}
	BOOL IsRandomBattle(){return m_bRandomBattle;}
	void SetRandomBattle(BOOL bRndBattle){m_bRandomBattle=bRndBattle;}
	void SetNight();
	void SetDay(){m_bIsNight=false;m_pDisplay->RestoreGamma();}
	void SetGray(BOOL bGray){m_pDisplay->SetGray(bGray);}
	void ScrollScreenTo(int TileX,int TileY);
	void ScrollScreenToPlayer();
	void ScrollScreenToNpc(int ID);

	int ShowBeginMenu();
	BOOL ShowStaticPictureWithMessage(char*szJPEG,char*str);

	int ShowShop(char*szFile,char*szSegment);

	inline int GetBattleFrequency(){return m_nBattleFrequency;}
	inline void SetBattleFrequency(int freq){m_nBattleFrequency=freq;}
 	inline void SetState(int state){m_nCurrentGameState=state;}
	inline int GetState(){return m_nCurrentGameState;}

	BOOL RandomEnemy(CRole*pRole);
public:

	void NpcRandomMove();									//NPC随机移动
	void SortAndShowRole();									//对所有角色排序并显示出来
	void ComputeMapStartPos();
	void MsgBox(char*str,...);								//消息框
	BOOL LoadMap(char*szFile);								//读取地图
	BOOL LoadMap(int ID);
	
	BOOL LoadRole(char*szFile,char*szSection,STRenderRole**ppRole);//读取角色

	BOOL AddPlayer(CRole*pRole);
	BOOL AddPlayer(char*szName,int x,int y);
	BOOL AddPlayerWithIniData(char*szFile,char*szSection);
	BOOL AddNpc(CRole*pNpc);
	BOOL AddNpc(char*szRoleName,char*szNameInGame,int nIDInGame,int x,int y);
	BOOL DelNpc(int nIDInGame);
	int Delay(DWORD dwDelay);
	void SetMapRole(STRenderRole*pRole){m_pMapRole=pRole;}
public:
	int  WaitMediaPlayOK(BOOL bBreakIfPressKey=true);		//等待媒体播放完成
	BOOL PlayMedia(char*szFile,BOOL bLoop=true,BOOL bWait=false,BOOL bBreakIfPressKey=true);//播放媒体
	BOOL PauseMedia();
	BOOL ResumeMedia();

	BOOL RandomBattle();
	BOOL BossBattle(char*szBattleMap,char*szBattleMusic,char*szBossGraphIni,char*szBossRoleIni,char*szBossRoleSegment,BOOL bNeedWin);

	inline CRenderMap*GetRenderMap(){return m_pRenderMap;}
	inline char* GetCurrentMusicFile(){return m_szCurrentMusicFile;}
	inline CMapSurface*GetMapSurface(){return m_pMapSurface;}
	inline BOOL IsPlayGame(){return m_bPlayGame;}
	inline IDataBase<STEffect>*GetEffectDataBase(){return m_pdbEffect;}
	inline IDataBase<STLoadScriptData>*GetLoadScriptDataBase(){return m_pdbLoadScript;}
	inline IDataBase<STMagic>*GetMagicDataBase(){return m_pdbMagic;}
	inline IDataBase<STGood>*GetGoodsDataBase(){return m_pdbGoods;}
	inline IDataBase<STChangeMapData>*GetChangeMapDataBase(){return m_pdbChangeMap;}
	inline void SetPlayer(STRenderRole*pRole){m_pPlayer=pRole;}//设置地图主角
	inline KGDList<STRenderRole*> *GetNpcList(){return m_pNpcList;}//得到NPC链表
	inline HWND	GetHWnd(){return m_hWnd;}					//得到窗口句柄
	inline CLog*   GetLog(){return m_pLog;}					//得到日志
	inline CMap*	GetMap(){return m_pMap;}				//得到地图数据
	inline CScriptData*GetScriptData(){return m_pScriptData;}//得到脚本数据
	inline STRenderRole*GetPlayer(){return m_pPlayer;}		//得到地图主角
	inline CMessage* GetMessageQueue(){return m_pMsg;}		//得到消息队列
	inline CDisplay* GetDisplay() {return m_pDisplay;}		//得到CDisplay
	inline CSoundManager*GetSoundPlayer(){return m_pSoundPlayer;}//得到播放dsound
	inline CRender*GetRender() {return m_pRender;}			//得到渲染队列
	inline CDirectInputKeyBoard*GetKeyBoard(){return m_pKeyBoard;}
	inline CDirectInputMouse*GetMouse(){return m_pMouse;}
	inline BOOL IsActive() {return m_bActive;}

};
#endif

⌨️ 快捷键说明

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