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

📄 maingame.cpp

📁 混乱竞技场的全套代码,客户端资源可以网上搜
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// MainGame.cpp: implementation of the MainGame class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MainGame.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

MainGame::MainGame(CGsEngine*	pEngine)
:CGsGame(pEngine),
m_world(pEngine),
m_tex_game_msg(pEngine),
m_bk_music(pEngine)
{
	m_is_msg_change	= FALSE;
		for( WORD ix=0; ix<2; ix++ )
		{
			for( WORD iy=0; iy<2; iy++ )
			{
//				FLOAT tu = ix;
//				FLOAT tv = iy;
				float fx = m_world.GetViewWidthPix()*ix;
				float fy = m_world.GetViewHeightPix()*iy;

				m_aVertex[ix+iy*2] = D3DTLVERTEX( D3DVECTOR(fx,fy,0.0f),
                                                            0.5f,
															0xffffffff,
															0,
															0, 0 );
			}
		}
	m_want_unit_light	= TRUE;
	m_is_inputing_text	= FALSE;
	m_is_handling_place	= FALSE;
	m_select_magic	= -1;
	//memset(m_magic_list, 0, sizeof(MAGIC_SKILL)*8);
	m_rc_energy		= GRECT(775,100,780,400);
	m_rc_power		= GRECT(775,400,780,400);

}

MainGame::~MainGame()
{

}



LRESULT	MainGame::MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	return CGsGame::MsgProc( uMsg, wParam, lParam );
}



ID MainGame::OnMouseMove(UINT nFlags, GPOINT point)
{
//	if(m_pEngine->TestMouseState(MK_LBUTTON))
//	{
//		Game_Unit*	pUnit	= GetControlUnit();
//		if(pUnit)
//		{
//			LONG x,y;
//			m_world.GetOriginal(x, y);
//			pUnit->query_goto(point.x+x, point.y+y);
//			//pUnit->PlyWalkTo(point.x+x, point.y+y);
//		}
//	}
	ID id_ret = CGsGame::OnMouseMove( nFlags, point );

	m_select_magic	=-1;
	if(point.x>22 && point.x<58)
	{
		int i = (point.y-25)/50;
		if(i<8 && abs(point.y-50-i*50)<18)
		{
			m_select_magic	= i;
		}
	}

	if(id_ret>0)
		return id_ret;
	return id_ret;
}

ID MainGame::OnLButtonDown( UINT nFlags, GPOINT point )			
{ 
	if(m_select_magic>=0)
		return 0;
	ID id_ret = CGsGame::OnLButtonDown( nFlags, point );
	if(id_ret>0)
	{
		m_is_handling_place	= FALSE;
		return id_ret;
	}
	m_is_handling_place	= TRUE;
	Game_Unit*	pUnit	= GetControlUnit();
	if(pUnit)
	{
		LONG x,y;
		m_world.GetOriginal(x, y);
		std::vector<GM_Object*> obj_array;
		if(m_world.select_obj(obj_array, point.x+x, point.y+y)>0)
		{
			int aim_unit=0;
			for(int i=0; i<obj_array.size(); i++)
			{
				if(obj_array[i]->GetID()!=pUnit->GetID())
				{
					aim_unit	= obj_array[i]->GetID();
					Game_Unit*	ptr_unit = (Game_Unit*)m_world.GetObject(aim_unit);
					if(ptr_unit)
					{
						break;
					}
					else
					{
						aim_unit	= 0;
					}
				}
			}
			if(aim_unit>0)
			{
				pUnit->SetControl(TRUE);
				pUnit->m_aim_unit	= aim_unit;
			}
			else
			{
				//pUnit->SetControl(FALSE);
				pUnit->m_is_locate_control=FALSE;
				pUnit->m_is_auto_attack		= FALSE;
				pUnit->query_goto(point.x+x, point.y+y);
			}
		}
		else
		{
			//pUnit->SetControl(FALSE);
			pUnit->m_is_locate_control=FALSE;
			pUnit->m_is_auto_attack	= FALSE;
			pUnit->query_goto(point.x+x, point.y+y);
		}
	}
	return id_ret;
	
}
ID MainGame::OnLButtonUp( UINT nFlags, GPOINT point )				
{ 
	if(m_select_magic>=0)
	{
		Game_Unit*	pUnit	= GetControlUnit();
		if(pUnit)
		{
			if(m_select_magic<4)
			{
				if(pUnit->CanSpell())
				{
					pUnit->query_spell(0, 0, m_magic_list[m_select_magic].type);
					m_magic_list[m_select_magic].use = 1500;
				}
			}
			else
			{
				if(!pUnit->CanRanged() && pUnit->CanSpell() && Sys_GetTime()-pUnit->m_map_query_holder["spell"]>2500)
				{
					pUnit->query_spell(0, 0, m_magic_list[m_select_magic].type);
					m_magic_list[m_select_magic].use = 2500;
				}
			}
		}
		return 0;
	}
	ID id_ret = CGsGame::OnLButtonUp( nFlags, point );
	if(id_ret>0)
		return id_ret;
	return id_ret;
}
ID MainGame::OnLButtonDbClk( UINT nFlags, GPOINT point )			
{ 
	ID id_ret = CGsGame::OnLButtonDbClk( nFlags, point );
	if(id_ret>0)
		return id_ret;
	return id_ret;
	
}
ID MainGame::OnRButtonDown( UINT nFlags, GPOINT point )			
{ 
	ID id_ret = CGsGame::OnRButtonDown( nFlags, point );
	if(id_ret>0)
		return id_ret;
	Game_Unit*	pUnit	= GetControlUnit();
	if(pUnit)
	{
		LONG x,y;
		m_world.GetOriginal(x, y);
		std::vector<GM_Object*> obj_array;
		if(m_world.select_obj(obj_array, point.x+x, point.y+y)>0)
		{
			int aim_unit=0;
			for(int i=0; i<obj_array.size(); i++)
			{
				if(obj_array[i]->GetID()!=pUnit->GetID())
				{
					aim_unit	= obj_array[i]->GetID();
					Game_Unit*	ptr_unit = (Game_Unit*)m_world.GetObject(aim_unit);
					if(ptr_unit)
					{
						break;
					}
					else
					{
						aim_unit	= 0;
					}
				}
			}
			pUnit->m_aim_unit	= aim_unit;
			if(aim_unit>0)
			{
				pUnit->SetControl(FALSE);
			}
			else
			{
				pUnit->SetControl(FALSE);
			}
		}
		else
		{
			pUnit->m_aim_unit	= 0;
			pUnit->SetControl(FALSE);
		}
	}	
	return id_ret;
	
}
ID MainGame::OnRButtonUp( UINT nFlags, GPOINT point )				
{ 
	ID id_ret = CGsGame::OnRButtonUp( nFlags, point );
	if(id_ret>0)
		return id_ret;

	
	return id_ret;
}
ID MainGame::OnRButtonDbClk( UINT nFlags, GPOINT point )			
{ 
	ID id_ret = CGsGame::OnRButtonDbClk( nFlags, point );
	if(id_ret>0)
		return id_ret;
	return id_ret;
	
}


ID MainGame::OnMouseWheel(UINT nFlags, short zDelta, GPOINT point)
{
	ID id_ret = CGsGame::OnMouseWheel(nFlags, zDelta, point);
	if(id_ret>0)
		return id_ret;
	return id_ret;
}

ID MainGame::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if(nChar==VK_RETURN)
	{
		return 0;
	}
	ID id_ret = CGsGame::OnChar(nChar, nRepCnt, nFlags);
	if(id_ret>0)
		return id_ret;

	return id_ret;

}

ID MainGame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	ID id_ret = CGsGame::OnKeyDown(nChar, nRepCnt, nFlags);
	if(id_ret>0)
		return id_ret;

	return id_ret;
}

ID MainGame::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	ID id_ret = CGsGame::OnKeyUp(nChar, nRepCnt, nFlags);
//	if(id_ret>0)
//		return id_ret;
	Game_Unit*	pUnit	= GetControlUnit();
	if(pUnit)
	{
		CGsUIPanel* pPanel = m_pEngine->FindUIFromName("input_msg");
		if(nChar==VK_RETURN)
		{
			if(pPanel)
			{
				if(pPanel->IsFocus())
				{
					pPanel->SetFocus(FALSE);
					pUnit->query_speek(pPanel->GetCaption());
					pPanel->SetCaption("");
				}
				else
				{
					pPanel->SetFocus(TRUE);
				}
			}
			//if(m_is_inputing_text==FALSE)
			//	m_is_inputing_text	= TRUE;
		}
		if(pPanel&&pPanel->IsFocus())
		{
			return id_ret;
		}
		switch(nChar) {
		case VK_SPACE:
			{
				if(pUnit->is_death())
				{
					STRUCT_HANDLE_UNIT	shu;
					shu.action	= GSACT_REVIVE;
					shu.uid_action_type		= 0;
					shu.uid		= pUnit->GetID();
					shu.uid_obj	= pUnit->GetID();
					shu.pos.src_x	= pUnit->m_FlatX;
					shu.pos.src_y	= pUnit->m_FlatY;
					shu.pos.src_h	= pUnit->m_fHeight;
					shu.pos.dest_x	= pUnit->m_FlatX;
					shu.pos.dest_y	= pUnit->m_FlatY;
					shu.pos.dest_h	= pUnit->m_fHeight;
					query_handle_unit(&shu);
				}
			}
			break;
		case VK_F1:
		case VK_F2:
		case VK_F3:
		case VK_F4:
			{
				int sel = nChar - VK_F1;
				if(pUnit->CanSpell())
				{
					pUnit->query_spell(0, 0, m_magic_list[sel].type);
					m_magic_list[sel].use = 1500;
				}
			}
		case VK_F5:
		case VK_F6:
		case VK_F7:
		case VK_F8:
			{
				int sel = nChar - VK_F1;
				if(!pUnit->CanRanged() && pUnit->CanSpell() && Sys_GetTime()-pUnit->m_map_query_holder["spell"]>2500)
				{
					pUnit->query_spell(0, 0, m_magic_list[sel].type);
					m_magic_list[sel].use = 2500;
				}
			}
			break;
		case 'Q':
			{
				pUnit->m_is_auto_attack		= TRUE;
			}
			break;
		case 'A':
//		case 'a':
			{
				pUnit->m_is_locate_control	= TRUE;
			}
			break;
		case 'S':
//		case 's':
			{
				pUnit->m_is_locate_control	= FALSE;
				pUnit->m_is_auto_attack		= FALSE;
			}
			break;
		default:
			break;
		}
	}
	return id_ret;
}



void MainGame::on_handle_place(void *pData)
{
	if(pData==NULL)
		return;
	STRUCT_HANDLE_PLACE* p	= (STRUCT_HANDLE_PLACE*)pData;
	Game_Unit*	pUnit	= (Game_Unit*)m_world.GetObject(p->uid);
	if(pUnit)
	{
		if(abs(pUnit->m_FlatX-p->pos.src_x)>100)
			pUnit->m_FlatX = p->pos.src_x;
		if(abs(pUnit->m_FlatY-p->pos.src_y)>100)
			pUnit->m_FlatY = p->pos.src_y;
		if(p->pos.src_x==p->pos.dest_x && p->pos.src_y==p->pos.dest_y && p->pos.src_h==p->pos.dest_h)
		{

⌨️ 快捷键说明

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