Пример #1
0
/*-------------------------------------------------------------------------------------------------------------------- 
-- FUNCTION: onClickContext
--
-- DATE: 2013/02/28
--
-- REVISIONS: (Date and Description)
--
-- DESIGNER: Luke Tao
--
-- PROGRAMMER: Luke Tao
--
-- INTERFACE: int InputManager::onClickContext(sf::Event mouseEvent, sf::FloatRect menuContext, 
--						sf::FloatRect buildContext, sf::FloatRect playContext)
--					       
--					       sf::Event mouseEvent - the mouse event
--					       sf::FloatRect menuContext - the menu context
--					       sf::FloatRect buildContext - the builder context
--					       sf::Float Rect playContext - the player context
--
-- RETURNS: Context defined values.
--
-- NOTES: This function handles the events of the mouse clicks. It will print out the coordinates of where the
--	  mouse click happens and determines if it is within one of the context buttons. If the mouse click is within
--        the buttons, it will set the current context value and return that value.
----------------------------------------------------------------------------------------------------------------------*/
int InputManager::onClickContext(sf::Event mouseEvent, sf::FloatRect menuContext, sf::FloatRect buildContext, sf::FloatRect playContext)
{
	int x = mouseEvent.mouseButton.x;
	int y = mouseEvent.mouseButton.y;

	std::cout << "x :" << x << " y: " << y << std::endl;
	if(menuContext.contains(x, y))
	{
		//call menu function
		std::cout << "Context changed to menu" << std::endl;
		setCurrentContext(MENU_CONTEXT);
		return MENU_CONTEXT;
	}
	else if(buildContext.contains(x, y))
	{
		//call builder function
		std::cout << "Context changed to builder" << std::endl;
		setCurrentContext(BUILDER_CONTEXT);
		return BUILDER_CONTEXT;
	}	
	else if(playContext.contains(x, y))
	{
		//call player function
		std::cout << "Context changed to player" << std::endl;
		setCurrentContext(PLAYER_CONTEXT);
		return PLAYER_CONTEXT;
	}
	return getCurrentContext();
}
 bool triIntersectRect(sf::Vector2f t1, sf::Vector2f t2, sf::Vector2f t3, sf::FloatRect rect) {
   //the triangle is made by t1, t2 & t2.
   //return true if the triangle & the rectangle intersect
   if ( rect.contains(t1) || rect.contains(t2) || rect.contains(t3) )
     return true;
   if (lineSegInTriangle(t1,t2,t3,sf::Vector2f(rect.left, rect.top), sf::Vector2f(rect.left+rect.width, rect.top))
     || lineSegInTriangle(t1,t2,t3,sf::Vector2f(rect.left+rect.width, rect.top), sf::Vector2f(rect.left+rect.width, rect.top+rect.height))
     || lineSegInTriangle(t1,t2,t3,sf::Vector2f(rect.left+rect.width, rect.top+rect.height), sf::Vector2f(rect.left, rect.top+rect.height))
     || lineSegInTriangle(t1,t2,t3,sf::Vector2f(rect.left, rect.top+rect.height), sf::Vector2f(rect.left, rect.top) ) )
       return true;
   return false;
 }
Пример #3
0
void LayerSet::Cull(const sf::FloatRect& bounds)
{
	if(	bounds.contains(m_boundingBox.left, m_boundingBox.top) ||
		bounds.contains(m_boundingBox.width, m_boundingBox.height) ||
		m_boundingBox.contains(bounds.left, bounds.top) ||
		m_boundingBox.contains(bounds.left + bounds.width, bounds.top + bounds.height))
	{
		m_visible = true;
	}
	else
	{
		m_visible = false;
	}
}
Пример #4
0
//Check collision between a single rectangle and a point
int Level2::checkCollision(const sf::FloatRect &boundingBox, sf::Vector2f &point)
{
	if (boundingBox.contains(point))
	{
		return 1;
	}
	return 0;
}
Пример #5
0
list<Unit*> Joueur::getUnitsInRect(sf::FloatRect rectangleSelection)
{
  list<Unit*> liste;
  list<Unit*>::iterator it;
  for(it = units.begin(); it != units.end(); it++)
    if(rectangleSelection.contains((*it)->getPosition().x + (*it)->getSocleCenter().x, (*it)->getPosition().y + (*it)->getSocleCenter().y)) 
      liste.push_back(*it);
  return liste;
}
Пример #6
0
bool AABBCollision(const sf::FloatRect& box, float x, float y)
{
    return box.contains(x, y);
}
Пример #7
0
bool AABBCollision(const sf::FloatRect& box, const sf::Vector2f& point)
{
    return box.contains(point);
}
Пример #8
0
bool Game::onMouseOver(sf::FloatRect rect)
{
    return rect.contains(State->mouse.getPosition().x,State->mouse.getPosition().y);
}