cmagic.cpp
来自「一个个人开发的rpg游戏<亚特兰蒂斯传奇>的源码」· C++ 代码 · 共 182 行
CPP
182 行
//--------------------------------------------------------------------------------------------------------
// 游戏魔法模块
//CMagic.cpp
//游戏引擎中的魔法部分
//作者:吴振华(kylinx)(中国科大01级11系)
//E-mail:game-diy@163.com
//创建于:2003/6/24 by Kylinx
//--------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<ddraw.h>
#include"CMagic.h"
#include"CError.h"
#include"CGame.h"
#include"CText.h"
#include"CMacro.h"
#include"CFont.h"
////////////////////////////////////////////////////////////////////////////////////////////
//构造
////////////////////////////////////////////////////////////////////////////////////////////
CMagic::CMagic()
{
m_pMagic=NULL;
}
////////////////////////////////////////////////////////////////////////////////////////////
//析构
////////////////////////////////////////////////////////////////////////////////////////////
CMagic::~CMagic()
{
Release();
}
BOOL CMagic::InitMagic(CGame*pGame,STMagic*pMagic,int x,int y)
{
LOA_ASSERT(pGame);
LOA_ASSERT(pMagic);
m_pMagic=pMagic;
this->m_pDisplay=pGame->GetDisplay();
this->m_nCurrentFrame=0;
this->x=x;
this->y=y;
if(m_pMagic->pSound)
{
if(!m_pMagic->pSound->IsSoundPlaying())
m_pMagic->pSound->Play(0,0);
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////
//显示魔法
////////////////////////////////////////////////////////////////////////////////////////////
BOOL CMagic::ShowMagic(CGame*pGame,STMagic*pMagic,int x,int y,int nPriority)
{
LOA_ASSERT(pGame);
LOA_ASSERT(pMagic);
m_pMagic=pMagic;
this->m_pDisplay=pGame->GetDisplay();
this->m_nCurrentFrame=0;
this->x=x;
this->y=y;
this->CreateTask(true,true,nPriority);
if(m_pMagic->pSound)
{
if(!m_pMagic->pSound->IsSoundPlaying())
m_pMagic->pSound->Play(0,0);
}
if( pGame->GetRender()->AddTask(this))
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////////////////////
//执行显示魔法的任务
////////////////////////////////////////////////////////////////////////////////////////////
void LOA_RENDER_API CMagic::Render()
{
if(m_nCurrentFrame>=m_pMagic->nFrames)
return;
m_pDisplay->ColorKeyBlt(x,y,m_pMagic->pSurface->GetDDrawSurface(),
&m_pMagic->aRect[this->m_nCurrentFrame]);
if(timeGetTime()-m_pMagic->dwOldTime< m_pMagic->dwDelay)
return;
m_pMagic->dwOldTime=timeGetTime();
this->m_nCurrentFrame++;
return;
}
////////////////////////////////////////////////////////////////////////////////////////////
//检查魔法是否显示完成
////////////////////////////////////////////////////////////////////////////////////////////
BOOL LOA_RENDER_API CMagic::IsRenderComplete()
{
if(m_nCurrentFrame>=m_pMagic->nFrames)
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////////////////////
//释放
////////////////////////////////////////////////////////////////////////////////////////////
void LOA_RENDER_API CMagic::Release()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CRenderRoleMagic::SetRender(CDisplay*pDisplay,CFont*pFont,STMagic*pMagic)
{
LOA_ASSERT(pDisplay);
LOA_ASSERT(pFont);
m_pDisplay=pDisplay;
m_pFont=pFont;
m_pMagic=pMagic;
m_nCurrentMagicFrame=0;
m_dwOldTime=0;
m_bStopRender=false;
return true;
}
void CRenderRoleMagic::StopRender()
{
m_bStopRender=true;
}
void LOA_RENDER_API CRenderRoleMagic::Release()
{
}
void LOA_RENDER_API CRenderRoleMagic::Render()
{
if(m_bStopRender)
return;
CText text;
HDC hdc;
m_pDisplay->GetBackBuffer()->GetDC(&hdc);
::SetBkMode(hdc,TRANSPARENT);
::SetTextColor(hdc,RGB(0,255,0));
::SelectObject(hdc,m_pFont->GetFont());
if(m_pMagic)
{
text.ShowMultiLineText(380,260,hdc,20,m_pMagic->szIntroduce);
}
else
{
text.ShowMultiLineText(380,110,hdc,20,"没有任何魔法");
}
m_pDisplay->GetBackBuffer()->ReleaseDC(hdc);
if(m_pMagic)
{
RECT rtDest={372,100,545,205};
DDBLTFX ddbltfx;
ZeroMemory(&ddbltfx,sizeof(ddbltfx));
ddbltfx.dwSize=sizeof(ddbltfx);
m_pMagic->pSurface->GetDDrawSurface()->GetColorKey(0,&ddbltfx.ddckSrcColorkey);
m_pDisplay->GetBackBuffer()->Blt(&rtDest,m_pMagic->pSurface->GetDDrawSurface(),&m_pMagic->aRect[m_nCurrentMagicFrame],DDBLT_WAIT|DDBLT_KEYSRC,&ddbltfx);
if(timeGetTime()-m_dwOldTime > m_pMagic->dwDelay)
{
m_dwOldTime=timeGetTime();
m_nCurrentMagicFrame++;
if(m_nCurrentMagicFrame>=m_pMagic->nFrames)
{
m_nCurrentMagicFrame=0;
}
}
}
}
BOOL LOA_RENDER_API CRenderRoleMagic::IsRenderComplete()
{
return false;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?