?? role.cpp
字號:
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 + -