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

📄 weather.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include "Weather.h"
#include "3dgamemap.h"
#include "gamedataset.h"
#include "basefunc.h"
#include <string.h>
#include "../ndsound/ndsound.h"

#define HZK24c "hzk24k"
#define HZK24t "hzk24t" 
#define const int _SCR_HEIGHT = 600;
int SIN[7] = { 0,173,342,500,642,766,766};
int COS[7] = {1000, 984,939, 866,766,642,642};
//------------------------------------------------------------
//
//树叶
//--------------------------------------------------------------
CLeaf::CLeaf(void)
{
	m_iStatus		=_LEAFSTATUS_NONE;
	return;
}


//--------------------------------------------------------------
BOOL CLeaf::Create(int iPosX,int iPosY,int iSceneDeepth,int fWind,int fGravity)
{
	
	if(m_iStatus!=_LEAFSTATUS_NONE)
		return FALSE;
	
	m_iStatus			=_LEAFSTATUS_CREATE;
	int iWorldX,iWorldY;
	g_objGameMap.Screen2World(iPosX,iPosY,iWorldX,iWorldY);
	m_iStartX			= iWorldX;
	m_iStartY			= iWorldY;
	m_iSceneDeepth		= iSceneDeepth;
	m_fWind				= fWind;
	
	m_dwLifeBeginTime	= TimeGet();
	m_dwElapseTime		= 0;
	m_iSceneDeepth	   %= 36;
	m_iLayerFrame		= iSceneDeepth/9 * 6;
	m_iSize				= 4+4*(36-m_iSceneDeepth)/36 ;
	m_fSpeed			= 2+16*m_iSceneDeepth/36;
	m_fGravity			= fGravity*(36-m_iSceneDeepth)/36+2 ; 
	
	m_fSinA				= SIN[(abs(m_fWind) + rand()%10)/10];
	if(m_fWind < 0)
		m_fSinA = - m_fSinA;
	
	m_fCosA				= COS[(abs(m_fWind) + rand()%10)/10];
	
	this->m_dwLifeTime		= 10000*(36-m_iSceneDeepth)/36 + 500 + 9000*abs(m_fSinA)/1000;
	this->m_ibmpFrameIndex	= m_iLayerFrame;
	this->m_nLoopCount		= 0;
	this->m_dStayGroundTime	= 0;
	this->m_iSplashX		= 0;
	this->m_iSplashY		= 0;
	this->m_bLieOnGround	= 0;
	this->m_iLastFrame		= -1;
	this->m_iLastPosX		= 0;
	this->m_iLastPosY		= 0;
	
	return TRUE;
}

void CLeaf::Show()
{
	
	if(m_iStatus==_LEAFSTATUS_NONE)
		return;
	DWORD dwNow =TimeGet();
	m_dwElapseTime	=dwNow - this->m_dwLifeBeginTime;
	if(m_dwElapseTime >= m_dwLifeTime)
	{
		if(m_iStatus==_LEAFSTATUS_CREATE)
		{
			this->m_dwLifeBeginTime	=TimeGet();
			m_dwElapseTime		=0;
			this->m_iStatus			=_LEAFSTATUS_SPLASH;
			
			if(!this->m_iSplashX || !this->m_iSplashY)
				this->m_iStatus = _LEAFSTATUS_NONE;		
			
			int nCellx,nCelly;
			g_objGameMap.World2Cell(this->m_iSplashX,this->m_iSplashY,nCellx,nCelly);
			int nCellW,nCellH;
			CMySize s;
			g_objGameMap.GetMapSize(s);
			nCellW = s.iWidth;
			nCellH = s.iHeight;
			if(nCellx<0 || nCellx > nCellW || nCelly<0 || nCelly > nCellH)
			{
				this->m_iStatus = _LEAFSTATUS_NONE;			
			}
#ifndef _NOTUSETRY
			try{
#endif
				DWORD uMask;
				CellInfo *c;
				c=g_objGameMap.GetCell(nCellx,nCelly);
				LayerInfo* pLayer = g_objGameMap.GetLastLayerInfo(c);
				uMask = pLayer->usTerrain;
				if(uMask == 1)//UNSTAY
					this->m_bLieOnGround = 0;
				else
					this->m_bLieOnGround = 1;
#ifndef _NOTUSETRY
			}
			catch(...)
			{
				this->m_iStatus = _LEAFSTATUS_NONE;				
			}
#endif
		}
	}
	
	if(m_iStatus==_LEAFSTATUS_CREATE)
	{		
		int 	dOffset		= (m_fSpeed * m_dwElapseTime * 1000  *  10 / 1800/1000 ) + (m_fGravity* m_dwElapseTime * 1000/1800   * m_dwElapseTime * 1000/1800 * 10 /1000 / 1000 /2)  ;// *10
		
		if(dOffset<=0 && m_dwElapseTime)
		{
			this->m_iStatus	=_LEAFSTATUS_NONE;
		}
		else
		{			
			g_objGameMap.World2Screen(this->m_iStartX,this->m_iStartY,m_iScreenX,m_iScreenY);
			int iX0	= m_iScreenX + dOffset*m_fSinA * m_iSize /1000/10; 
			int iY0	= m_iScreenY + dOffset*m_fCosA * m_iSize /1000/10; 
			
			if(m_nLoopCount % 3 == 1)
				m_ibmpFrameIndex++;
			if(m_ibmpFrameIndex>=this->m_iLayerFrame +  _LEAF_FRAME/4)
				m_ibmpFrameIndex = this->m_iLayerFrame;			
			CAni * pAni = g_objGameDataSet.GetDataAni("ani/weather.ani",m_szFileName);
			if(pAni)
				pAni->Show(m_ibmpFrameIndex,iX0,iY0,255);
			
			int nWorldx,nWorldy;
			int iX1	= iX0  + m_iSize*m_fSinA/1000 ;
			int iY1	= iY0  + m_iSize*m_fCosA/1000 ;
			g_objGameMap.Screen2World(iX1,iY1,nWorldx,nWorldy);
			this->m_iSplashX	= nWorldx;
			this->m_iSplashY	= nWorldy;
			this->m_nLoopCount ++;
		}
	}
	else if(m_iStatus==_LEAFSTATUS_SPLASH)
	{		
		this->m_dStayGroundTime ++;
		int nScreenx,nScreeny ; 
		g_objGameMap.World2Screen(this->m_iSplashX,this->m_iSplashY,nScreenx,nScreeny); 
		if(nScreenx< -5 || nScreenx > _SCR_WIDTH || nScreeny < -5 || nScreeny > _SCR_HEIGHT)
		{
			m_iStatus	=_LEAFSTATUS_NONE;	
			return;
		}
		CAni * pAni = g_objGameDataSet.GetDataAni("ani/weather.ani",m_szFileName);
		
		if(!m_bLieOnGround)
		{
			if(m_dStayGroundTime >20)
				m_iStatus = _LEAFSTATUS_NONE;
			if(pAni)			 
				pAni->Show(m_ibmpFrameIndex,nScreenx,nScreeny,210 - m_dStayGroundTime*10);			
		}
		else
		{
			if(m_dStayGroundTime > 480)
				m_iStatus	=_LEAFSTATUS_NONE;	
			else
				if(pAni)
					pAni->Show(m_ibmpFrameIndex,nScreenx,nScreeny, 250-m_dStayGroundTime/2);
		}	
	}
	
	return;
}

//--------------------------------------------------------------
void CLeaf::Destroy(void)  
{
	this->m_iStatus = _LEAFSTATUS_NONE;	
}

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

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


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


void CLeafSys::Pause()
{	
	DXSetVolume("sound/leaf.wav",0,0,0); 
	m_iStatu =  _LEAF_PAUSE;
	m_dwPauseTime = TimeGet();
	
}
void CLeafSys::Continue()
{
	if(m_iStatu !=  _LEAF_PAUSE)
		return;
	DWORD dwElapseTime = TimeGet() -  m_dwPauseTime;
	DWORD i;
	for(i = 0 ;i<this->m_Leaf.size();i++)
		m_Leaf[i]->m_dwLifeBeginTime += dwElapseTime;
	
	int nSelfVolume = m_iLeafAmount * 5 *100 / LEAF_MAX_AMOUNT;
	if(nSelfVolume >120)
		nSelfVolume = 120;
	else
		if(nSelfVolume < 50)
			nSelfVolume = 50;
		DXSetVolume("sound/leaf.wav",nSelfVolume,0,0); 
		
		m_iStatu = _LEAF_BEGIN;
}


BOOL CLeafSys::Create(int nWindDir= 20 ,int nLevel = 2,int nType = 1)
{
	Destroy();
	char szTitle[100];
	switch(nType)
	{
	case 1:
	case 2:
	case 3:
	case 4:
	case 5:
		sprintf(szTitle,"%s%d","Leaf",nType); 
		break;
		
	case 6:
	case 7:
		sprintf(szTitle,"%s%d","Leaf",6); 
		break;
	case 8:
		sprintf(szTitle,"%s%d","flying",1);
		break;
	case 9:
	case 10:
		return FALSE;
		
	default:
		return FALSE;
		
	}
	strcpy(m_szFileName,szTitle);	
	this->m_iStatu	= _LEAF_BEGIN;
	m_iLeafAmount	= 1;
	m_dwPauseTime	= 0;
	this->m_iTargetAmount = nLevel ; 
	this->m_nWindDirection = nWindDir;
	int i;
	for(i = 0;i<LEAF_MAX_AMOUNT;i++)
	{
		CLeaf * leaf = new CLeaf();
		m_Leaf.push_back(leaf);
	}
	
	int nSelfVolume = m_iLeafAmount * 500 / LEAF_MAX_AMOUNT;
	if(nSelfVolume >120)
		nSelfVolume = 120;
	else
		if(nSelfVolume < 30)
			nSelfVolume = 30;
		DXPlaySound("sound/leaf.wav",0,0,0,-1,nSelfVolume); 
		
		return TRUE;
}


void CLeafSys::Process(int & nStatus)
{ 
	if( m_iStatu == _LEAF_NONE )
		return;
	if( m_iStatu == _LEAF_PAUSE)
		return;
	
	for (int i=0;i<this->m_iLeafAmount ; i++)
	{
		
		if(this->m_iStatu == _LEAF_BEGIN && m_iLeafAmount< m_iTargetAmount )
		{
			int nInternal = m_iLeafAmount*2;
			if(nInternal >99)
				nInternal = 99;
			nInternal = 100 - nInternal;
			if(rand()%nInternal == 0)
			{
				m_iLeafAmount	+=1;
				int nSelfVolume = m_iLeafAmount * 300 / LEAF_MAX_AMOUNT;
				if(nSelfVolume >120)
				nSelfVolume = 120;
				else
				if(nSelfVolume < 20)
					nSelfVolume = 20;
				DXSetVolume("sound/leaf.wav",nSelfVolume,0,0); 
			}
		}
		else
		{
			if(this->m_iStatu == _LEAF_STOP )
			{
				if(m_iLeafAmount > 2)	
				{
					int nInternal = m_iLeafAmount*2 ;
					if(nInternal >99)
						nInternal = 99;
					nInternal = 100 - nInternal;
					if(rand()%nInternal == 0)
					{
						m_iLeafAmount -= 1;
						int nSelfVolume = m_iLeafAmount * 300 / LEAF_MAX_AMOUNT;
						if(nSelfVolume >120)
						nSelfVolume = 120;
						else
						if(nSelfVolume < 20)
							nSelfVolume = 20;
						DXSetVolume("sound/leaf.wav",nSelfVolume,0,0); 
					}
				}
				else
				{
					Destroy();
					nStatus = 0;
					return;
				}
			}
			else
			{
				if(this->m_iStatu == _LEAF_RESET)
					if(m_iLeafAmount< m_iTargetAmount)
					{
						int nInternal = m_iLeafAmount*2 ;
						if(nInternal >99)
							nInternal = 99;
						nInternal = 100 - nInternal;
						if(rand()%nInternal == 0)
						{
							m_iLeafAmount += 1;
							int nSelfVolume = m_iLeafAmount * 300 / LEAF_MAX_AMOUNT;
							if(nSelfVolume >120)
							nSelfVolume = 120;
							else
							if(nSelfVolume < 20)
								nSelfVolume = 20;
							DXSetVolume("sound/leaf.wav",nSelfVolume,0,0); 
						}
						
					}
					else						
						if(m_iLeafAmount >m_iTargetAmount && m_iLeafAmount>1)
						{
							int nInternal = m_iLeafAmount*2 ;
							if(nInternal >99)
								nInternal = 99;
							nInternal = 100 - nInternal;
							if(rand()%nInternal == 0)
							{
								m_iLeafAmount -= 1;
								int nSelfVolume = m_iLeafAmount * 300 / LEAF_MAX_AMOUNT;
								if(nSelfVolume >120)
								nSelfVolume = 120;
								else
								if(nSelfVolume < 20)
									nSelfVolume = 20;
								DXSetVolume("sound/leaf.wav",nSelfVolume,0,0); 
							}
						}
			}
		}
		
		if(!m_Leaf[i]->IsCreated())
		{
			int iPosX;
			if(this->m_nWindDirection >= 0)			 
				iPosX	= rand() % (_SCR_WIDTH +  10* m_nWindDirection)  - 10 * m_nWindDirection;
			else
				iPosX	= rand() % (_SCR_WIDTH - 10* m_nWindDirection)+20;
			int iPosY		= rand()%250-120; 
			int iSceneDeepth=rand()%32+4;
			
			m_Leaf[i]->Create(iPosX,iPosY,iSceneDeepth,m_nWindDirection + rand()%8,2);	
			m_Leaf[i]->SetPicture(m_szFileName);
		}
		m_Leaf[i]->Process();	 
	}
	return;
}


void CLeafSys::LeafStop()
{
	this->m_iStatu = _LEAF_STOP;
}

void CLeafSys::Destroy()
{
	DWORD i;
	for( i= 0 ;i<m_Leaf.size();i++)	 
		SAFE_DELETE(m_Leaf[i]); 
	m_Leaf.clear();	
	this->m_iStatu = _LEAF_NONE;
	DXCloseSound("sound/leaf.wav",0,0);
}
void CLeafSys::SetLeaf(int nWindDir,int nLevel = 0)
{
	if(nLevel>=LEAF_MAX_AMOUNT)
		nLevel=LEAF_MAX_AMOUNT-1;
	if(m_iLeafAmount != nLevel)
	{
		m_iStatu = _LEAF_RESET;
		m_iTargetAmount = nLevel;			
	}
	for(DWORD i=0;i<m_Leaf.size();i++)
	{	 
		m_Leaf[i]->m_fSinA				= SIN[(abs(nWindDir) + rand()%10)/10];
		if(nWindDir < 0)
			m_Leaf[i]->m_fSinA = - m_Leaf[i]->m_fSinA;
		
		m_Leaf[i]->m_fCosA				= COS[(abs(nWindDir) + rand()%10)/10];
		
	}
	m_nWindDirection = nWindDir;
	
}






//--------------------------------------------------------------
//雪
//--------------------------------------------------------------


CSnow::CSnow(void)
{
	m_iStatus		=_SNOWSTATUS_NONE;	
	return;
}


//--------------------------------------------------------------
void CSnow::Reset(void)
{
	m_iStatus		=_SNOWSTATUS_NONE;
}

//--------------------------------------------------------------
BOOL CSnow::Create(int iPosX,int iPosY,int iSceneDeepth,int fWind,int fGravity)
{
	if(m_iStatus!=_SNOWSTATUS_NONE)
		return FALSE;	 
	m_iStatus			=_SNOWSTATUS_CREATE;
    m_iStartX			=iPosX;
    m_iStartY			=iPosY;
	m_iSceneDeepth		=iSceneDeepth %16;
	m_fWind				=fWind;
	
	m_dwLifeBeginTime	=TimeGet();
	m_dwElapseTime		=0;
	
	m_fSinA				= SIN[(abs(m_fWind) + rand()%10)/10];
	if(m_fWind < 0)
		m_fSinA = - m_fSinA;
	m_fCosA				= COS[(abs(m_fWind) + rand()%10)/10];
	m_fSpeed			=2+(16-m_iSceneDeepth)/16;
	m_fGravity			=1; 
	m_dwLifeTime		=6000*(24-m_iSceneDeepth)/24+600 + 2500*abs(m_fSinA)/1000; 
	m_nStayTick			= 0;
	m_iLastPosX			= 0;
	m_iLastPosY			= 0;	 
	
	return TRUE;
}

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

void CSnow::ShowImage ( int iPosX, int iPosY )
{
    int iWorldX,iWorldY;
    g_objGameMap.Screen2World(iPosX,iPosY,iWorldX,iWorldY);
    m_iSplashX	=iWorldX;
    m_iSplashY	=iWorldY;	
	if((rand()%6)==1)
		iPosX	+=3-rand()%6;
	CAni * pAni = g_objGameDataSet.GetDataAni("ani/weather.ani",m_szFileName);
	if(pAni)
		pAni->Show(0,iPosX, iPosY,  (36-m_iSceneDeepth + 5) * 6);	
	return;
}


void CSnow::Show(void)
{
	
	if(m_iStatus==_SNOWSTATUS_NONE)
		return;
	m_dwElapseTime	=TimeGet()-m_dwLifeBeginTime;
	if(m_dwElapseTime >= m_dwLifeTime)
	{
		if(m_iStatus==_SNOWSTATUS_CREATE)

⌨️ 快捷键说明

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