📄 cgraph.cpp
字号:
m_adwSurfaceColorKey[6]=RGB(255,0,255);
m_adwSurfaceColorKey[7]=RGB(255,0,255);
m_adwSurfaceColorKey[8]=RGB(0,0,0);
m_adwSurfaceColorKey[9]=RGB(255,0,255);
m_adwSurfaceColorKey[10]=RGB(255,0,255);
}
//-----------------------------------------------------------------------------------
//显示动态图块
//-----------------------------------------------------------------------------------
void CMapSurface::ShowAniTileToAniSurface()
{
RECT rect;
for(DWORD i=0;i<m_dwTileAniCount;i++)
{
if(timeGetTime()-m_aTileAni[i].dwOldTime > m_aTileAni[i].dwDelay)
{
m_aTileAni[i].dwOldTime=timeGetTime();
::SetRect(&rect,
m_aTileAni[i].pPos[m_aTileAni[i].dwCurrentFrame].x<<5,
m_aTileAni[i].pPos[m_aTileAni[i].dwCurrentFrame].y<<5,
(m_aTileAni[i].pPos[m_aTileAni[i].dwCurrentFrame].x+1)<<5,
(m_aTileAni[i].pPos[m_aTileAni[i].dwCurrentFrame].y+1)<<5);
m_aSurface[10]->BltFast((i%20)<<5,
(i/20)<<5,
m_aSurface[ m_aTileAni[i].dwPicID],
&rect,true);
m_aTileAni[i].dwCurrentFrame++;
if(m_aTileAni[i].dwCurrentFrame>=m_aTileAni[i].dwFrames)
m_aTileAni[i].dwCurrentFrame=0;
}
}
}
//-----------------------------------------------------------------------------------
//初始化表面
//-----------------------------------------------------------------------------------
BOOL CMapSurface::InitSurface(const char*szAniFile)
{
LOA_ASSERT(szAniFile);
SetSurfaceValue();
char szBmpFile[1024];
if(FAILED(m_pDisplay->CreateSurfaceFromBitmap(&m_pSurfShadow,"pic\\shadow.bmp",0,0)))
{
m_pLog->WriteMessage("Create Role Shadow Surface From pic\\shadow.bmp Failed!");
return false;
}
m_pSurfShadow->SetColorKey(RGB(255,255,255));
for(DWORD i=0;i<10;i++)
{
memset(szBmpFile,0,1024);
wsprintf(szBmpFile,"tiles\\tile%d.bmp",i);
if(FAILED(m_pDisplay->CreateSurfaceFromBitmap(&m_aSurface[i],
szBmpFile,
0,//m_adwSurfaceWidth[i],
0)))//m_adwSurfaceHeight[i])))
{
m_pLog->WriteMessage("Create Surface(%d) from File<%s> Failed!\n",i,szBmpFile);
return false;
}
m_aSurface[i]->SetColorKey(m_adwSurfaceColorKey[i]);
}
if(FAILED(m_pDisplay->CreateSurface(&m_aSurface[10],
m_adwSurfaceWidth[10],
m_adwSurfaceHeight[10])))
{
m_pLog->WriteMessage("Create Surface(10) (AniSurface) Failed!\n");
return false;
}
m_aSurface[10]->SetColorKey(m_adwSurfaceColorKey[10]);
m_dwTileAniCount=::GetPrivateProfileInt("ani","count",0,szAniFile);
m_pLog->WriteMessage("Get Map Ani Tile Count=%d From<%s>\n",m_dwTileAniCount,szAniFile);
if(m_dwTileAniCount==0)
return true;
m_aTileAni=new STTileAni[m_dwTileAniCount];
if(!m_aTileAni)
{
m_pLog->WriteMessage("New Tile Ani Failed!\n");
return false;
}
int k,n;
char szAppName[256];
char szPosition[1024];
for(i=0;i<m_dwTileAniCount;i++)
{
memset(szAppName,0,256);
wsprintf(szAppName,"tile%d",i+1);
m_aTileAni[i].dwDelay=::GetPrivateProfileInt(szAppName,"delay",200,szAniFile);
m_aTileAni[i].dwFrames=::GetPrivateProfileInt(szAppName,"frames",0,szAniFile);
m_aTileAni[i].dwPicID=::GetPrivateProfileInt(szAppName,"picid",0,szAniFile);
m_aTileAni[i].dwCurrentFrame=0;
m_aTileAni[i].dwOldTime=0;
m_aTileAni[i].pPos=new POINT[m_aTileAni[i].dwFrames];
if(!m_aTileAni[i].pPos)
{
m_pLog->WriteMessage("New Tile Ani Position Failed!\n");
return false;
}
memset(szPosition,0,1024);
::GetPrivateProfileString(szAppName,"posx","",szPosition,1024,szAniFile);
for(DWORD j=0;j<m_aTileAni[i].dwFrames;j++)
{
m_aTileAni[i].pPos[j].x=0;
m_aTileAni[i].pPos[j].y=0;
}
k=0;
n=0;
char tmp[32];
while(szPosition[k])
{
j=0;
memset(tmp,0,32);
while(szPosition[k]!=',' && szPosition[k]!='\0')
{
tmp[j++]=szPosition[k];
k++;
}
if(tmp[j]==',')
tmp[j]='\0';
k++;
sscanf(tmp,"%d",&m_aTileAni[i].pPos[n].x);
n++;
}
memset(szPosition,0,1024);
::GetPrivateProfileString(szAppName,"posy","",szPosition,1024,szAniFile);
k=0;
n=0;
while(szPosition[k])
{
j=0;
memset(tmp,0,32);
while(szPosition[k]!=',' && szPosition[k]!='\0')
{
tmp[j++]=szPosition[k];
k++;
}
if(tmp[j]==',')
tmp[j]='\0';
k++;
sscanf(tmp,"%d",&m_aTileAni[i].pPos[n].y);
n++;
}
}
m_pLog->WriteMessage("Init Surface...OK!\n");
m_bSurfCreated=true;
return true;
}
BOOL CMapSurface::Init(CDisplay*pDisplay,CLog*pLog)
{
LOA_ASSERT(pDisplay);
LOA_ASSERT(pLog);
m_pDisplay=pDisplay;
m_pLog=pLog;
if(m_bSurfCreated)
return true;
return InitSurface("tiles\\ani.ini");
}
/////////////////////////////////////////////////////////////////////////////////////////
CRenderMap::CRenderMap():CRenderTask()
{
m_pDisplay=NULL;
m_pMapSurf=NULL;
m_pSurfGround=NULL;
m_xStart=0;
m_yStart=0;
m_bShowMap=true;
m_bSurfCreated=false;
}
CRenderMap::~CRenderMap()
{
Release();
}
void CRenderMap::ShowMap(BOOL bShow)
{
m_bShowMap=bShow;
}
BOOL CRenderMap::InitRender(CDisplay*pDisplay,CMapSurface*pMapSurf,CMap*pMap)
{
LOA_ASSERT(pDisplay);
LOA_ASSERT(pMapSurf);
LOA_ASSERT(pMap);
m_bShowMap=true;
m_pDisplay=pDisplay;
m_pMap=pMap;
m_pMapSurf=pMapSurf;
if(!m_bSurfCreated)
{
if(FAILED(m_pDisplay->CreateSurface(&m_pSurfGround,672,512)))
return false;
m_bSurfCreated=true;
m_pSurfGround->SetColorKey(RGB(255,0,255));
}
m_pSurfGround->Clear(RGB(255,0,255));
RECT rect;
::SetRect(&rect,m_pMap->m_head.xGround<<5,
m_pMap->m_head.yGround<<5,
(m_pMap->m_head.xGround+1)<<5,
(m_pMap->m_head.yGround+1)<<5);
for(int i=0;i<21;i++)
{
for(int j=0;j<16;j++)
{
m_pSurfGround->BltFast(i<<5,j<<5,m_pMapSurf->m_aSurface[m_pMap->m_head.groundID]->GetDDrawSurface(),&rect,true);
}
}
return true;
}
void CRenderMap::ShowGround()
{
int left=m_xStart%32;
int top=m_yStart%32;
RECT rect={left,top,left+640,top+480};
m_pDisplay->ColorKeyBlt(0,0,m_pSurfGround->GetDDrawSurface(),&rect);
}
void CRenderMap::ShowObj()
{
RECT rect;
DWORD beginX=m_xStart>>5;
DWORD endX=beginX+21;
if(endX>(DWORD)m_pMap->m_head.Width)
endX=m_pMap->m_head.Width;
DWORD beginY=m_yStart>>5;
DWORD endY=beginY+16;
if(endY>(DWORD)m_pMap->m_head.Height)
endY=m_pMap->m_head.Height;
int x=-((int)m_xStart % 32);
int y=-((int)m_yStart % 32);
DWORD oldy=y;
for(DWORD i=beginX;i<endX;i++)
{
y=oldy;
for(DWORD j=beginY;j<endY;j++)
{
if(m_pMap->m_ppTile[i][j].IDObj_1!=255)
{
::SetRect(&rect,((DWORD)(m_pMap->m_ppTile[i][j].xObj_1))<<5,
((DWORD)(m_pMap->m_ppTile[i][j].yObj_1))<<5,
((DWORD)(m_pMap->m_ppTile[i][j].xObj_1)+1)<<5,
((DWORD)(m_pMap->m_ppTile[i][j].yObj_1)+1)<<5);
m_pDisplay->ColorKeyBlt(x,y,
m_pMapSurf->m_aSurface[m_pMap->m_ppTile[i][j].IDObj_1]->GetDDrawSurface(),
&rect);
}
if(m_pMap->m_ppTile[i][j].IDObj_2!=255)
{
::SetRect(&rect,((DWORD)(m_pMap->m_ppTile[i][j].xObj_2))<<5,
((DWORD)(m_pMap->m_ppTile[i][j].yObj_2))<<5,
((DWORD)(m_pMap->m_ppTile[i][j].xObj_2)+1)<<5,
((DWORD)(m_pMap->m_ppTile[i][j].yObj_2)+1)<<5);
m_pDisplay->ColorKeyBlt(x,y,
m_pMapSurf->m_aSurface[m_pMap->m_ppTile[i][j].IDObj_2]->GetDDrawSurface(),
&rect);
}
y+=32;
}
x+=32;
}
}
BOOL LOA_RENDER_API CRenderMap::IsRenderComplete()
{
return false;
}
void LOA_RENDER_API CRenderMap::Release()
{
if(m_pSurfGround)
{
delete m_pSurfGround;
m_pSurfGround=NULL;
}
}
void LOA_RENDER_API CRenderMap::Render()
{
if(!m_bShowMap)
return;
ShowGround();
ShowObj();
}
////////////////////////////////////////////////////////////////////////////////////////////////
CRenderRoleHeadPic::CRenderRoleHeadPic()
{
m_pDisplay=NULL;
m_pRole=NULL;
m_bEnd=true;
}
CRenderRoleHeadPic::~CRenderRoleHeadPic()
{
}
BOOL CRenderRoleHeadPic::InitRender(int x,int y,CDisplay*pDisplay,STRenderRole*pRole)
{
if(!pRole->pGraph->pSurfHead)
return false;
DDSURFACEDESC2 ddsd;
ddsd=pRole->pGraph->pSurfHead->GetDDSurfaceDesc();
m_pRole=pRole;
m_pDisplay=pDisplay;
m_x=x;
m_y=y;
m_x-=ddsd.dwWidth;
if(m_x<0)
m_x=0;
m_y-=ddsd.dwHeight;
if(m_y<0)
m_y=0;
m_bEnd=false;
return true;
}
void CRenderRoleHeadPic::EndRender()
{
m_bEnd=true;
}
void LOA_RENDER_API CRenderRoleHeadPic::Release()
{
}
void LOA_RENDER_API CRenderRoleHeadPic::Render()
{
m_pDisplay->ColorKeyBlt(m_x,m_y,m_pRole->pGraph->pSurfHead->GetDDrawSurface());
}
BOOL LOA_RENDER_API CRenderRoleHeadPic::IsRenderComplete()
{
return m_bEnd;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CRenderRoleState::InitRender(CDisplay*pDisplay,STRenderRole*pRole)
{
LOA_ASSERT(pDisplay);
LOA_ASSERT(pRole);
m_pDisplay=pDisplay;
m_pRole=pRole;
m_pFont=new CFont;
if(!m_pFont)
return false;
if(!m_pFont->CreateFont())
return false;
return true;
}
void LOA_RENDER_API CRenderRoleState::Release()
{
if(m_pFont)
{
delete m_pFont;
m_pFont=NULL;
}
}
void LOA_RENDER_API CRenderRoleState::Render()
{
m_pDisplay->ColorKeyBlt(30,100,m_pRole->pGraph->pSurfHead->GetDDrawSurface());
HDC hdc;
char str[256];
m_pDisplay->GetBackBuffer()->GetDC(&hdc);
::SelectObject(hdc,m_pFont->GetFont());
::SetBkMode(hdc,TRANSPARENT);
::SetTextColor(hdc,RGB(0,0,255));
wsprintf(str,"亚特 Level:%d",m_pRole->pRole->Level);
::TextOut(hdc,30,300,str,strlen(str));
wsprintf(str,"HP:%d/%d",m_pRole->pRole->Hp,m_pRole->pRole->MaxHp);
::TextOut(hdc,40,330,str,strlen(str));
wsprintf(str,"MP:%d/%d",m_pRole->pRole->Mp,m_pRole->pRole->MaxMp);
::TextOut(hdc,40,350,str,strlen(str));
wsprintf(str,"EXP:%d/%d",m_pRole->pRole->Exp,m_pRole->pRole->MaxExp);
::TextOut(hdc,40,370,str,strlen(str));
::SetTextColor(hdc,RGB(255,0,0));
wsprintf(str,"总攻击力:%d",m_pRole->pRole->Attack);
::TextOut(hdc,460,120,str,strlen(str));
wsprintf(str,"武器攻击力:%d",m_pRole->pRole->WeaponAttack);
::TextOut(hdc,460,140,str,strlen(str));
wsprintf(str,"武器等级:%d",m_pRole->pRole->WeaponLevel);
::TextOut(hdc,460,160,str,strlen(str));
wsprintf(str,"武器经验值:");
::TextOut(hdc,460,180,str,strlen(str));
wsprintf(str,"%d/%d",m_pRole->pRole->WeaponExp,m_pRole->pRole->WeaponMaxExp);
::TextOut(hdc,460,200,str,strlen(str));
wsprintf(str,"总防御力:%d",m_pRole->pRole->Defend);
::TextOut(hdc,460,220,str,strlen(str));
wsprintf(str,"防具防御力:%d",m_pRole->pRole->DefendDefend);
::TextOut(hdc,460,240,str,strlen(str));
wsprintf(str,"防具等级:%d",m_pRole->pRole->DefendLevel);
::TextOut(hdc,460,260,str,strlen(str));
wsprintf(str,"防具经验值:");
::TextOut(hdc,460,280,str,strlen(str));
wsprintf(str,"%d/%d",m_pRole->pRole->DefendExp,m_pRole->pRole->DefendMaxExp);
::TextOut(hdc,460,300,str,strlen(str));
::SetTextColor(hdc,RGB(0,0,255));
wsprintf(str,"敏捷度:%d",m_pRole->pRole->Smart);
::TextOut(hdc,460,330,str,strlen(str));
wsprintf(str,"金钱:%d",m_pRole->pRole->Money);
::TextOut(hdc,460,350,str,strlen(str));
m_pDisplay->GetBackBuffer()->ReleaseDC(hdc);
}
BOOL LOA_RENDER_API CRenderRoleState::IsRenderComplete()
{
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -