texplode.cpp

来自「一个另类的坦克大战源程序」· C++ 代码 · 共 109 行

CPP
109
字号
// TExplode.cpp: implementation of the TExplode class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TExplode.h"
#include "TWorld.h"

EPG TExplode::m_epg[4];
ESound TExplode::m_sound[3];

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

TExplode::TExplode(int x,int y,EXPLODE nType)
:TObject(x,y,CLASS_TEXPLODE),m_nType(nType),m_nCurrentFrame(0)
{
	SetDelayTimer(100);
	switch(nType)
	{
	case EXPLODE_TANK:
	case EXPLODE_BOX:
		m_sound[0].Play();
		break;
	case EXPLODE_PLAYER:
		//玩家爆炸动画慢一点,与声音配合
		SetDelayTimer(200);
		m_sound[0].Play();
		break;
	}
}

TExplode::~TExplode()
{

}


///////////////////////////////////////////////
//移动
void TExplode::Move()
{
	if(!IsMyTime())
		return ;

	///////////////////////////////////////////
	//计算

	if(m_nType==EXPLODE_PLAYER)
	{
		//玩家爆炸应该壮烈一点
		if(m_nCurrentFrame >= m_epg[3].GetFrameCount()-1)
		{
			//先来一个小爆炸
			m_sound[1].Play();

			//然后变成大爆炸
			m_nType = EXPLODE_TANK;
			m_nCurrentFrame = 0;
			return ;
		}
	}else{
		
		//一般爆炸就可以了
		if(m_nCurrentFrame>=m_epg[m_nType].GetFrameCount()-1)
		{
			//爆炸消失
			Dead();
			return ;
		}
	}
	m_nCurrentFrame ++;
}


///////////////////////////////////////////////
//画出爆炸
void TExplode::Draw()
{
	POINT p;
	p.x = m_nX;
	p.y = m_nY;
	g_world.LPToDP(p);
	if(m_nType==EXPLODE_PLAYER)
	{
		WGE_Surface.Blt(m_epg[3],m_nCurrentFrame,
			p.x,p.y);
	}else
		WGE_Surface.Blt(m_epg[m_nType],
			m_nCurrentFrame,
			p.x,p.y );
}

////////////////////////////////////////////
//取得动画边框
void TExplode::GetRect(RECT& rc)
{
	int i;
	if(m_nType==EXPLODE_PLAYER)
		i = 3;
	else 
		i = m_nType;
	rc.left = m_nX - m_epg[i].GetFrame(m_nCurrentFrame)->m_nKeyX;
	rc.top = m_nY - m_epg[i].GetFrame(m_nCurrentFrame)->m_nKeyY;
	rc.bottom = rc.top + m_epg[i].GetFrame(m_nCurrentFrame)->m_dwHeight ;
	rc.right = rc.left + m_epg[i].GetFrame(m_nCurrentFrame)->m_dwWidth ;
}

⌨️ 快捷键说明

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