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

📄 gm_world.cpp

📁 混乱竞技场的全套代码,客户端资源可以网上搜
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		for(int x=m_rcOriginalCell.left; x<m_rcOriginalCell.right+1; x++)
		{
			int node_pos[3];
			node_pos[0] = GridNodeIndexU(x, y);
			node_pos[1] = GridNodeIndexC(x, y);
			node_pos[2] = GridNodeIndexD(x, y);
			for(int n=0; n<3; n++)
			{
				_MESH_NODE node	= m_aNode[node_pos[n]];
				pVertex[n]	= D3DTLVERTEX( D3DVECTOR(node.xRough - m_rcOriginalPix.left, node.yRough - m_rcOriginalPix.top, 1.0f),
																				   0.5f,
																				   0xff00ff00,
																				   0,
																				   1.0f,
																				   1.0f
																				  );
			}
			if(m_flag_grid_drawing & DRAW_GRID_FRAME)
			{
				hr = pD3dDevice->DrawPrimitive(D3DPT_LINESTRIP , D3DFVF_TLVERTEX, pVertex, 3, 0 );
				if(FAILED(hr))
					return hr;
			}
			if(m_flag_grid_drawing & DRAW_GRID_OBJECT)
			{
				it = m_mapObject.find(x + y*m_num_grid_width);
				if(it != m_mapObject.end())
				{
					if(it->second.size()>0)
					{
						pVertex[0].color	= 0x7fff0000;
						pVertex[1].color	= 0x7fff0000;
						pVertex[2].color	= 0x7fff0000;
						hr = pD3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP , D3DFVF_TLVERTEX, pVertex, 3, 0 );
						if(FAILED(hr))
							return hr;
					}
				}
			}
		}
	}



//	SAFE_DELETE_ARRAY(pVertex);

	return S_OK;
}



BOOL GM_World::PlaceObjectInPoint(GM_Object *pObject)
{
	assert(pObject!=NULL);

	LONG px = pObject->m_FlatX;
	LONG py = pObject->m_FlatY;

	LONG x = px;
	LONG y = py;

	PickRoughGrid(x,y);


	pObject->m_gridX	= x;
	pObject->m_gridY	= y;

	pObject->m_index	= x + y*m_num_grid_width;

	pObject->m_pWorld	= this;

	PickRoughToFlat(px, py);

	x	= px - pObject->m_seize_x - m_cell_width;
	y	= py - pObject->m_seize_y - m_cell_height;

	PickFlatGrid(x,y);
	if(x<0)
		x=0;
	if(x>m_num_grid_width)
		x = m_num_grid_width;
	if(y<0)
		y=0;
	if(y>m_num_grid_height)
		y = m_num_grid_height;

	px	+= pObject->m_seize_x + m_cell_width;
	py	+= pObject->m_seize_y + m_cell_height;

	PickFlatGrid(px,py);
	if(px<0)
		px=0;
	if(px>m_num_grid_width)
		px = m_num_grid_width;
	if(py<0)
		py=0;
	if(py>m_num_grid_height)
		py = m_num_grid_height;

	for(int gy=y; gy<py; gy++)
	{
		for(int gx=x; gx<px; gx++)
		{
			LONG cx=gx;
			LONG cy=gy;
			if(pObject->TestSeize(cx,cy))//a*a + b*b < 1)
			{
				if(gx==m_mouse_grid.x&&gy==m_mouse_grid.y)
				{
					pObject->m_bSelect	= TRUE;
				}
// 				int a = m_mapObject.size();
				INDEX idx = gx + gy*m_num_grid_width;
				m_mapObject[idx].push_back(pObject);
// 				m_mapObject.insert(t_object_map::value_type(gx + gy*m_num_grid_width,pObject));
			}
		}
	}

	return true;
}

BOOL GM_World::AddObject(GM_Object *pObject)
{
	assert(pObject!=NULL);
//	m_apObject.push_back(pObject);
	std::map<ID, GM_Object*>::iterator it	= m_apObject.find(pObject->GetID());
	if(it==m_apObject.end())
	{
		m_apObject[pObject->GetID()]	= pObject;
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}



VOID GM_World::GetRangeDirectionObject(OBJ_MAP &map, LONG nX, LONG nY, float range, GM_Object* obj_shit)
{
/*
	std::map<INDEX, GM_Object*>		mapTemp;

	map.clear();

	float	range_y	= range/m_cell_rate;

	LONG px = nX;
	LONG py = nY;

	LONG x = px;
	LONG y = py;

	PickRoughGrid(x,y);

	PickRoughToFlat(px, py);

	x	= px - range - m_cell_width;
	y	= py - range_y - m_cell_height;

	PickFlatGrid(x,y);

	if(x<0)
		x=0;
	if(x>m_num_grid_width)
		x = m_num_grid_width;
	if(y<0)
		y=0;
	if(y>m_num_grid_height)
		y = m_num_grid_height;

	px	+= range + m_cell_width;
	py	+= range_y + m_cell_height;

	PickFlatGrid(px,py);
	if(px<0)
		px=0;
	if(px>m_num_grid_width)
		px = m_num_grid_width;
	if(py<0)
		py=0;
	if(py>m_num_grid_height)
		py = m_num_grid_height;

	for(int gy=y; gy<py; gy++)
	{
		t_object_map::iterator it = m_mapObject.upper_bound(x + gy*m_num_grid_width);
		if(it==m_mapObject.end())
			break;
		while(it->first <= px + gy*m_num_grid_width && it!=m_mapObject.end())
		{
			if(obj_shit!=it->second)
			{
				if(it->second->TestRange(range, nX, nY))
				{
					mapTemp.insert(std::map<INDEX, GM_Object*>::value_type(it->second->m_index, it->second));
				}
			}
			it++;
		}
	}

	std::map<INDEX, GM_Object*>::iterator	iter	= mapTemp.begin();
	while(iter!=mapTemp.end())
	{
		GM_Object*	pObj	= iter->second;
		float	dd	= (pObj->m_FlatX-nX)*(pObj->m_FlatX-nX) + (pObj->m_FlatY-nY)*(pObj->m_FlatY-nY);
		map.insert(OBJ_MAP::value_type(dd, pObj));
		iter++;
	}
*/


}


VOID GM_World::GetRangeAngleObject(OBJ_MAP &map, LONG nX, LONG nY, float range, GM_Object* obj_shit)
{
/*
	std::map<INDEX, GM_Object*>		mapTemp;

	map.clear();

	float	range_y	= range/m_cell_rate;

	LONG px = nX;
	LONG py = nY;

	LONG x = px;
	LONG y = py;

	PickRoughGrid(x,y);

	PickRoughToFlat(px, py);

	x	= px - range - m_cell_width;
	y	= py - range_y - m_cell_height;

	PickFlatGrid(x,y);

	if(x<0)
		x=0;
	if(x>m_num_grid_width)
		x = m_num_grid_width;
	if(y<0)
		y=0;
	if(y>m_num_grid_height)
		y = m_num_grid_height;

	px	+= range + m_cell_width;
	py	+= range_y + m_cell_height;

	PickFlatGrid(px,py);
	if(px<0)
		px=0;
	if(px>m_num_grid_width)
		px = m_num_grid_width;
	if(py<0)
		py=0;
	if(py>m_num_grid_height)
		py = m_num_grid_height;

	INDEX idx	= y*m_num_grid_width;
	for(int gy=y; gy<py; gy++)
	{
		for(int gx = x; gx<gy; gx++)
		{
			if(m_aTerrain[idx + gx] < 0)
			{
				mapTemp.insert(std::map<INDEX, GM_Object*>::value_type(idx + gx, NULL));
			}
		}
		t_object_map::iterator it = m_mapObject.upper_bound(x + gy*m_num_grid_width);
		//if(it==m_mapObject.end())
		//	break;
		while(it->first <= px + idx && it!=m_mapObject.end())
		{
			if(obj_shit!=it->second && mapTemp.find(it->second->m_index)==mapTemp.end())
			{
				if(it->second->TestRange(range, nX, nY))
				{
					mapTemp.insert(std::map<INDEX, GM_Object*>::value_type(it->second->m_index, it->second));
				}
			}
			it++;
		}
		idx	+=m_num_grid_width;
	}

	std::map<INDEX, GM_Object*>::iterator	iter	= mapTemp.begin();
	LONG dx,dy;
	while(iter!=mapTemp.end())
	{
		GM_Object*	pObj	= iter->second;
		if(pObj)
		{
			dx	= pObj->m_FlatX-nX;
			dy	= pObj->m_FlatY-nY;
		}
		else
		{
			IndexToGrid(iter->first, dx, dy);
			GridCenter(dx,dy);
			dx	-= nX;
			dy	-= nY;
		}
		float	angle	= atan(dy*m_cell_rate/dx);
		if(dx<0)
		{
			angle += const_PI;
		}
		else if(dy<0)
		{
			angle += const_2_PI;
		}
		map.insert(OBJ_MAP::value_type(angle, pObj));
		iter++;
	}
*/


}

VOID GM_World::TriggerThunder(float m_rate, BOOL bLighting)
{
//	m_thunder_alpha	= 0.8f;
//	m_thunder_rate	= m_rate;
//	m_thunder_time	= 0.0f;
//	TriggerEarthquake(10.0f, 0.5f);
//	if(m_pThunder)
//		m_pThunder->RunThunder(m_rcOriginalPix.left + m_pEngine->GetRenderWidth()/2, m_rcOriginalPix.top + m_pEngine->GetRenderHeight());
}

VOID GM_World::TriggerThunderPoint(LONG px, LONG py)
{
//	m_thunder_alpha	= 0.8f;
//	m_thunder_rate	= 3.5;
//	m_thunder_time	= 0.0f;
//	TriggerEarthquake(10.0f, 0.5f);
//	if(m_pThunder)
//		m_pThunder->RunThunder(px, py);
}


VOID GM_World::TriggerRaining(LONG rain, BOOL bThunder)
{
//	if(m_pRain==NULL)
//		return;
//	if(rain>0)
//	{
//		m_pRain->SetRain(rain, 8, bThunder);
//	}
//	else
//	{
//		m_pRain->StopRain();
//	}
}

VOID GM_World::TriggerEarthquake(float fGrade, float time_sec)
{
	m_quake_grade	= fGrade;
	if(m_quake_time<time_sec)
		m_quake_time	= time_sec;
}


VOID GM_World::PlaceTerrainBlock(LONG nX, LONG nY)
{
	m_aTerrain[nX + nY*m_num_grid_width] &= TERRAIN_FLAG_BLOCK;
}

VOID GM_World::PlaceTerrainBarrier(LONG nX, LONG nY)
{
	m_aTerrain[nX + nY*m_num_grid_width] &= TERRAIN_FLAG_BARRIER;
}




VOID GM_World::OnSizeChanged()
{

}

BOOL GM_World::CreateWorld(int width, int height)
{
	assert(m_cell_width!=0 && m_cell_height!=0);

	Cleanup();

	m_scene_width	= width;
	m_scene_height	= height;

 	LONG a	= m_scene_width;
 	LONG b	= m_scene_height;
	PickFlatGrid(a, b);
	m_num_grid_width	= a+1;
	m_num_grid_height	= b+1;
	m_fXOriginalPix		= 0.0f;
	m_fYOriginalPix		= 0.0f;
	m_rcOriginalPix		= GRECT(0,0,0,0);
	m_rcOriginalCell	= GRECT(0,0,0,0);
	m_dwSceneTime	= 0;
	m_dwSceneBaseTime	= m_pEngine->m_dwEngineTime;
	m_dwSceneStopTime	= 0;

	int i,j;
	_MESH_NODE node;
	node.height	= 0;
	node.light	= 1.0;
	for(i=0; i<(m_num_grid_height+1)/2+1; i++)
	{
		for(j=0; j<m_num_grid_width+1; j++)
		{
			node.xFlat	= (float)m_cell_width*j;
			node.xRough	= node.xFlat;
			node.yFlat	= -(float)m_cell_height/2.0*((j+1)%2) + (float)m_cell_height*i;
			node.yRough	= node.yFlat;
 			m_aNode.push_back(node);
		}
	}

	for(i=0; i<m_num_grid_width*m_num_grid_height; i++)
	{
		m_aTerrain.push_back(0);
	}
	
	return TRUE;
}

BOOL GM_World::CreateWorld(const char *strBackground)
{
	m_background.Create(strBackground);
	CGsTexture* pTex = m_background.GetCurrentFrame();
	if(pTex==NULL)
		return FALSE;
	return CreateWorld(pTex->GetWidthEx(), pTex->GetHeightEx());

}

HRESULT GM_World::RestoreSource()
{
//	return m_background.RestoreObjects();

	if(m_ptr_ui_minimap)
		m_ptr_ui_minimap->RestoreSource();

	std::map<ID, GM_Object*>::iterator	it = m_apObject.begin();
	while(it!=m_apObject.end())
	{
		it->second->RestoreSource();
		it++;
	}

	return S_OK;
}

VOID GM_World::ReleaseSource()
{
	if(m_ptr_ui_minimap)
		m_ptr_ui_minimap->ReleaseSource();

	std::map<ID, GM_Object*>::iterator	it = m_apObject.begin();
	while(it!=m_apObject.end())
	{
		it->second->ReleaseSource();
		it++;
	}
//	m_background.ReleaseObjects();
	return;
}

VOID GM_World::SetMinimapUI(GM_UI_Minimap *pUIMinimap)
{
	if(m_ptr_ui_minimap==pUIMinimap)
		return;
	m_ptr_ui_minimap	= pUIMinimap;
	if(m_ptr_ui_minimap)
	{
		m_ptr_ui_minimap->m_pWorld	= this;
	}
	m_ptr_ui_minimap->RestoreSource();
	CalcMinimap();
}

VOID GM_World::CalcMinimap()
{
	if(m_ptr_ui_minimap)
	{
//		float fw	= (float)m_ptr_ui_minimap->m_rcMap.width()/(float)m_scene_width;
//		float fh	= (float)m_ptr_ui_minimap->m_rcMap.height()/(float)m_scene_height;
//		m_ptr_ui_minimap->m_rcView.left	= m_rcOriginalPix.left*fw;
//		m_ptr_ui_minimap->m_rcView.top	= m_rcOriginalPix.top*fh;
//		m_ptr_ui_minimap->m_rcView.right	= m_rcOriginalPix.right*fw;
//		m_ptr_ui_minimap->m_rcView.bottom	= m_rcOriginalPix.bottom*fh;
		m_ptr_ui_minimap->m_rcView.left	= m_rcOriginalPix.left/m_ptr_ui_minimap->m_fScaleW;
		m_ptr_ui_minimap->m_rcView.top	= m_rcOriginalPix.top/m_ptr_ui_minimap->m_fScaleH;
		m_ptr_ui_minimap->m_rcView.right	= m_rcOriginalPix.right/m_ptr_ui_minimap->m_fScaleW;
		m_ptr_ui_minimap->m_rcView.bottom	= m_rcOriginalPix.bottom/m_ptr_ui_minimap->m_fScaleH;
		m_ptr_ui_minimap->m_rcView	+= m_ptr_ui_minimap->m_rcMap.top_left();
	}
}

GM_Object* GM_World::GetObject(ID id)
{
	std::map<ID, GM_Object*>::iterator it	= m_apObject.find(id);
	if(it==m_apObject.end())
		return NULL;
	return it->second;
}

void GM_World::DeleteObject(ID id)
{
	std::map<ID, GM_Object*>::iterator it	= m_apObject.find(id);
	if(it!=m_apObject.end())
	{
		if(it->second)
		{
			delete(it->second);
		}
		m_apObject.erase(it);
	}
	return ;

}

BOOL GM_World::TestActiveRange(LONG x, LONG y)
{
	return x-m_rcOriginalPix.left>-m_active_range &&
		   x-m_rcOriginalPix.right<m_active_range &&
		   y-m_rcOriginalPix.top>-m_active_range &&
		   y-m_rcOriginalPix.bottom<m_active_range;
}

⌨️ 快捷键说明

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