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

📄 water.cpp

📁 好游戏的客户端原码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				nSelectedRedValue	= nRedValue - INT((nRedValue*rLengthCnt*rDrakRate)/(nRadius));
				nSelectedGreenValue	= nGreenValue - INT((nGreenValue*rLengthCnt*rDrakRate)/(nRadius));
				nSelectedBlueValue	= nBlueValue - INT((nBlueValue*rLengthCnt*rDrakRate)/(nRadius));
/*				SetRect(&rc,
					   (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS),
					   (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS),
					   (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS+2),
					   (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS+2));
				g_xMainWnd.DrawWithGDI(rc, NULL, RGB(255, 0, 0), 1);
*/			}
			else
			{
				nSelectedRedValue = nSelectedGreenValue = nSelectedBlueValue = 0;
			}

			if ( nSelectedRedValue	 < 0 )		nSelectedRedValue	= 0;
			if ( nSelectedGreenValue < 0 )		nSelectedGreenValue = 0;
			if ( nSelectedBlueValue	 < 0 )		nSelectedBlueValue	= 0;

			if ( m_avLight[nCntY][nCntX].color == 0 )
				m_avLight[nCntY][nCntX].color = RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue); 
			else
			{
				nSelectedRedValue += (INT)RGB_GETBLUE(m_avLight[nCntY][nCntX].color);
				nSelectedGreenValue += (INT)RGB_GETGREEN(m_avLight[nCntY][nCntX].color);
				nSelectedBlueValue += (INT)RGB_GETRED(m_avLight[nCntY][nCntX].color);

				if ( nSelectedRedValue	 > 255 )		nSelectedRedValue	= 255;
				if ( nSelectedGreenValue > 255 )		nSelectedGreenValue = 255;
				if ( nSelectedBlueValue	 > 255 )		nSelectedBlueValue	= 255;

				m_avLight[nCntY][nCntX].color =  RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue);
			}
		}
	}

	return TRUE;
}


BOOL CWater::SetLightRadiusWithElipse(INT XLightPos, INT YLightPos, INT nXRadius, INT nYRadius, 
										 INT nRedValue, INT nGreenValue, INT nBlueValue, 
										 FLOAT rDrakRate)
{
	INT nX, nY;
	GetScreenPosToLightTile(XLightPos, YLightPos, &nX, &nY);

	INT nStartTileX			= nX - nXRadius;
	INT nStartTileY			= nY - nYRadius;
	INT nEndTileX			= nX + nXRadius + 1;
	INT nEndTileY			= nY + nYRadius + 1;
	
	FLOAT rXRadius = (FLOAT)(nXRadius*WATER_TILE_WIDTH);
	FLOAT rYRadius = (FLOAT)(nYRadius*WATER_TILE_HEIGHT);
	INT	  nRadius  = 0;

	if ( rXRadius > rYRadius )
	{
		nRadius = (INT)rXRadius;
	}
	else
	{
		nRadius = (INT)rYRadius;
	}

	DOUBLE rLengthCnt		= 0;
	INT nSelectedRedValue	= 0; 
	INT nSelectedGreenValue	= 0; 
	INT nSelectedBlueValue	= 0; 

	if ( nStartTileX < 0 )					nStartTileX = 0;
	if ( nStartTileY < 0 )					nStartTileY = 0;
	if ( nEndTileX > WATER_NUM_CNTX_LIGHTTILE+1 )	nEndTileX = WATER_NUM_CNTX_LIGHTTILE+1;
	if ( nEndTileY > WATER_NUM_CNTY_LIGHTTILE+1 )	nEndTileY = WATER_NUM_CNTY_LIGHTTILE+1;


	for ( INT nCntY = nStartTileY; nCntY < nEndTileY; nCntY++ )
	{
		for ( INT nCntX = nStartTileX; nCntX < nEndTileX; nCntX++ )
		{
			if ( nCntX < WATER_NUM_CNTX_LIGHTTILE && nCntY < WATER_NUM_CNTY_LIGHTTILE )
			{
				// 器牢飘痢阑 器窃窍瘤 臼绰 谅窍. 器牢飘痢阑 器窃窍瘤 臼绰 快惑.
				if ( (nCntX > nX && nCntY < nY) || (nCntX < nX && nCntY > nY) )
				{
					WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
					*pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
					*pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
					*pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
					*pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
					*pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
					*pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
				}
				else
				{
					WORD* pwIndex = ((WORD*)m_pwLightIndices+(nCntX+nCntY*(WATER_NUM_CNTX_LIGHTTILE))*6);
					*pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
					*pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
					*pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
					*pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
					*pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);  
					*pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
				}
			}

/*			RECT rc;
			SetRect(&rc,
				   (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS),
				   (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS),
				   (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS+WATER_TILE_WIDTH),
				   (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS+WATER_TILE_HEIGHT));
			g_xMainWnd.DrawWithGDI(rc, NULL, RGB(0, 255, 255), 1);
*/
	
			INT nCurrCntXRate, nCurrCntYRate;
			if ( rXRadius > rYRadius )		
			{
				nCurrCntXRate = nCntX;
				nCurrCntYRate = nCntY + (INT)((nCntY-nY)*(FLOAT)(rXRadius/rYRadius-1.0f));
			}
			else if ( rXRadius < rYRadius )										
			{
				nCurrCntXRate = nCntX + (INT)((nCntX-nX)*(FLOAT)(rYRadius/rXRadius-1.0f));
				nCurrCntYRate = nCntY;
			}
			else
			{
				nCurrCntXRate = nCntX;
				nCurrCntYRate = nCntY;
			}

			rLengthCnt	= sqrt((XLightPos-(nCurrCntXRate*WATER_TILE_WIDTH+WATER_TILE_START_XPOS))*(XLightPos-(nCurrCntXRate*WATER_TILE_WIDTH+WATER_TILE_START_XPOS)) + 
							   (YLightPos-(nCurrCntYRate*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS))*(YLightPos-(nCurrCntYRate*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS)));

/*			SetRect(&rc,
				   (XLightPos),
				   (YLightPos),
				   (XLightPos+5),
				   (YLightPos+5));
			g_xMainWnd.DrawWithGDI(rc, NULL, RGB(255, 0, 0), 1);
*/
			if ( rLengthCnt	<= nRadius )
			{
				nSelectedRedValue	= nRedValue - INT((nRedValue*rLengthCnt*rDrakRate)/(nRadius));
				nSelectedGreenValue	= nGreenValue - INT((nGreenValue*rLengthCnt*rDrakRate)/(nRadius));
				nSelectedBlueValue	= nBlueValue - INT((nBlueValue*rLengthCnt*rDrakRate)/(nRadius));
	/*			SetRect(&rc,
					   (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS),
					   (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS),
					   (nCntX*WATER_TILE_WIDTH+WATER_TILE_START_XPOS+2),
					   (nCntY*WATER_TILE_HEIGHT+WATER_TILE_START_YPOS+2));
				g_xMainWnd.DrawWithGDI(rc, NULL, RGB(255, 0, 0), 1);
	*/			}
			else
			{
				nSelectedRedValue = nSelectedGreenValue = nSelectedBlueValue = 0;
			}

			if ( nSelectedRedValue	 < 0 )		nSelectedRedValue	= 0;
			if ( nSelectedGreenValue < 0 )		nSelectedGreenValue = 0;
			if ( nSelectedBlueValue	 < 0 )		nSelectedBlueValue	= 0;

			if ( m_avLight[nCntY][nCntX].color == 0 )
				m_avLight[nCntY][nCntX].color = RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue); 
			else
			{
				if ( nSelectedRedValue < (INT)RGB_GETBLUE(m_avLight[nCntY][nCntX].color) )
					nSelectedRedValue = (INT)RGB_GETBLUE(m_avLight[nCntY][nCntX].color);
				if ( nSelectedGreenValue < (INT)RGB_GETGREEN(m_avLight[nCntY][nCntX].color) )
					nSelectedGreenValue = (INT)RGB_GETGREEN(m_avLight[nCntY][nCntX].color);
				if ( nSelectedBlueValue < (INT)RGB_GETRED(m_avLight[nCntY][nCntX].color) )
					nSelectedBlueValue = (INT)RGB_GETRED(m_avLight[nCntY][nCntX].color);

				m_avLight[nCntY][nCntX].color =  RGB(nSelectedRedValue, nSelectedGreenValue, nSelectedBlueValue);
			}
		}
	}

	return TRUE;
}




VOID CWater::ShowLightFog(BOOL bShowFog)
{
	if ( g_xMainWnd.Get3DDevice() )
	{
		if( SUCCEEDED(g_xMainWnd.Get3DDevice()->BeginScene()) )
		{
			D3DVECTOR vTrans;
			D3DMATRIX matTrans;
			D3DMATRIX matWorldOriginal;

			g_xMainWnd.Get3DDevice()->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);

//			if ( bShowFog )
//				SetLightRadiusWithElipse(400, 242, 6, 6, 230, 230, 230);
//				SetLightRadiusWithElipse(400, 242, 1, 1, 230, 230, 230);
//				SetLightRadiusWithCircle(400, 242, 8, 230, 230, 230);
/*				SetLightRadiusWithCircle(586, 248, 3, 230, 230, 230);
				SetLightRadiusWithCircle(604, 248, 3, 230, 230, 230);
*///				SetLightRadiusWithRing(400, 242, 7, 230, 230, 230, 8, 230, 230, 230);
			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ZERO);
			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR);

/*			BYTE bOpa = 255;
			D3DMATERIAL7 mtrl;
			D3DUtil_InitMaterial(mtrl, 
								 (FLOAT)255/255.0f,
								 (FLOAT)255/255.0f,
								 (FLOAT)255/255.0f);
			mtrl.diffuse.a = (bOpa+1)/255.0f;
			g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
			SetBlendRenderState(g_xMainWnd.Get3DDevice(), _BLEND_NORMAL, mtrl);
*/
			vTrans.x = -400; vTrans.y = 300; vTrans.z = 0;
			D3DUtil_SetTranslateMatrix(matTrans, vTrans);
			g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matTrans);
//			g_xMainWnd.Get3DDevice()->SetTexture(0, NULL);


			static int a = 0;
			static int b = 0;
			static float scrlcnt = 0.0f;
			if ( scrlcnt >= WATER_NUM_CNTX_LIGHTTILE )		scrlcnt = 0;
			a++;
			if ( a >= 1 )
			{
				for ( INT nCntY = 0; nCntY < (WATER_NUM_CNTY_LIGHTTILE+1); nCntY++ )
				{
					FLOAT av = (FLOAT)((FLOAT)nCntY/(FLOAT)WATER_NUM_CNTY_LIGHTTILE);

					for ( INT nCntX = 0; nCntX < (WATER_NUM_CNTX_LIGHTTILE+1); nCntX++ )
					{
						FLOAT au = (FLOAT)((FLOAT)nCntX/(FLOAT)WATER_NUM_CNTX_LIGHTTILE) + scrlcnt;
						if ( au > 1 )							au = 1-au;
						FLOAT az = m_avLight[nCntY][nCntX].z;
						if ( b > 10 )
						{
//							az = (FLOAT)GetRandomNum(0, 50);
						}
						FLOAT ax = /*(FLOAT)GetRandomNum(0, 10) + */(FLOAT)(WATER_TILE_START_XPOS+(nCntX*WATER_TILE_WIDTH));
						FLOAT ay = /*(FLOAT)GetRandomNum(0, 1) + */(FLOAT)(-WATER_TILE_START_YPOS-(nCntY*WATER_TILE_HEIGHT));

//						if ( av > 1 )							av = 1-av;
						
						m_avLight[nCntY][nCntX] = D3DLVERTEX(D3DVECTOR(ax, ay, az),
								  							 m_dwLightColor, RGB(0, 0, 0), au, av);
					}
				}
				memcpy(m_avSaveLight, m_avLight, sizeof(D3DLVERTEX)*(WATER_NUM_CNTY_LIGHTTILE+1)*(WATER_NUM_CNTX_LIGHTTILE+1));
				a = 0;
			}
			scrlcnt += 0.0006f;
			if ( b > 10 )
			{
				b = 0;
			}
			b++;

			g_xMainWnd.Get3DDevice()->SetTexture(0, D3DTextr_GetSurface(m_szWater[m_bCurrTexIdx]));

			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
			g_xMainWnd.Get3DDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
														  D3DFVF_LVERTEX,
														  m_avLight, WATER_NUM_LIGHTTILE_VERTICES, 
														  m_pwLightIndices, WATER_NUM_LIGHTTILE_INDICES, NULL );
			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);

//			ResetBlendenderState(g_xMainWnd.Get3DDevice());
			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ONE);
			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
			g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);

			g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);

			g_xMainWnd.Get3DDevice()->EndScene();
		}
	}
}

⌨️ 快捷键说明

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