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

📄 cbshadow.cpp

📁 赤壁之战的游戏源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}
		}
		//lwc旧的透明阴影
		////////////////////////////////////////////////////////
	}// End of for(i)

}

/////////////////////
/////////////////////
// 显示更新一个区域的阴影
// nX, nY	:	中心位置,以格子为单位
// nXLast, nYLast:	上一次的坐标
// nRange	:	单元的视野大小,以格子为单位
void SHADOW_Draw( int nX, int nY, int nXLast, int nYLast, int nRange )
{
	int i,j;
	WORD codeR;
	struct MAP_REGION_CODE_STRUCT stctR;
	int bOdd;
	int nDrawX, nDrawY;
	int nDrawXLast, nDrawYLast;

	// draw current position
	nDrawX = nX, nDrawY = nY;
	codeR = MAP_GetRegionData( nDrawX, nDrawY );
	MAP_RegionDeCode( codeR, &stctR );

	if( stctR.nShadow != 0 )
	{	
		stctR.nShadow = 0 ;///nVal;//lwc
		SHADOW_DrawItem( nDrawX, nDrawY,0, &DRAW_rcClient );//lwc

		// 缩略图
		MINI_SetGroundData( nDrawX, nDrawY, 0 );
	}
	//lwc新的阴影
	if( cMap_shadowEx[nDrawX][nDrawY]==0 );
	{
		stctR.nShadowEx = 0 ;///nVal;//lwc
		SHADOW_DrawItem( nDrawX, nDrawY,0, &DRAW_rcClient );//lwc
	}
	Assert( cMap_shadowEx[nDrawX][nDrawY]>=0 );
	cMap_shadowEx[nDrawX][nDrawY]++;

	codeR = MAP_RegionEnCode( stctR );
	MAP_SetRegionData( nDrawX, nDrawY, codeR );
	
	bOdd = nY&1;
	for( i=0; i< nRange; i++ )//lwc < 改==
	for( j=0; j< ((i+1)<<3); j++ )
	{
		nDrawX = nX + MAP_ptSenser[bOdd][i][j].x;
		nDrawY = nY + MAP_ptSenser[bOdd][i][j].y;
		if( nDrawX < 0 || nDrawX >= MAP_Lib.szNum.cx)	continue;
		if( nDrawY < 0 || nDrawY >= MAP_Lib.szNum.cy)	continue;
		codeR = MAP_GetRegionData( nDrawX, nDrawY );
		MAP_RegionDeCode( codeR, &stctR );  
		if( stctR.nShadow != 0 )
		{//打开全黑的一层;
			stctR.nShadow = 0;
			SHADOW_DrawItem( nDrawX, nDrawY, stctR.nShadow, &DRAW_rcClient );

			// 缩略图
			MINI_SetGroundData( nDrawX, nDrawY, 0 );
		}

		////////////////////////////////////////////////////////
		//lwc新的透明阴影
        if( i != nRange-1)
        {//贴透明阴影
			if( cMap_shadowEx[nDrawX][nDrawY]==0 );
			{
				stctR.nShadowEx = 0 ;///nVal;//lwc
				SHADOW_DrawItem( nDrawX, nDrawY,0, &DRAW_rcClient );//lwc

				// 缩略图
//				MINI_SetGroundData( nDrawX, nDrawY, 0 );
			}
			Assert( cMap_shadowEx[nDrawX][nDrawY]>=0 );
			cMap_shadowEx[nDrawX][nDrawY]++;
		}
		else
		{   
            if (cMap_shadowEx[nDrawX][nDrawY]==0)
            {
                stctR.nShadowEx = 1;//lwc
                SHADOW_DrawItem( nDrawX, nDrawY, stctR.nShadowEx, &DRAW_rcClient ); //lwc

				// 缩略图
				MINI_SetGroundData( nDrawX, nDrawY, 0 );
            }
		}
		//lwc新的透明阴影
		////////////////////////////////////////////////////////
				
		codeR = MAP_RegionEnCode( stctR );
		MAP_SetRegionData( nDrawX, nDrawY, codeR );   //lwc
	}// End of for(i)

	//lwc老的阴影
	nDrawXLast = nXLast, nDrawYLast = nYLast;
	cMap_shadowEx[nDrawXLast][nDrawYLast]--;//
	Assert( cMap_shadowEx[nDrawXLast][nDrawYLast]>=0 );
	if (cMap_shadowEx[nDrawXLast][nDrawYLast]==0)
	{
		codeR = MAP_GetRegionData( nDrawXLast, nDrawYLast );
		MAP_RegionDeCode( codeR, &stctR );

		stctR.nShadowEx = 1 ;///nVal;//lwc
		SHADOW_DrawItem( nDrawXLast, nDrawYLast,1, &DRAW_rcClient );//lwc

		codeR = MAP_RegionEnCode( stctR );
		MAP_SetRegionData( nDrawXLast, nDrawYLast, codeR );
	}
	
	bOdd = nYLast&1;
	for( i=0; i< nRange; i++ )
	for( j=0; j< ((i+1)<<3); j++ )
	{
		nDrawXLast = nXLast + MAP_ptSenser[bOdd][i][j].x;//相对于
		nDrawYLast = nYLast + MAP_ptSenser[bOdd][i][j].y;
		if( nDrawXLast < 0 || nDrawXLast >= MAP_Lib.szNum.cx)	continue;
		if( nDrawYLast < 0 || nDrawYLast >= MAP_Lib.szNum.cy)	continue;

		////////////////////////////////////////////////////////
		//lwc旧的透明阴影
		if( i != nRange-1)
		{
			cMap_shadowEx[nDrawXLast][nDrawYLast]--;
			Assert( cMap_shadowEx[nDrawXLast][nDrawYLast]>=0 );
			if (cMap_shadowEx[nDrawXLast][nDrawYLast]==0)
			{
				codeR = MAP_GetRegionData( nDrawXLast, nDrawYLast );
				MAP_RegionDeCode( codeR, &stctR );  

				stctR.nShadowEx = 1;//lwc
				SHADOW_DrawItem( nDrawXLast, nDrawYLast, 1, &DRAW_rcClient ); //lwc

				codeR = MAP_RegionEnCode( stctR );
				MAP_SetRegionData( nDrawXLast, nDrawYLast, codeR );   //lwc
			}
		}
		//lwc旧的透明阴影
		////////////////////////////////////////////////////////
	}// End of for(i)
}


/////////////////////
// 显示更新一个区域的阴影,只显示第一层
// nX, nY	:	中心位置,以格子为单位
// nXLast, nYLast:	上一次的坐标
// nRange	:	单元的视野大小,以格子为单位
void SHADOW_Draw0( int nX, int nY, int nXLast, int nYLast, int nRange )
{
	int i,j;
	WORD codeR;
	struct MAP_REGION_CODE_STRUCT stctR;
	int bOdd;
	int nDrawX, nDrawY;

	// draw current position
	nDrawX = nX, nDrawY = nY;
	codeR = MAP_GetRegionData( nDrawX, nDrawY );
	MAP_RegionDeCode( codeR, &stctR );

	if( stctR.nShadow != 0 )
	{	
		stctR.nShadow = 0 ;///nVal;//lwc
		SHADOW_DrawItem( nDrawX, nDrawY,0, &DRAW_rcClient );//lwc

		// 缩略图
		MINI_SetGroundData( nDrawX, nDrawY, 0 );
	}

	codeR = MAP_RegionEnCode( stctR );
	MAP_SetRegionData( nDrawX, nDrawY, codeR );
	
	bOdd = nY&1;
	for( i=0; i< nRange; i++ )//lwc < 改==
	for( j=0; j< ((i+1)<<3); j++ )
	{
		nDrawX = nX + MAP_ptSenser[bOdd][i][j].x;
		nDrawY = nY + MAP_ptSenser[bOdd][i][j].y;
		if( nDrawX < 0 || nDrawX >= MAP_Lib.szNum.cx)	continue;
		if( nDrawY < 0 || nDrawY >= MAP_Lib.szNum.cy)	continue;
		codeR = MAP_GetRegionData( nDrawX, nDrawY );
		MAP_RegionDeCode( codeR, &stctR );  
		if( stctR.nShadow != 0 )
		{//打开全黑的一层;
			stctR.nShadow = 0;
			SHADOW_DrawItem( nDrawX, nDrawY, stctR.nShadow, &DRAW_rcClient );

			// 缩略图
			MINI_SetGroundData( nDrawX, nDrawY, 0 );
		}
				
		codeR = MAP_RegionEnCode( stctR );
		MAP_SetRegionData( nDrawX, nDrawY, codeR );   //lwc
	}// End of for(i)
}
/////////////////////

/////////////////////
void SHADOW_Update2Back( CONST RECT *prcCut /*=NULL*/, BOOL bFront /*=FALSE*/ )
{
	if( SHADOW_bEnable == FALSE )	return;	// if disable shadow, do nothing

	POINT ptDest;
	RECT rcSrc;
	if( prcCut == NULL )
	{
		ptDest.x = DRAW_rcClient.left, 
		ptDest.y = DRAW_rcClient.top;
		rcSrc.left = rcSrc.top = 0;
		rcSrc.right = DRAW_rcClient.right - DRAW_rcClient.left;
		rcSrc.bottom = DRAW_rcClient.bottom - DRAW_rcClient.top;
	}
	
	// draw from shadow back surface to back buffer
	SHADOW_sBack.BltToBack( ptDest, &rcSrc );

	// draw from back buffer to front buffer
	if( bFront )
		DDC_UpdateScreen( &DRAW_rcClient );
}

// redraw all the shadows in client area
void SHADOW_DrawAll( LPRECT prcCut/*=NULL*/ )
{
	if( SHADOW_bEnable == FALSE )	return;	// if disable shadow, do nothing

	int i,j;
	if( prcCut == NULL )
		prcCut = &DRAW_rcClient;	// 缺省时为客户区

	// 用黑色填充背景面
	RECT rect;
	SetRect( &rect, prcCut->left, prcCut->top, prcCut->right, prcCut->bottom );
	OffsetRect( &rect, -DRAW_rcClient.left, -DRAW_rcClient.top );
	if( !SHADOW_sBack.Erase( 0, &rect ) )// red, RGB(255,0,0)//lwc
		OutputDebugString( "Erase error!\n" );

	// 画亮部
	int nShadow=0;
	for( j=DRAW_rcScreen.top; j<DRAW_rcScreen.bottom; j++ )
	for( i=DRAW_rcScreen.left; i<DRAW_rcScreen.right; i++ )
	{
		WORD codeR = MAP_GetRegionData( i, j );
		struct MAP_REGION_CODE_STRUCT stctR;
		MAP_RegionDeCode( codeR, &stctR );
		//
		if( stctR.nShadow != MAP_SHADOW_NONE 
			&& stctR.nShadowEx == 0 )
			SHADOW_DrawItem( i, j, stctR.nShadow, prcCut );
	}
	for( j=DRAW_rcScreen.top; j<DRAW_rcScreen.bottom; j++ )
	for( i=DRAW_rcScreen.left; i<DRAW_rcScreen.right; i++ )
	{
		WORD codeR = MAP_GetRegionData( i, j );
		struct MAP_REGION_CODE_STRUCT stctR;
		MAP_RegionDeCode( codeR, &stctR );
		if( stctR.nShadowEx == 1 )
			SHADOW_DrawItem( i, j,stctR.nShadowEx, prcCut );
	}
}

// 拷贝阴影背景面上保留的区域到新的位置
inline void SHADOW_MoveBack( POINT ptDest, LPRECT prcSrc )
{
	ptDest.x -= DRAW_rcClient.left,
	ptDest.y -= DRAW_rcClient.top;
	RECT rect;
	rect.left = prcSrc->left - DRAW_rcClient.left,
	rect.top = prcSrc->top - DRAW_rcClient.top,
	rect.right = prcSrc->right - DRAW_rcClient.left,
	rect.bottom = prcSrc->bottom - DRAW_rcClient.top;
	SHADOW_sBack.BltSurface( ptDest.x, ptDest.y, 
		SHADOW_sBack.GetSurface(), &rect, DDBLTFAST_NOCOLORKEY );
}
/////////////////////

/////////////////////
// enable or disable shadow
// bEnable	:	enable or disable shadow
void SHADOW_Enable( BOOL bEnable/* = TRUE*/ )
{
	SHADOW_bEnable = bEnable;
	MINI_DrawAll( 1-bEnable );
	SHADOW_DrawAll();
}

// test if shadow is enabled
// return :	TRUE if enabled
BOOL SHADOW_IfEnabled()
{
	return SHADOW_bEnable;
}

// test if this point is under the shadow
// nX, nY	:	point to test
// return	:	MAP_SHADOW_NONE if it is blanked
//				else returns the content of stctR.nShadow
inline int SHADOW_IfBlanked( int nX, int nY )
{
	WORD codeR = MAP_GetRegionData( nX, nY );
	struct MAP_REGION_CODE_STRUCT stctR;
	MAP_RegionDeCode( codeR, &stctR );
	if( SHADOW_bEnable == FALSE )
		return 0;	// 阴影全部打开
	if( stctR.nShadow == MAP_SHADOW_NONE )
		return MAP_SHADOW_NONE;	// 被全黑的影子遮挡
//	if( cMap_shadowEx[nX][nY] != 0 )
//		return 1;	// 被半透明阴影遮挡
	if( stctR.nShadowEx == 1 )
		return 1;
	return 0;	// 没有被遮挡
}
/////////////////////

⌨️ 快捷键说明

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