当前位置: 首页>>代码示例>>C++>>正文


C++ Drawable::boundingRect方法代码示例

本文整理汇总了C++中Drawable::boundingRect方法的典型用法代码示例。如果您正苦于以下问题:C++ Drawable::boundingRect方法的具体用法?C++ Drawable::boundingRect怎么用?C++ Drawable::boundingRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drawable的用法示例。


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

示例1: collide

bool Drawable::collide(Drawable &item)
{
   Rect rect1 = item.boundingRect();
   Rect rect2 = boundingRect();

   Point points1[4];
   points1[0] = rect1.top_right();
   points1[1] = rect1.top_left();
   points1[2] = rect1.bottom_left();
   points1[3] = rect1.bottom_right();

   Point points2[4];
   points2[0] = rect2.top_right();
   points2[1] = rect2.top_left();
   points2[2] = rect2.bottom_left();
   points2[3] = rect2.bottom_right();

   for (int i = 0; i < 4; ++i)
   {
      /*
	If only on corner of this is on item, or if only one of the
	item corner is on this, we return true because it collides.
	Otherwisely, we return false since it doesn't.
      */

      if (isOn(points1[i]))
	 return true;
      if (item.isOn(points2[i]))
	 return true;
   }
   return false;
}
开发者ID:bruni68510,项目名称:Joyau,代码行数:32,代码来源:Drawable.cpp

示例2: collide

bool GameMap::collide(Drawable &spr)
{
   DrawableRect tmp;
   if (colH != -1)
   {
      Rect rect = spr.boundingRect();
      tmp.setPos(rect.x, rect.y + rect.h - colH);
      tmp.resize(rect.w, colH);
   }
   Drawable &col = colH != -1 ? tmp : spr;

   for (unsigned int i = 0; i < tiles.size(); ++i)
   {
      Sprite &tile = tilesets[tiles[i].tileset];
      tile.setTile(tiles[i].tileX, tiles[i].tileY, tileWidth, tileHeight);
      
      // Coord relative to the map !
      tile.setPos(getX() + tiles[i].x, getY() + tiles[i].y);

      Line line;

      if (tiles[i].type.right)
      {
	 line.setPos(getX() + tiles[i].x + tileWidth, getY() + tiles[i].y);
	 line.setPoint(getX() + tiles[i].x + tileWidth, 
		       getY() + tiles[i].y + tileHeight);
	 if (col.collide(line))
	    return true;
      }

      if (tiles[i].type.left)
      {
	 line.setPos(getX() + tiles[i].x, getY() + tiles[i].y);
	 line.setPoint(getX() + tiles[i].x, getY() + tiles[i].y + tileHeight);
	 if (col.collide(line))
	    return true;
      }

      if (tiles[i].type.up)
      {
	 line.setPos(getX() + tiles[i].x, getY() + tiles[i].y);
	 line.setPoint(getX() + tiles[i].x + tileWidth, getY() + tiles[i].y);
	 if (col.collide(line))
	    return true;
      }

      if (tiles[i].type.down)
      {
	 line.setPos(getX() + tiles[i].x, getY() + tiles[i].y + tileHeight);
	 line.setPoint(getX() + tiles[i].x + tileWidth, 
		       getY() + tiles[i].y + tileHeight);
	 if (col.collide(line))
	    return true;
      }

      if (tiles[i].type.content)
	 if (col.collide(tile))
	    return true; // If it collides with only one tile, it collides..
   }
   return false; // It didn't collide with any tiles.
}
开发者ID:Epictetus,项目名称:Joyau,代码行数:61,代码来源:GameMap.cpp


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