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

📄 weather.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	{
		CSand * sand = new CSand();
		m_Sand.push_back(sand);
	}
	int nSelfVolume = m_iSandAmount  *100 / _MAX_AMOUNT;
	if(nSelfVolume >140)
		nSelfVolume = 140;
	else
		if(nSelfVolume < 20)
			nSelfVolume = 20;
		DXPlaySound("sound/sand.wav",0,0,0,-1,nSelfVolume); 
		return TRUE;
}

//--------------------------------------------------------------
void CSandSys::Reset(void)
{
	m_iStatu = _SAND_BEGIN;
	m_iSandAmount	= 10;
	m_iTargetAmount = 10; 
	
	int nSelfVolume = m_iSandAmount * 4 *100 / _MAX_AMOUNT;
	if(nSelfVolume >140)
		nSelfVolume = 140;
	else
		if(nSelfVolume < 20)
			nSelfVolume = 20;
		DXSetVolume("sound/sand.wav",nSelfVolume,0,0); 
		
		for(DWORD i=0;i<m_Sand.size();i++)
			m_Sand[i]->Reset();
}

//--------------------------------------------------------------


void CSandSys::Process(int & nStatus)
{
	if(m_iStatu == _SAND_NONE)
		return;
	if(m_iStatu == _SAND_PAUSE)
		return;
	
	for (int i=0;i<m_iSandAmount ; i++)
	{
		
		if(m_iStatu == _SAND_BEGIN && m_iSandAmount< m_iTargetAmount)
		{
			int nInternal = m_iSandAmount ;
			if(nInternal >199)
				nInternal = 199;
			nInternal = 200 - nInternal;
			if(rand()%nInternal == 0)
			{
				m_iSandAmount	+=1;
				int nSelfVolume = m_iSandAmount * 4 *100 / _MAX_AMOUNT;
				if(nSelfVolume >140)
					nSelfVolume = 140;
				else
					if(nSelfVolume < 25)
						nSelfVolume = 25;
					DXSetVolume("sound/rain.wav",nSelfVolume,0,0); 
			}
		}
		else
			if(m_iStatu == _SAND_STOP )
			{
				if(m_iSandAmount > 5)
				{
					int nInternal = m_iSandAmount ;
					if(nInternal >199)
					nInternal = 199;
					nInternal = 200 - nInternal;
					if(rand()%nInternal == 0)
					{
					m_iSandAmount	--;
					int nSelfVolume = m_iSandAmount * 4 *100 / _MAX_AMOUNT;
					if(nSelfVolume >140)
						nSelfVolume = 140;
					else
						if(nSelfVolume < 25)
							nSelfVolume = 25;
						DXSetVolume("sound/rain.wav",nSelfVolume,0,0); 
					}
				}
				else
				{
					Destroy();
					nStatus = 0;
					return;
				}
			}
			
			else
				if(m_iStatu == _SAND_RESET)
					if(m_nLevel > m_iSandAmount)
					{
						int nInternal = m_iSandAmount ;
						if(nInternal >199)
							nInternal = 199;
						nInternal = 200 - nInternal;
						if(rand()%nInternal == 0)
						{
							m_iSandAmount	+=1;
							int nSelfVolume = m_iSandAmount * 4 *100 / _MAX_AMOUNT;
							if(nSelfVolume >140)
								nSelfVolume = 140;
							else
								if(nSelfVolume < 25)
									nSelfVolume = 25;
								DXSetVolume("sound/rain.wav",nSelfVolume,0,0); 
						}
					}
					else
						if(m_iSandAmount > m_nLevel && m_iSandAmount > 10 )
						{

							int nInternal = m_iSandAmount ;
							if(nInternal >199)
							nInternal = 199;
							nInternal = 200 - nInternal;
							if(rand()%nInternal == 0)
							{
							m_iSandAmount	--;
							int nSelfVolume = m_iSandAmount * 4 *100 / _MAX_AMOUNT;
							if(nSelfVolume >140)
								nSelfVolume = 140;
							else
								if(nSelfVolume < 25)
									nSelfVolume = 25;
								DXSetVolume("sound/rain.wav",nSelfVolume,0,0); 
							}
						}
			if(m_iSandAmount > _MAX_AMOUNT)
				m_iSandAmount = _MAX_AMOUNT;
			if(m_iSandAmount <0)
				m_iSandAmount = 0;	 
			
			if(!m_Sand[i]->IsCreated())
			{
				int iPosY,iPosX;
				if(m_nWindDirection >= 0)		
				{
					iPosY	= rand() % (_SCR_HEIGHT +  8* m_nWindDirection)  - 8 * m_nWindDirection;
					iPosX		= -rand()%50 - 10; 
					m_Sand[i]->m_nDir =1;
				}
				else
				{
					iPosY	= rand() % (_SCR_HEIGHT - 8* m_nWindDirection)+10; 
					iPosX		= _SCR_WIDTH + rand()%30; 
					m_Sand[i]->m_nDir = -1;
				}			
				int iSceneDeepth=rand()%32+4;
				
				int nDir=1;
				if(rand()%2 == 1)
					nDir = -1; 
				m_Sand[i]->Create(iPosX,iPosY,iSceneDeepth,m_nWindDirection + rand()%30 * nDir  , 1,m_nLevel);	
				
			}
			m_Sand[i]->Process( );
	}
	
	return;
}

void CSandSys::SandStop()
{
	this->m_iStatu = _SAND_STOP;
}

void CSandSys::Destroy()
{
	DXCloseSound("sound/sand.wav",0,0);
	for(DWORD i = 0 ;i<m_Sand.size();i++)	 
		SAFE_DELETE(m_Sand[i]);
	
	m_Sand.clear(); 
	m_iStatu = _SAND_NONE;
	
}





//-----------------------------------------------------------------------------------
//
//烟花
//-----------------------------------------------------------------------------


//--------------------------------------------------------------
void CYinFa::Reset(void)
{
	m_iStatus		=_YINFASTATUS_NONE;
}

BOOL CYinFa::Create(int iOrigPosX,int iOrigPosY,int nMarginX, int nMarginY, int nRadius  )
{
	
	if(m_iStatus!=_YINFASTATUS_NONE)
		return FALSE;
	
	m_iStatus				=  _YINFASTATUS_START;
	m_nCenterWorldPoint.x	= iOrigPosX - 80 + rand()%170;
	m_nCenterWorldPoint.y	= iOrigPosY ;
	m_nMarginWorldPoint.x	= nMarginX;
	m_nMarginWorldPoint.y	= nMarginY;
	m_fRadius				= nRadius;	 
	
	m_nPathCount			= rand()%(nRadius/20+1)+2;
	m_nPathLength			= nRadius/28 + 2 ;  
	m_nStartWoldPoint.x		= iOrigPosX;
	m_nStartWoldPoint.y		= iOrigPosY + 200; 
	
	
	
	return TRUE;
}


void CYinFa::Show()
{
	if(m_iStatus==_YINFASTATUS_NONE)
		return;	 
	
	if(	m_iStatus == _YINFASTATUS_START)
	{
		if( m_nStartWoldPoint.y <= this->m_nCenterWorldPoint.y + m_nPathCount * 5)
		{
			m_iStatus = _YINFASTATUS_CREATE;
			m_dwLifeBeginTime = TimeGet();
			m_nPathCount = 0; 
		}
		else
		{
			m_nPathCount ++;
			m_nStartWoldPoint.y -= m_nPathCount * 5 - rand()% 5;
			int iY0	=  	m_nStartWoldPoint.y;
			int iX0	=  m_nStartWoldPoint.x + (m_nStartWoldPoint.x - this->m_nCenterWorldPoint.x)* (m_nPathCount * m_nPathCount)  / 600; 
			int nScreenX,nScreenY;
			g_objGameMap.World2Screen(iX0,iY0,nScreenX,nScreenY);
			CAni * pAni = g_objGameDataSet.GetDataAni("ani/weather.ani",m_szFileTitle);
			if(pAni)
				pAni->Show(0,nScreenX,nScreenY , 255,_SHOWWAY_ADDITIVE);
		}
	}
	else
		if(m_iStatus==_YINFASTATUS_CREATE)
		{
			DWORD m_dwElapseTime	=TimeGet()-m_dwLifeBeginTime; 
			double dElapseTime	=(double)m_dwElapseTime/80.0;
			double dOffsetB		=(double)1.0*dElapseTime*dElapseTime/2.0;
			
			int iY0	= m_nPathCount * (m_nMarginWorldPoint.y - m_nCenterWorldPoint.y )/ m_nPathLength + m_nCenterWorldPoint.y + dOffsetB ;
			int iX0	= m_nPathCount * (m_nMarginWorldPoint.x - m_nCenterWorldPoint.x )/ m_nPathLength + m_nCenterWorldPoint.x ;
			int nScreenX,nScreenY;
			g_objGameMap.World2Screen(iX0,iY0,nScreenX,nScreenY);
			int nStepPerColor = m_nPathLength / _YINFA_FRAME + 1;
			int nFrame = (m_nPathCount  )/ nStepPerColor*1.5;
			if(nFrame >= _YINFA_FRAME)
				nFrame = _YINFA_FRAME - 1;
			if(nFrame < 0)
				nFrame =0;				 
			CAni * pAni = g_objGameDataSet.GetDataAni("ani/weather.ani",m_szFileTitle);
			if(pAni)
			{
				pAni->Show(nFrame,nScreenX,nScreenY + (m_nPathLength-m_nPathCount), 255,_SHOWWAY_ADDITIVE);
				pAni->Show(nFrame,nScreenX+10,nScreenY+10 + (m_nPathLength-m_nPathCount), 255,_SHOWWAY_ADDITIVE);
			}	 
			
			m_nPathCount ++;			
			if(m_nPathCount >= m_nPathLength)
			{
				m_iStatus	=_YINFASTATUS_FALL;
				int nRadius;
				nRadius = (m_fRadius  + 1)/5;
				if(nRadius<15)
					nRadius = 15;
				m_nFallLenght = rand()%nRadius +10 ;
				m_nFallStep = 0;
				m_nFallWorldPoint.x =  m_nMarginWorldPoint.x + rand()% 10;
				m_nFallWorldPoint.y  =	m_nPathCount * (m_nMarginWorldPoint.y - m_nCenterWorldPoint.y )/ m_nPathLength + m_nCenterWorldPoint.y + dOffsetB;
				
			}
		}
		else if(m_iStatus==_YINFASTATUS_FALL)
		{ 
			if( m_nFallStep >= m_nFallLenght )
			{
				m_iStatus = _YINFASTATUS_END;	
				return;
			}
				
			m_nFallStep++;
			int iX0,iY0,nScreenx,nScreeny;
			iX0 = m_nFallWorldPoint.x ; 
			iY0 = m_nFallWorldPoint.y + m_nFallStep * 4 + m_nFallStep * m_nFallStep /50 ; 
			g_objGameMap.World2Screen(iX0,iY0,nScreenx,nScreeny);
			CAni * pAni = g_objGameDataSet.GetDataAni("ani/weather.ani",m_szFileTitle);
			if(pAni)
			{
				int nFrame = pAni->GetFrameAmount() -1;
				pAni->Show(nFrame,nScreenx,nScreeny, 255 - 255 * m_nFallStep/m_nFallLenght);//,_SHOWWAY_ADDITIVE);
				pAni->Show(nFrame,nScreenx + 10 ,nScreeny + 10, 255 - 255 * m_nFallStep/m_nFallLenght);//,_SHOWWAY_ADDITIVE);
			}
		}
		
		return;
}



//--------------------------------------------------------------
void CYinFa::Destroy(void)
{
	return;
}

//--------------------------------------------------------------

void CYinFa::Process()
{
	Show();
	return;
}



BOOL CYinFaSys::Create(int nScreenX,int nScreenY,int nNum, int nShowNum, int nRadius, int nType,DWORD dwDelayTime)
{
	if( nRadius > 400)
		nRadius = 400;
	if( nRadius < 5 )
		nRadius = 5;
	if(nShowNum > 20)
		nShowNum = 20;
	if(nShowNum <1 )
		nShowNum = 1;
	if(nNum < 1)
		nNum =1;
	if(nType <= 0)
		nType = 1;
	this->m_nYinFaShowNum   = nShowNum;
	this->m_nYinFaTotal		= nNum;
	this->m_nYinFaType		= nType;
	m_nYinFaUsed			= 0;
	m_fRadius				= nRadius; 
	
	sprintf(m_szFileTitle,"%s%d","YinFa",nType);	 
	
	this->m_iStatu			= _YINFA_BEGIN; 
	m_dwCreateTime			= TimeGet() + dwDelayTime;
	
	for(int i = 0; i<_MAX_AMOUNT * 2; i++)
	{
		CYinFa * YinFa = new CYinFa();
		m_YinFa.push_back(YinFa);
	}
	
	this->m_nInterval		= 0;
	int nCenterX			=nScreenX; 
	int nCenterY			= nScreenY; 
	
	g_objGameMap.Screen2World( nCenterX  , nCenterY   , m_nOrigWorldPointX, m_nOrigWorldPointY ); 
	m_nCreated = 1;
	m_dwDelayTime			= dwDelayTime;
	m_dwBeginTime			= TimeGet();
	return TRUE;
}

//--------------------------------------------------------------
// FIREWORK
//--------------------------------------------------------------



void CYinFaSys::Process()
{ 
	if(m_nCreated != 1)
		return;
	else
	{
		if((TimeGet() - m_dwBeginTime) < m_dwDelayTime)
			return;
	}
	if(m_iStatu == _YINFA_NONE)
		return;
	int nParticleStep = 4;
	if(m_fRadius>500)
		nParticleStep = 8;
	else
		if(m_fRadius > 300)
			nParticleStep = 6;
		
		if( m_iStatu !=  _YINFA_STOP)	 
		{
			if( !m_YinFa[m_fRadius/3 + m_fRadius /2 +m_fRadius*2 /3+1]->IsCreated())
			{
				int x,i;
				this->m_nInterval++;
				
				if(this->m_nInterval > 3)
				{
					float nRx = (float)m_fRadius  ;
					float nRy= (float)nRx*2/3;
					for (float x= -nRx,i= m_fRadius/3 + m_fRadius /2 +m_fRadius*2 /3 ; x< nRx ; x+=nParticleStep)
					{	
						if(i>= _MAX_AMOUNT*2)
							break;
						int TargetY = sqrt( nRy * nRy - x * x / (nRx * nRx)  * (nRy * nRy) ) + m_nOrigWorldPointY;
						int TargetX = x + m_nOrigWorldPointX;	
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx );//* 1.8 					
						m_YinFa[i++]->SetPicture(m_szFileTitle);					
						int nOtherSideY = TargetY - m_nOrigWorldPointY;
						TargetY = m_nOrigWorldPointY - nOtherSideY;					
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx );// * 1.8
						m_YinFa[i++]->SetPicture(m_szFileTitle);					
					}
					m_nYinFaUsed += this->m_nYinFaShowNum;
					if(m_nYinFaUsed >= this->m_nYinFaTotal)
					{
						this->YinFaStop();
						
					}
				}
				else	if(this->m_nInterval > 2)
				{
					float nRx = (float)m_fRadius *2/3;
					float nRy= (float)nRx*2/3;
					float nRx1 = nRx;
					float nRy1 = nRy;
					for (  x= -nRx,i= m_fRadius/3 + m_fRadius/2  ; x< nRx ; x+=nParticleStep)
					{
						float x1 = x;
						int TargetY = sqrt( nRy1 * nRy1 - x1 * x1 / (nRx1 * nRx1)  * (nRy1 * nRy1) ) + m_nOrigWorldPointY;
						int TargetX = x + m_nOrigWorldPointX;	
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx1 );//* 1.5					
						m_YinFa[i++]->SetPicture(m_szFileTitle);					
						int nOtherSideY = TargetY - m_nOrigWorldPointY;
						TargetY = m_nOrigWorldPointY - nOtherSideY;					
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx1  );//* 1.5					
						m_YinFa[i++]->SetPicture(m_szFileTitle);
					}			 
				}
				else if(this->m_nInterval > 1)
				{
					float nRx = (float)m_fRadius/2.0f;
					float nRy= (float)nRx*2/3.0f;
					float nRx1 =nRx;
					float nRy1 = nRy;
					for (float x= -nRx,i= m_fRadius/3 ; x< nRx ; x+=nParticleStep)
					{
						float x1 = x;
						int TargetY = sqrt( nRy1 * nRy1 - x1 * x1 / (nRx1 * nRx1)  * (nRy1 * nRy1) ) + m_nOrigWorldPointY;
						int TargetX = x1 + m_nOrigWorldPointX;	
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx1 );//*1.2					
						m_YinFa[i++]->SetPicture(m_szFileTitle);					
						int nOtherSideY = TargetY - m_nOrigWorldPointY;
						TargetY = m_nOrigWorldPointY - nOtherSideY;					
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx1  );//	*1.2				
						m_YinFa[i++]->SetPicture(m_szFileTitle);
					}		
					
				}
				else
				{
					DXPlaySound("sound/firework1.wav",0,0 );
					float nRx = (float)m_fRadius*3/12.0f;
					float nRy= (float)nRx*2/3.0f;
					float nRx1 = nRx;
					float nRy1 = nRy;
					
					for (float x= -nRx,i=m_fRadius/12 ; x< nRx ; x+=nParticleStep)
					{
						float x1 = x;// * 2;
						int TargetY = sqrt( nRy1 * nRy1 - x1 * x1 / (nRx1 * nRx1)  * (nRy1 * nRy1) ) + m_nOrigWorldPointY;
						int TargetX = x + m_nOrigWorldPointX;	
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx );					
						m_YinFa[i++]->SetPicture(m_szFileTitle);					
						int nOtherSideY = TargetY - m_nOrigWorldPointY;
						TargetY = m_nOrigWorldPointY - nOtherSideY;
						
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx );					
						m_YinFa[i++]->SetPicture(m_szFileTitle);
						
					}	
					
					nRx = (float)m_fRadius/12.0f;
					nRy= (float)nRx*2/3.0f;
					
					for (x= -nRx,i=0 ; x< nRx ; x+=nParticleStep)
					{		
						int TargetY = sqrt( nRy * nRy - x * x / (nRx * nRx)  * (nRy * nRy) ) + m_nOrigWorldPointY;
						int TargetX = x + m_nOrigWorldPointX;	
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx );					
						m_YinFa[i++]->SetPicture(m_szFileTitle);					
						int nOtherSideY = TargetY - m_nOrigWorldPointY;
						TargetY = m_nOrigWorldPointY - nOtherSideY;					
						m_YinFa[i]->Create( m_nOrigWorldPointX, m_nOrigWorldPointY, TargetX, TargetY, nRx );
						m_YinFa[i++]->SetPicture(m_szFileTitle);
						
					}		
				}
		}
		
	}
	
	else
	{
		if(m_iStatu != _YINFA_NONE)
			if(_YINFASTATUS_END  ==m_YinFa[m_fRadius  + m_fRadius /2 ]->IsCreated()   && m_nInterval++ > 255 )
				this->Destroy();
	}
	for(DWORD j = 0;j<m_YinFa.size();j++)

⌨️ 快捷键说明

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