• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sf::FloatRect类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sf::FloatRect的典型用法代码示例。如果您正苦于以下问题:C++ FloatRect类的具体用法?C++ FloatRect怎么用?C++ FloatRect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了FloatRect类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: intersectedWall

void Player::intersectedWall(const sf::FloatRect &intersection)
{
    if (intersection.intersects(vert_rect))
    {
        if (intersection.top > boundingBox.top + boundingBox.height / 2)
        {
            boundingBox.top -= intersection.height;
        }
        if (intersection.top < boundingBox.top + boundingBox.height / 2)
        {
            boundingBox.top += intersection.height;
        }
    }

    if (intersection.intersects(horz_rect))
    {
        if (intersection.left < boundingBox.left + boundingBox.width / 2)
        {
            boundingBox.left += intersection.width;
        }
        if (intersection.left > boundingBox.left + boundingBox.width / 2)
        {
            boundingBox.left -= intersection.width;
        }
    }

    updateCross();
}
开发者ID:gallowstree,项目名称:PE-Server,代码行数:28,代码来源:Player.cpp


示例2: onClickContext

/*-------------------------------------------------------------------------------------------------------------------- 
-- 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();
}
开发者ID:JohnPayment,项目名称:Project,代码行数:54,代码来源:InputManager.cpp


示例3: triIntersectRect

 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;
 }
开发者ID:bugubugu123,项目名称:Game_Design_Group_4_Project,代码行数:12,代码来源:collisionDetection.cpp


示例4: Cull

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;
	}
}
开发者ID:DioMuller,项目名称:quest-for-the-crown-j,代码行数:14,代码来源:MapLayer.cpp


示例5: theTile

 bool Player::CollisionGeneral(const sf::FloatRect playerRect,bool &kill){
    int maxHeight, minHeight, maxWidth, minWidth;
    bool collision=false;
    minHeight=playerRect.Top/GameConfig::g_config["tileheight"];
    minWidth=playerRect.Left/GameConfig::g_config["tilewidth"];
    maxHeight=(playerRect.Top+playerRect.Height-1)/GameConfig::g_config["tileheight"];
    maxWidth=(playerRect.Left+playerRect.Width-1)/GameConfig::g_config["tilewidth"];

    if(minHeight<0)minHeight=0;
    if(maxHeight>(*m_map)->m_height)maxHeight=(*m_map)->m_height;
    if(minWidth<0)minWidth=0;
    if(maxWidth>(*m_map)->m_width)maxWidth=(*m_map)->m_width;
    for(int y=minHeight;y<=maxHeight;y++){
        for(int x=minWidth;x<=maxWidth;x++){
            if(!(x>=(*m_map)->m_width or y>=(*m_map)->m_height)){
                if((*m_map)->Tile(x,y).kill)kill=true;
                if(((*m_map)->Tile(x,y).fall && IsPrincess() && !(*m_map)->Tile(x,y).princess)||
                ((*m_map)->Tile(x,y).fall && !IsPrincess() && (*m_map)->Tile(x,y).princess)||
                !(*m_map)->Tile(x,y).fall){
                    if((*m_map)->Tile(x,y).solid && !((*m_map)->Tile(x,y).touch && (*m_map)->Tile(x,y).tile.GetColor().a==0)){
                        if((*m_map)->Tile(x,y).fall)(*m_map)->m_tileSet.at(x).at(y).touch=true;
                        sf::FloatRect  theTile(x*GameConfig::g_config["tilewidth"],y*GameConfig::g_config["tileheight"],GameConfig::g_config["tilewidth"],GameConfig::g_config["tileheight"]);
                        if(playerRect.Intersects(theTile)||theTile.Intersects(playerRect)){
                            collision= true;
                        }
                    }
                }
            }
        }
    }
    return collision;
 }
开发者ID:PhiBabin,项目名称:LD21---Escape,代码行数:32,代码来源:Player.cpp


示例6: theTile

bool GameMob::CollisionGeneral(const sf::FloatRect entityRect){
    int maxHeight, minHeight, maxWidth, minWidth;
    minHeight=entityRect.Top/GameConfig::g_config["tileheight"];
    minWidth=entityRect.Left/GameConfig::g_config["tilewidth"];
    maxHeight=(entityRect.Top+entityRect.Height-1)/GameConfig::g_config["tileheight"];
    maxWidth=(entityRect.Left+entityRect.Width-1)/GameConfig::g_config["tilewidth"];

    if(minHeight<0)minHeight=0;
    if(maxHeight>(*m_map)->m_height)maxHeight=(*m_map)->m_height;
    if(minWidth<0)minWidth=0;
    if(maxWidth>(*m_map)->m_width)maxWidth=(*m_map)->m_width;

    for(int y=minHeight;y<=maxHeight;y++){
        for(int x=minWidth;x<=maxWidth;x++){
            if((*m_map)->Tile(x,y).solid){
                sf::FloatRect  theTile(x*GameConfig::g_config["tilewidth"],y*GameConfig::g_config["tileheight"],GameConfig::g_config["tilewidth"],GameConfig::g_config["tileheight"]);
                if(entityRect.Intersects(theTile)||theTile.Intersects(entityRect)){
                    if((*m_map)->Tile(x,y).boomer && (*m_map)->Tile(x,y).color==GameConfig::ColorToNbr(GetColor()))(*m_map)->Explode(x,y);
                    return true;
                }
            }
        }
    }
    return false;
 }
开发者ID:PhiBabin,项目名称:Toisin,代码行数:25,代码来源:GameMob.cpp


示例7: checkCollisionsWithin

bool CollisionCell::checkCollisionsWithin(std::vector<WorldObject *> *_outputCollisions, sf::FloatRect _bounds)
{
	bool collision = false;

	for (unsigned int i = 0; i < m_TouchingWorldObjects.size(); i += 1)
	{
		if (_bounds.intersects(m_TouchingWorldObjects.at(i)->getBounds()))
		{
			bool present = false;

			for (unsigned int j = 0; j < _outputCollisions->size(); j += 1)
			{
				if (_outputCollisions->at(j) == m_TouchingWorldObjects.at(i))
				{
					present = true;
					break;
				}
			}

			if (!present)
			{
				collision = true;
				_outputCollisions->push_back(m_TouchingWorldObjects.at(i));
			}
		}
	}

	return collision;
}
开发者ID:zeno15,项目名称:RTSDevelopement,代码行数:29,代码来源:CollisionCell.cpp


示例8:

std::vector<MapObject*> QuadTreeNode::Retrieve(const sf::FloatRect& bounds, sf::Uint16& searchDepth)
{	
	searchDepth = m_level;
	std::vector<MapObject*> foundObjects;
	sf::Int16 index = m_GetIndex(bounds);

	//recursively add objects of child node if bounds is fully contained
	if(!m_children.empty() && index != -1) 
	{
		foundObjects = m_children[index]->Retrieve(bounds, searchDepth);
	}
	else
	{
		//add all objects of child nodes which intersect test area
		for(auto& child : m_children)
		{
			if(bounds.intersects(child->m_bounds))
			{
				std::vector<MapObject*> childObjects = child->Retrieve(bounds, searchDepth);
				foundObjects.insert(foundObjects.end(), childObjects.begin(), childObjects.end());
			}
		}

	}
	//and append objects in this node
	foundObjects.insert(foundObjects.end(), m_objects.begin(), m_objects.end());
	m_debugShape.setOutlineColor(sf::Color::Red);
	return foundObjects;
}
开发者ID:Kheartz,项目名称:Hexagon-Alpha2-Repos,代码行数:29,代码来源:QuadTreeNode.cpp


示例9: isCollision

bool Game::isCollision(sf::FloatRect box1, sf::FloatRect box2)
{
	bool collision = false;
	if (box1.intersects(box2))
		collision = true;
	return collision;
}
开发者ID:vihanchaudhry,项目名称:ZombieGame,代码行数:7,代码来源:Game.cpp


示例10: getIndex

std::vector<std::shared_ptr<tgd::Entity>> QuadTree::retrieve(sf::FloatRect bounds, sf::Uint16 searchDepth)
{
    searchDepth = mLevel;
    std::vector<std::shared_ptr<tgd::Entity>> foundObjects;
    sf::Int16 index = getIndex(bounds);

    //recursively add objects of child node if bounds is full contained
    if(!mChildren.empty() && index != -1)
    {
        foundObjects = mChildren[index]->retrieve(bounds, searchDepth);
    }
    else
    {
        //add all objects of child nodes which intersect test area
        for(auto& child : mChildren)
        {
            if(bounds.intersects(child->mBounds))
            {
                std::vector<std::shared_ptr<tgd::Entity>> childObjects = child->retrieve(bounds, searchDepth);
                foundObjects.insert(foundObjects.end(), childObjects.begin(), childObjects.end());
            }
        }
    }
    //and append objects in this node
    foundObjects.insert(foundObjects.end(), mObjects.begin(), mObjects.end());

    return foundObjects;
}
开发者ID:jason-bunn,项目名称:SFMLTests,代码行数:28,代码来源:QuadTree.cpp


示例11: while

std::vector<xy::Entity> DynamicTreeSystem::query(sf::FloatRect area, std::uint64_t filter) const
{
    Detail::FixedStack<std::int32_t, 256> stack;
    stack.push(m_root);

    std::vector<xy::Entity> retVal;
    retVal.reserve(256);

    while (stack.size() > 0)
    {
        auto treeID = stack.pop();
        if (treeID == TreeNode::Null)
        {
            continue;
        }

        const auto& node = m_nodes[treeID];
        if (area.intersects(node.fatBounds))
        {
            //TODO it would be nice to precache the filter fetch, but it would miss changes at the component level
            if (node.isLeaf() && node.entity.isValid()
                && (node.entity.getComponent<BroadphaseComponent>().m_filterFlags & filter)) 
            {
                //we have a candidate, stash
                retVal.push_back(node.entity);
            }
            else
            {
                stack.push(node.childA);
                stack.push(node.childB);
            }
        }
    }
    return retVal;
}
开发者ID:JonnyPtn,项目名称:xygine,代码行数:35,代码来源:DynamicTreeSystem.cpp


示例12:

//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;
}
开发者ID:Arqu3,项目名称:Spelprojekt-1,代码行数:9,代码来源:Level2.cpp


示例13: intersects

bool TalkingSprite::intersects(sf::FloatRect rect) const {
    for (auto && it: collisionBoxList) {
        if (rect.intersects(it)) {
            return true;
        }
    }
    return false;
}
开发者ID:NoahKittleson,项目名称:RPG-Engine,代码行数:8,代码来源:TalkingSprite.cpp


示例14: Intersects

bool WorldObjects::Intersects(const sf::FloatRect & bounds)
{
	for (int i = 0; i < Count(); ++i)
	{
		if (bounds.intersects(objects[i]->getGlobalBounds()))
			return true;
	}
	return false;
}
开发者ID:SimonBerggren,项目名称:FlexPim,代码行数:9,代码来源:WorldObjects.cpp


示例15: boundsCheck

bool Level::boundsCheck(sf::FloatRect& bounds)
{
    for (int i = 0; i < activeTiles.size(); ++i) {
        if (bounds.intersects(activeTiles[i].getGlobalBounds()))
            return true;
    }

    return false;
}
开发者ID:GGist,项目名称:SpriteEngine,代码行数:9,代码来源:Level.cpp


示例16:

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;
}
开发者ID:matthieu637,项目名称:risk,代码行数:9,代码来源:Joueur.cpp


示例17: queryRegion

void Quadtree::queryRegion(std::vector<QuadtreeOccupant*> &result, const sf::FloatRect &region) {
	// Query outside root elements
	for (std::unordered_set<QuadtreeOccupant*>::iterator it = _outsideRoot.begin(); it != _outsideRoot.end(); it++) {
		QuadtreeOccupant* oc = *it;
		sf::FloatRect r = oc->getAABB();

		if (oc != nullptr && region.intersects(oc->getAABB()))
			// Intersects, add to list
			result.push_back(oc);
	}

	std::list<QuadtreeNode*> open;

	open.push_back(_pRootNode.get());

	while (!open.empty()) {
		// Depth-first (results in less memory usage), remove objects from open list
		QuadtreeNode* pCurrent = open.back();
		open.pop_back();

		if (region.intersects(pCurrent->_region)) {
			for (std::unordered_set<QuadtreeOccupant*>::iterator it = pCurrent->_occupants.begin(); it != pCurrent->_occupants.end(); it++) {
				QuadtreeOccupant* oc = *it;

				if (oc != nullptr && region.intersects(oc->getAABB()))
					// Visible, add to list
					result.push_back(oc);
			}

			// Add children to open list if they intersect the region
			if (pCurrent->_hasChildren)
			for (int i = 0; i < 4; i++)
			if (pCurrent->_children[i]->getNumOccupantsBelow() != 0)
				open.push_back(pCurrent->_children[i].get());
		}
	}
}
开发者ID:Nuos,项目名称:crawler,代码行数:37,代码来源:Quadtree.cpp


示例18: cull

void MapLayer::cull(sf::FloatRect bounds){
	if (m_type == MapLayerType::TileLayer){
		int tilePatchCount = m_tilePatches.size();
		for (int i = 0; i < tilePatchCount; i++){
			if (bounds.intersects(m_tilePatches[i].aabb))
				m_tilePatches[i].visible = true;
			else
				m_tilePatches[i].visible = false;
		}
		sf::RectangleShape test;
		test.setSize(sf::Vector2f(bounds.width, bounds.height));
		test.setFillColor(sf::Color(255, 0,0, 25));
		test.setOutlineColor(sf::Color::Magenta);
		test.setOutlineThickness(8.f);
		test.setPosition(bounds.left, bounds.top);
		testShapes.back() = test;
	}
}
开发者ID:Stephen321,项目名称:3rdYearProject,代码行数:18,代码来源:MapLayer.cpp


示例19:

	sf::Vector2f CollisionResolver::resolve_inside_bounds(const sf::FloatRect& within, const sf::FloatRect& bounds)
	{
		sf::Vector2f resolved_position(within.Left,within.Top);
		if(within.Left < bounds.Left)
		{
			resolved_position.x = bounds.Left;
		}
		if(within.Left + within.GetWidth() > bounds.Left + bounds.GetWidth())
		{
			resolved_position.x = bounds.Left + bounds.GetWidth() - within.GetWidth();
		}
		if(within.Top < bounds.Top)
		{
			resolved_position.y = bounds.Top;
		}
		if(within.Top + within.GetHeight() > bounds.Top + bounds.GetHeight())
		{
			resolved_position.y = bounds.Top + bounds.GetHeight() - within.GetHeight();
		}
		return resolved_position;
	}
开发者ID:nlguillemot,项目名称:jamoween,代码行数:21,代码来源:collision.cpp


示例20: OnCollide

void Unit::OnCollide(Entity& entity, const sf::FloatRect& overlap)
{
	if (IsDying() || entity.IsDying())
	{
		return;
	}
	switch (entity.GetCollideEffect())
	{
		case FX_REJECTION:
			// repoussement horizontal ?
			if (overlap.GetHeight() < overlap.GetWidth())
			{
				// vers le haut ou le bas
				knocked_dir_ = entity.GetPosition().y > GetPosition().y ? UP : DOWN;
			}
			else // vertical
			{
				// vers la gauche ou la droite
				knocked_dir_ = entity.GetPosition().x > GetPosition().x ? LEFT : RIGHT;
			}
			knocked_start_ = Game::GetInstance().GetElapsedTime();
			knocked_speed_ = KNOCK_INITIAL_SPEED;
			is_knocked_ = true;
			break;

		case FX_STOP:
			{
				Direction dir;
				float dist;
				if (overlap.GetHeight() < overlap.GetWidth())
				{
					dir = entity.GetPosition().y > GetPosition().y ? UP : DOWN;
					dist = overlap.GetHeight();
				}
				else
				{
					dir = entity.GetPosition().x > GetPosition().x ? LEFT : RIGHT;
					dist = overlap.GetWidth();
				}
				Move(dir, dist);
			}
			break;
		case FX_NOTING:
			break;
	}
}
开发者ID:charafsalmi,项目名称:ppd-paris-descartes,代码行数:46,代码来源:Unit.cpp



注:本文中的sf::FloatRect类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sf::Font类代码示例发布时间:2022-05-31
下一篇:
C++ sf::Clock类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap