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

📄 role.cpp

📁 成熟的RPG引擎,Flysky发布. 斜视角引擎.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	return ret;
}

//=====================
//动态Role处理
//=====================
bool CRole::DRole(int ID)
{
	if(rl[ID].move==true)
	{
		if(rl[ID].PathCSteps<rl[ID].PathSteps)
		{
			if (rl[ID].Path[rl[ID].PathCSteps].x>=0&&rl[ID].Path[rl[ID].PathCSteps].y>=0&&
				rl[ID].Path[rl[ID].PathCSteps].x<Map->Width&&
				rl[ID].Path[rl[ID].PathCSteps].x<Map->Height)
			{
				if (rl[ID].facejd!=false)rl[ID].facej++;
				#ifdef _AStarD
				if ((rl[ID].Path[rl[ID].PathCSteps].x-rl[ID].x)<0&&(rl[ID].Path[rl[ID].PathCSteps].y-rl[ID].y)>0) rl[ID].face=LDFace;
				else if ((rl[ID].Path[rl[ID].PathCSteps].x-rl[ID].x)>0&&(rl[ID].Path[rl[ID].PathCSteps].y-rl[ID].y)>0) rl[ID].face=RDFace;
				else if ((rl[ID].Path[rl[ID].PathCSteps].x-rl[ID].x)<0&&(rl[ID].Path[rl[ID].PathCSteps].y-rl[ID].y)<0) rl[ID].face=LUFace;
				else if ((rl[ID].Path[rl[ID].PathCSteps].x-rl[ID].x)>0&&(rl[ID].Path[rl[ID].PathCSteps].y-rl[ID].y)<0) rl[ID].face=RUFace;
				else if ((rl[ID].Path[rl[ID].PathCSteps].x-rl[ID].x)>0) rl[ID].face=RightFace;
				#else
				if ((rl[ID].Path[rl[ID].PathCSteps].x-rl[ID].x)>0) rl[ID].face=RightFace;
				#endif
				else if ((rl[ID].Path[rl[ID].PathCSteps].x-rl[ID].x)<0) rl[ID].face=LeftFace;
				else if ((rl[ID].Path[rl[ID].PathCSteps].y-rl[ID].y)>0) rl[ID].face=DownFace;
				else if ((rl[ID].Path[rl[ID].PathCSteps].y-rl[ID].y)<0) rl[ID].face=UpFace;
				//更新旧的
				rl[ID].oldx=rl[ID].x;
				rl[ID].oldy=rl[ID].y;

				//刷新坐标
				Map->CBlockOn(false,rl[ID].x,rl[ID].y); //取消障碍
				rl[ID].x=rl[ID].Path[rl[ID].PathCSteps].x;
				rl[ID].y=rl[ID].Path[rl[ID].PathCSteps].y;
				Map->CBlockOn(true,rl[ID].x,rl[ID].y); //加上障碍
			}
			if (!actor.empty())
			{
				if (ID==actor[0]) //如果这个是主角的话,不是镜头的那个,而是最前面的
				{
					if (Map->IsHook(rl[ID].x,rl[ID].y)==true) //十个陷阱
					{
	
					}
				}
			}
			rl[ID].PathCSteps++;
		}
		else
		{
			rl[ID].facej=0;
			rl[ID].PathCSteps=0;
			//如果
			if (rl[ID].WalkLoop!=true) {rl[ID].move=false;rl[ID].facejd=false;}
		}
		if (rl[ID].facej>3) rl[ID].facej=0;
		NPCZDS(ID);
		return true;
	}
	return false;
}

//==================================
//显示处理
//==================================
void CRole::NPCZDS(int rlID) //计算遮挡
{
	//NPC之后
	int ox,oy,tx,ty;
	MDToMI(rl[rlID].x,rl[rlID].y,tx,ty);
	rl[rlID].zd.clear();
	POINT pt; //临时坐标
	POINT tp=FindRoleP(rl[rlID].lpDDS_ROLEP);
	int py=rl[rlID].roler.left-rl[rlID].PicS.x;
	int px=rl[rlID].roler.right-rl[rlID].PicS.y;
	for (int t=tx-py;t<tx+TileWidth;t+=TileWidth) //为了加快速度 不是加一,而是加一个格子
	{
		for (int s=ty-py;s<ty+TileHeight;s+=TileHeight)
		{
			MIToMD(t,s,ox,oy);
			pt.x=ox+1;pt.y=oy;
			rl[rlID].zd.push_back(pt);//第一个
			pt.x=ox+1;pt.y=oy+1;
			rl[rlID].zd.push_back(pt);//第二个
			pt.x=ox;pt.y=oy+1;
			rl[rlID].zd.push_back(pt);//第三个
		}
	}
}

void CRole::Show(LPDIRECTDRAWSURFACE7 DDSurface) //全部显示
{
	int x1,y1;
	bool amove=false; //是否有人移动
	if (!RlFind.empty()) //如果索引表不是空的话
	{
		if (!actor.empty()) Map->SetStartXY(rl[actor[PRole]].x-PX,rl[actor[PRole]].y-PY); //如果不是空的,更改
		for (int i=0; i<int(RlFind.size());i++) //循环
		{
			//人物动态处理
			if (DRole(RlFind[i].ID)==true)
			{
				RlFind[i].value=rl[RlFind[i].ID].x+rl[RlFind[i].ID].y; //放到这,提高速度
				amove=true; //有人物移动了
			}
			//人物显示处理
			MDToMI(rl[RlFind[i].ID].x-Map->GetStartXY().x,rl[RlFind[i].ID].y-Map->GetStartXY().y,x1,y1);
			if (x1>=0&&y1>=0&&x1<ScreenWidth+rl[RlFind[i].ID].roler.right&&y1<ScreenHeight+rl[RlFind[i].ID].roler.bottom)
			{
				CreateRect(tmpr,rl[RlFind[i].ID].roler.right*rl[RlFind[i].ID].facej,
					rl[RlFind[i].ID].roler.bottom*rl[RlFind[i].ID].face,
					rl[RlFind[i].ID].roler.right*(rl[RlFind[i].ID].facej+1),
					rl[RlFind[i].ID].roler.bottom*(rl[RlFind[i].ID].face+1));
				BltFast(DDSurface,x1-rl[RlFind[i].ID].roler.left,y1-rl[RlFind[i].ID].roler.top,rl[RlFind[i].ID].lpDDS_ROLEP,&tmpr,SrcKey);
			}
			//人物对物品遮挡处理
			if (!rl[RlFind[i].ID].zd.empty()) for (int d=0;d<int(rl[RlFind[i].ID].zd.size());d++) {Map->ShowTile(2,rl[RlFind[i].ID].zd[d].x,rl[RlFind[i].ID].zd[d].y,DDSurface);} //展示遮挡
		}
		//人物对人物遮挡处理
		//主角1陷阱处理
		if (amove==true) TablePX();
		if (!actor.empty()) Map->SetStartXY(rl[actor[PRole]].x-PX,rl[actor[PRole]].y-PY); //如果不是空的,更改
	}

}

void CRole::CheckLoop(LPDIRECTDRAWSURFACE7 DDSurface){Show(DDSurface);}//显示NPC

//=========================================
//移动部分 Flysky
//=========================================
void CRole::AMoveTo(bool IsScreen,int x,int y,bool FindPath) //主角移动
{
	//X和Y为斜视角
	if (IsScreen==true) {x=x+Map->MapStartX;y=y+Map->MapStartY;} //如果是在屏幕里,直接加左上角坐标
	if (x<0) x=0;
	if (y<0) y=0;
	if (x>=Map->Width) x=Map->Width-1;
	if (y>=Map->Height) y=Map->Height-1;
	if (!actor.empty()) //不是空的才执行
	{
		POINT tpoint;
			if (FindPath==false)
			{
				if (Map->IsBlock(x,y)!=true)
				{
					for (int i=0;i<int(actor.size());i++)
					{
						if (i==0)
						{
							rl[actor[i]].move=true;
							rl[actor[i]].facejd=true; //脚动
							rl[actor[i]].WalkLoop=false; //不循环
							rl[actor[i]].PathSteps=1;rl[actor[i]].PathCSteps=0; //刷新
							rl[actor[i]].Path.clear(); //清空路径
							tpoint.x=x;
							tpoint.y=y;
							rl[actor[i]].Path.push_back(tpoint);
						}
						else
						{
							rl[actor[i]].move=true;
							rl[actor[i]].facejd=true; //脚动
							rl[actor[i]].WalkLoop=false; //不循环
							rl[actor[i]].PathSteps=1;rl[actor[i]].PathCSteps=0; //刷新
							rl[actor[i]].Path.clear(); //清空路径
							tpoint.x=rl[actor[i-1]].oldx;
							tpoint.y=rl[actor[i-1]].oldy;
							rl[actor[i]].Path.push_back(tpoint);
						}
					}
				}
				else //如果走不动,直接转向
				{
					for (int i=0;i<int(actor.size());i++)
					{
						#ifdef _AStarD
						if ((x-rl[actor[i]].x)<0&&(y-rl[actor[i]].y)>0) rl[actor[i]].face=LDFace;
						else if ((x-rl[actor[i]].x)>0&&(y-rl[actor[i]].y)>0) rl[actor[i]].face=RDFace;
						else if ((x-rl[actor[i]].x)<0&&(y-rl[actor[i]].y)<0) rl[actor[i]].face=LUFace;
						else if ((x-rl[actor[i]].x)>0&&(y-rl[actor[i]].y)<0) rl[actor[i]].face=RUFace;
						else if ((x-rl[actor[i]].x)>0) rl[actor[i]].face=RightFace;
						#else
						if ((x-rl[actor[i]].x)>0) rl[actor[i]].face=RightFace;
						#endif
						else if ((x-rl[actor[i]].x)<0) rl[actor[i]].face=LeftFace;
						else if ((y-rl[actor[i]].y)>0) rl[actor[i]].face=DownFace;
						else if ((y-rl[actor[i]].y)<0) rl[actor[i]].face=UpFace;
					}
				}
			}
			else if (FindPath==true)
			{
					if (x==rl[actor[0]].x&&y==rl[actor[0]].y) return;
					CFindPath cf(Map);
					if (cf.Find(rl[actor[0]].x,rl[actor[0]].y,x,y)!=true) return;
					if (cf.TheSteps==1&&Map->IsBlock(x,y)==true) 
					{
						for (int i=0;i<int(actor.size());i++)
						{
							#ifdef _AStarD
							if ((x-rl[actor[i]].x)<0&&(y-rl[actor[i]].y)>0) rl[actor[i]].face=LDFace;
							else if ((x-rl[actor[i]].x)>0&&(y-rl[actor[i]].y)>0) rl[actor[i]].face=RDFace;
							else if ((x-rl[actor[i]].x)<0&&(y-rl[actor[i]].y)<0) rl[actor[i]].face=LUFace;
							else if ((x-rl[actor[i]].x)>0&&(y-rl[actor[i]].y)<0) rl[actor[i]].face=RUFace;
							else if ((x-rl[actor[i]].x)>0) rl[actor[i]].face=RightFace;
							#else
							if ((x-rl[actor[i]].x)>0) rl[actor[i]].face=RightFace;
							#endif
							else if ((x-rl[actor[i]].x)<0) rl[actor[i]].face=LeftFace;
							else if ((y-rl[actor[i]].y)>0) rl[actor[i]].face=DownFace;
							else if ((y-rl[actor[i]].y)<0) rl[actor[i]].face=UpFace;
						}
						return;
					}
					rl[actor[0]].move=true;
					rl[actor[0]].facejd=true; //脚动
					rl[actor[0]].WalkLoop=false; //不循环
					rl[actor[0]].PathSteps=cf.TheSteps;
					rl[actor[0]].PathCSteps=0;
					rl[actor[0]].Path.clear(); //清空路径
					for(int i=0;i<cf.TheSteps;i++) rl[actor[0]].Path.push_back(cf.ThePath[i]);
					for (int i=1;i<int(actor.size());i++)
					{
						rl[actor[i]].move=true;
						rl[actor[i]].facejd=true; //脚动
						rl[actor[i]].WalkLoop=false; //不循环
						rl[actor[i]].PathSteps=cf.TheSteps;
						rl[actor[i]].PathCSteps=0;
						rl[actor[i]].Path.clear(); //清空
						if (rl[actor[i-1]].move)
						{
							if (cf.TheSteps>0) {tpoint.x=rl[actor[i-1]].oldx;tpoint.y=rl[actor[i-1]].oldy;rl[actor[i]].Path.push_back(tpoint);}
							if (cf.TheSteps>1) {tpoint.x=rl[actor[i-1]].x;tpoint.y=rl[actor[i-1]].y;rl[actor[i]].Path.push_back(tpoint);}
							if (cf.TheSteps>2) {for (int d=2;d<cf.TheSteps;d++) { rl[actor[i]].Path.push_back(rl[actor[i-1]].Path[d-2]);}}
						}
					}
			}
	}

}

void CRole::NMoveTo(bool IsScreen,int ID,int x,int y,bool FindPath,bool ChFace) //NPC移动
{
}

void CRole::NAMove(bool IsScreen,bool FT,int ID,int x,int y) //NPC自动走动
{
	if (x!=-1&&y!=-1&&(x<0||y<0||x>=Map->Width||y>=Map->Height)) return; //地图越界
	if (ID<0||ID>=int(npc.size())) return; //越标
	if (IsScreen==true) {x=x+Map->MapStartX;y=y+Map->MapStartY;} //如果是在屏幕里,直接加左上角坐标
	if (FT==true)
	{
		CFindPath cf(Map); //初始化A*算法
		if (cf.Find(rl[npc[ID]].x,rl[npc[ID]].y,x,y)!=true) return;
		rl[npc[ID]].move=true; //移动
		rl[npc[ID]].facejd=true; //脚动
		rl[npc[ID]].WalkLoop=true; //循环
		if (x!=-1&&y!=-1)
		{
			rl[npc[ID]].facej=0;
			rl[npc[ID]].PathCSteps=0;
			rl[npc[ID]].movex=x;rl[npc[ID]].movey=y; //更新移动值
		}
		rl[npc[ID]].PathSteps=cf.TheSteps<<1; //步数
		rl[npc[ID]].Path.clear();
		for (int t=0;t<cf.TheSteps;t++) //一半
		{
			rl[npc[ID]].Path.push_back(cf.ThePath[t]);
		}
		for (int i=0;i<cf.TheSteps;i++) //另一半
		{
			rl[npc[ID]].Path.push_back(cf.ThePath[cf.TheSteps-1-i]);
		}
	}
	else
	{
		rl[npc[ID]].PathSteps=0;
		rl[npc[ID]].facej=0;
		rl[npc[ID]].Path.clear();
		rl[npc[ID]].PathCSteps=0;
		rl[npc[ID]].WalkLoop=false; //循环
		rl[npc[ID]].facejd=false; //脚动
		rl[npc[ID]].move=false; //全部关闭
	}
}

//====================================
//关于坐标
//=====================================
POINT CRole::ActorXy(int ID) //获取主角坐标
{
	POINT tp={rl[actor[ID]].x,rl[actor[ID]].y}; //写入坐标
	return tp;
}
BOOL CRole::ActorXy(int ID,int &x,int &y) //获取主角坐标 引用
{
	if ((x=rl[actor[ID]].x)&&(y=rl[actor[ID]].y)) return TRUE;
	return FALSE;
}
POINT CRole::NpcXy(int ID) //获取NPC坐标
{
	POINT tp={rl[npc[ID]].x,rl[npc[ID]].y}; //写入坐标
	return tp;
}
BOOL CRole::NpcXy(int ID,int &x,int &y) //获取主角坐标 引用
{
	if ((x=rl[npc[ID]].x)&&(y=rl[npc[ID]].y)) return TRUE;
	return FALSE;
}
POINT CRole::RoleXy(int ID)
{
	POINT tp={rl[ID].x,rl[ID].y}; //写入坐标
	return tp;
}
BOOL CRole::RoleXy(int ID,int &x,int &y)
{
	if ((x=rl[ID].x)&&(y=rl[ID].y)) return TRUE;
	return FALSE;
}
//=================================
//脚本部分
//==================================
char * CRole::GetRoleScriptName()
{
	if (!rl.empty())
	{
		int value=-1;
		int ID=-1;
		if (rl[actor[0]].face==UpFace||rl[actor[0]].face==LeftFace)
		{
			value=rl[actor[0]].x+rl[actor[0]].y-1;
			vector <int> tmp=FindDataTV(value);
			for (int i=0;i<int(tmp.size());i++)
			{
				if (rl[tmp[i]].IsNPC==true)
				{
					if (rl[actor[0]].face==UpFace&&rl[tmp[i]].y==rl[actor[0]].y-1&&rl[tmp[i]].x==rl[actor[0]].x) ID=tmp[i];
					if (rl[actor[0]].face==LeftFace&&rl[tmp[i]].y==rl[actor[0]].y&&rl[tmp[i]].x==rl[actor[0]].x-1)ID=tmp[i];
				}
			}
		}
		else if (rl[actor[0]].face==DownFace||rl[actor[0]].face==RightFace)
		{
			value=rl[actor[0]].x+rl[actor[0]].y+1; 
			vector <int> tmp=FindDataTV(value);
			for (int i=0;i<int(tmp.size());i++)
			{
				if (rl[tmp[i]].IsNPC==true)
				{
					if (rl[actor[0]].face==DownFace&&rl[tmp[i]].y==rl[actor[0]].y+1&&rl[tmp[i]].x==rl[actor[0]].x) ID=tmp[i];
					if (rl[actor[0]].face==RightFace&&rl[tmp[i]].y==rl[actor[0]].y&&rl[tmp[i]].x==rl[actor[0]].x+1)ID=tmp[i];
				}
			}
		}
		if (ID!=-1) return rl[ID].EScrFName;
	}
	return NULL;
}

char * CRole::GetRoleScriptName(int x,int y)
{
	if (!rl.empty())
	{
		const int value=x+y;
		int ID=-1;
		vector <int> tmp=FindDataTV(value);
		for (int i=0;i<int(tmp.size());i++)
		{
			if (rl[tmp[i]].IsNPC==true&&rl[tmp[i]].x==x&&rl[tmp[i]].y==y) ID=tmp[i];
		}		
		if (ID!=-1) return rl[ID].EScrFName;
	}
	return NULL;
}

⌨️ 快捷键说明

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