Ejemplo n.º 1
0
void CCommander::Select(float dt)
{
	hgeRect* rect = m_pSelectSqure->GetRect();
	if(m_pHge->Input_KeyDown(HGEK_LBUTTON))m_IsOneSlt = false;
	if(m_pHge->Input_GetKeyState(HGEK_LBUTTON))
	{
		if(m_pSelectSqure->IsPress())//多选
		{			
			for(UNITS_ITR itr = m_units->begin();itr != m_units->end();itr ++)
			{
				CUnit* unit = *itr;
				if (rect->Intersect(unit->GetRect()))
				{
					if (!unit->IsSelected() && unit->m_camp == m_camp)
					{
						unit->SetSelected(true);
						m_IsOneSlt = true;
					}
				}
				else
				{
					if (unit->IsSelected())
					{
						unit->SetSelected(false);
					}
				}
			}

		}else//单选
		{
			for(UNITS_ITR itr = m_units->begin();itr != m_units->end();itr ++)
			{
				CUnit* unit = *itr;
				if(unit->IsSelected())
				{
					unit->SetSelected(false);
				}
			}
			for(UNITS::reverse_iterator itr = m_units->rbegin();itr != m_units->rend();itr ++)
			{
				CUnit* unit = *itr;
				Point pos = m_pSelectSqure->GetMousePoint();
				if(unit->GetRect()->TestPoint(pos.x, pos.y))
				{
					if(!unit->IsSelected())
					{
						unit->SetSelected(true);
						if(unit->m_camp == m_camp)
						m_IsOneSlt = true;
					}
					break;
				}
			}

		}
	}
}
Ejemplo n.º 2
0
void CCommander::Move(float dt)
{
	if(m_pHge->Input_KeyDown(HGEK_RBUTTON))//右键行走
	{
		Point pos = m_pSelectSqure->GetMousePoint();
		CUnit* tagetunit = NULL;
		bool attack = false;
		for(UNITS_ITR itr = m_units->begin();itr != m_units->end();itr ++)
		{
			CUnit* unit = *itr;
			if (unit->GetRect()->TestPoint(pos.x, pos.y))
			{
				if (unit->m_camp + m_camp == 0) 
				{
					attack = true;
					tagetunit = unit;
				}
			}
		}

		POS_LIST* list = NULL;
		//if(!attack)
			list = CUnit::GetPointList(
			pos.x/m_pMap->m_tileWidth,
			pos.y/m_pMap->m_tileHeight,
			m_pMap->m_map);

		for(UNITS_ITR itr = m_units->begin();itr != m_units->end();itr ++)
		{
			CUnit* unit = *itr;
			if(unit->IsSelected() && unit->m_camp == m_camp)
			{
				if(attack)
				{
					unit->SetAttackTaget(tagetunit);
				}
				//else
				//{
					if(list->size() > 0)
					{
						long pos = list->front();
						float posx = (POS_X(pos))*m_pMap->m_tileWidth;
						float posy = (POS_Y(pos))*m_pMap->m_tileHeight;
						unit->SetDst(Point(posx,posy));
						list->pop();
					}
				//}
			}
		}
		//if(!attack)
			list->c.clear();
	}
}