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


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

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


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

示例1: fill_shape

static void fill_shape(sf::RenderTarget& target, sf::Shape& shape, int x, int y, sf::Color colour) {
	shape.setPosition(x, y);
	shape.setFillColor(colour);
	setActiveRenderTarget(target);
	target.draw(shape);
	
}
开发者ID:calref,项目名称:cboe,代码行数:7,代码来源:render_shapes.cpp

示例2: frame_shape

static void frame_shape(sf::RenderTarget& target, sf::Shape& shape, int x, int y, sf::Color colour) {
	shape.setPosition(x, y);
	shape.setOutlineColor(colour);
	shape.setFillColor(sf::Color::Transparent);
	// TODO: Determine the correct outline value; should be one pixel, not sure if it should be negative
	shape.setOutlineThickness(-1.0);
	target.draw(shape);
}
开发者ID:calref,项目名称:cboe,代码行数:8,代码来源:render_shapes.cpp

示例3:

bool	RectangleBlock::RectangleEquality(const sf::Shape& a, const sf::Shape& b) {
	if(a.GetNbPoints() != b.GetNbPoints() ) return false;

	for(int i=0;i<a.GetNbPoints();i++) {			//egyesével megvizsgáljuk
		if(a.GetPointPosition(i) != b.GetPointPosition(i)) {
			return false;
		}
	}
	return true;
}
开发者ID:pjatacsuk,项目名称:hentes_map_editor,代码行数:10,代码来源:RectangleBlock.cpp

示例4: Controls

void Controls(sf::RenderWindow &Window, sf::Shape &player)
{
    if(Window.GetInput().IsKeyDown(sf::Key::Right))
        player.Move(MOVESPEED, 0);
    else if(Window.GetInput().IsKeyDown(sf::Key::Left))
        player.Move(-MOVESPEED, 0);
    else if(Window.GetInput().IsKeyDown(sf::Key::Down))
        player.Move(0, MOVESPEED);
    else if(Window.GetInput().IsKeyDown(sf::Key::Up))
        player.Move(0, -MOVESPEED);
}
开发者ID:CodingMadeEasy,项目名称:Sfml-1.6,代码行数:11,代码来源:Tut22.cpp

示例5: GetShapeSize

sf::Vector2f GetShapeSize(sf::Shape& s){
    sf::Vector2f Min={0.f,0.f},Max=Min;
    for(unsigned int a=0;a<s.GetNbPoints();a++){
        auto it=s.GetPointPosition(a);
        if(it.x<Min.x)Min.x=it.x;
        if(it.y<Min.y)Min.y=it.y;
        if(it.x>Max.x)Max.x=it.x;
        if(it.y>Max.y)Max.y=it.y;
    }
    return Max-Min;
}
开发者ID:Zeatherann,项目名称:GameEngine,代码行数:11,代码来源:GameEngine.cpp

示例6: ProjectOntoAxis

  void ICollisionSystem::ProjectOntoAxis(const sf::Shape& theShape, const sf::Vector2f& theAxis, float& theMin, float& theMax)
	{
    sf::Vector2f anPoint=theShape.getTransform().transformPoint(theShape.getPoint(0));
  	GQE::Uint32 anPointCount=theShape.getPointCount();
		theMin = (anPoint.x*theAxis.x+anPoint.y*theAxis.y);
		theMax = theMin;
		for (int j = 1; j<anPointCount; j++)
		{
			anPoint=theShape.getTransform().transformPoint(theShape.getPoint(j));
			float Projection = (anPoint.x*theAxis.x+anPoint.y*theAxis.y);

			if (Projection<theMin)
				theMin=Projection;
			if (Projection>theMax)
				theMax=Projection;
		}
	}
开发者ID:ItsJackson,项目名称:gqe,代码行数:17,代码来源:ICollisionSystem.cpp

示例7: Intersects

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

示例8: pointIntersectsShape

bool pointIntersectsShape(int x, int y, sf::Shape shape) {
  // TODO: Hardcoding this is pretty much the dumbest 
  // thing in the history of forever.

  sf::Vector2<float> ltop = shape.GetPointPosition(0);
  sf::Vector2<float> rbot = shape.GetPointPosition(2);

  sf::Rect<float> hitbox(ltop.x, ltop.y, rbot.x, rbot.y);

  return hitbox.Contains(x, y);

}
开发者ID:erik,项目名称:blocks,代码行数:12,代码来源:shape.cpp

示例9: ApplyGradient

void sf::ApplyGradient(sf::Shape& shape, Orientation::Type orientation, const sf::Color& color1, const sf::Color& color2, bool applyOnBorder)
{
    if(orientation != sf::Orientation::NONE)
    {
        sf::FloatRect shapeRect(shape.GetPointPosition(0), sf::Vector2f(0.f,0.f));
        sf::Vector2f rectRightBottomCorner(0.f,0.f);

        // Define left and top limits
        for(unsigned int i = 0; i < shape.GetPointsCount(); ++i)
        {
            sf::Vector2f pointPosition = shape.GetPointPosition(i);
            shapeRect.Left = (pointPosition.x < shapeRect.Left) ? pointPosition.x : shapeRect.Left;
            shapeRect.Top = (pointPosition.y < shapeRect.Top) ? pointPosition.y : shapeRect.Top;
            rectRightBottomCorner.x = (pointPosition.x > rectRightBottomCorner.x) ? pointPosition.x : rectRightBottomCorner.x;
            rectRightBottomCorner.y = (pointPosition.y > rectRightBottomCorner.y) ? pointPosition.y : rectRightBottomCorner.y;
        }
        shapeRect.Width = rectRightBottomCorner.x-shapeRect.Left;
        shapeRect.Height = rectRightBottomCorner.y-shapeRect.Top;

        // Apply gradient
        for(unsigned int i = 0; i < shape.GetPointsCount(); ++i)
        {
            float factor = 0.f;
            sf::Vector2f pointPosition = shape.GetPointPosition(i);
            switch(orientation)
            {
            case Orientation::TOPTOBOTTOM :
                factor = 1-(pointPosition.y-shapeRect.Top)/shapeRect.Height;
                break;

            case Orientation::BOTTOMTOTOP :
                factor = (pointPosition.y-shapeRect.Top)/shapeRect.Height;
                break;

            case Orientation::LEFTTORIGHT :
                factor = 1-(pointPosition.x-shapeRect.Left)/shapeRect.Width;
                break;

            case Orientation::RIGHTTOLEFT :
                factor = (pointPosition.x-shapeRect.Left)/shapeRect.Width;
                break;

            default :
                factor = 1;
                break;
            }
            if(applyOnBorder)
                shape.SetPointOutlineColor(i, sf::Color(factor*color1.r+(1-factor)*color2.r, factor*color1.g+(1-factor)*color2.g, factor*color1.b+(1-factor)*color2.b, factor*color1.a+(1-factor)*color2.a));
            else
                shape.SetPointColor(i, sf::Color(factor*color1.r+(1-factor)*color2.r, factor*color1.g+(1-factor)*color2.g, factor*color1.b+(1-factor)*color2.b, factor*color1.a+(1-factor)*color2.a));
        }
    }
}
开发者ID:eolhing,项目名称:aSFML,代码行数:53,代码来源:Shape.cpp

示例10: draw

void Renderer::draw(sf::Shape const& shape, ZIndex_t zindex, sf::RenderStates const& states)
{
    auto bounds = shape.getGlobalBounds();
    if(isInScreen(bounds))
    {
        m_drawCallbacks.push_back({
            zindex,
            [&shape, states] (sf::RenderTarget& renderer)
            {
                renderer.draw(shape, states);
            }
        });
    }
}
开发者ID:HopsonCommunity,项目名称:ZombieGame,代码行数:14,代码来源:Renderer.cpp

示例11: Collision

void Collision(sf::RenderWindow &Window, sf::Sound &collision, sf::Shape player, sf::Shape &object)
{
    if(player.GetPosition().x + PLAYERWIDTH < object.GetPosition().x ||
       player.GetPosition().x > object.GetPosition().x + OBJECTWIDTH ||
       player.GetPosition().y + PLAYERHEIGHT < object.GetPosition().y ||
       player.GetPosition().y > object.GetPosition().y + OBJECTHEIGHT)
    {
        // No Collision
    }
    else
    {
        collision.Play();
        object.SetPosition(rand() % (ScreenWidth - OBJECTWIDTH), rand() % (ScreenHeight - OBJECTHEIGHT));
    }
}
开发者ID:CodingMadeEasy,项目名称:Sfml-1.6,代码行数:15,代码来源:Tut22.cpp

示例12:

void GUI::Game::Object::draw(sf::RenderWindow& window, boost::shared_ptr<const ::Game::Player> viewer, bool selected) {
    // TODO: Load real graphics and track animations.
    static sf::Shape tmp, circle;
    if (!tmp.GetNbPoints()) {
        tmp.AddPoint(-0.8, -0.4);
        tmp.AddPoint(-0.0, -0.4);
        tmp.AddPoint(-0.0, -0.8);
        tmp.AddPoint(+0.8, -0.0);
        tmp.AddPoint(-0.0, +0.8);
        tmp.AddPoint(-0.0, +0.4);
        tmp.AddPoint(-0.8, +0.4);
        tmp.SetOutlineWidth(0.15);
    }
    if (!circle.GetNbPoints()) {
        circle = sf::Shape::Circle(0, 0, 1, sf::Color(0xff, 0xff, 0xff, 0x44), 0.2, sf::Color(0xff, 0xff, 0xff, 0xdd));
    }

    Vector2<SIUnit::Position> pos = object->getPosition();
    double r = object->getObjectType()->radius.getDouble();

    if (object->getOwner() == viewer) {
        circle.SetColor(sf::Color(0x33, 0x33, 0xcc));
        tmp.SetColor(sf::Color(0x33, 0x33, 0xcc));
    } else {
        circle.SetColor(sf::Color(0xcc, 0x33, 0x00));
        tmp.SetColor(sf::Color(0xdd, 0x00, 0x00));
    }

    if (selected) {
        circle.SetScale(r, r);
        circle.SetPosition(pos.x.getDouble(), pos.y.getDouble());
        window.Draw(circle);
    }

    tmp.SetScale(r, r);
    tmp.SetPosition(pos.x.getDouble(), pos.y.getDouble());
    tmp.SetRotation(-Math::toDegrees(object->getDirection().getDouble()));
    window.Draw(tmp);
}
开发者ID:projectskillz,项目名称:PutkaRTS,代码行数:39,代码来源:Object.cpp

示例13: OrientedBox

void TEALShow::OrientedBox( sf::Shape &s, sf::Color col)
{
	AddTransformedRectanglePoints( s.getLocalBounds(), s.getTransform(), col );
}
开发者ID:HHMedina,项目名称:DePaul-UNI-Projects,代码行数:4,代码来源:TEALShow.cpp

示例14: Shape_point

static sf::Vector2f Shape_point(sf::Shape const& s, unsigned idx)
{
    if (idx >= s.getPointCount())
        throw "point index of shape out of range";
    return s.getPoint(idx);
}
开发者ID:Oberon00,项目名称:jd,代码行数:6,代码来源:SfGraphics.cpp

示例15: toConvexShape

	sf::ConvexShape toConvexShape(const sf::Shape& shape)
	{
		const unsigned int size = shape.getPointCount();

		sf::ConvexShape convexShape;

		// Adapt shape properties
		convexShape.setFillColor(shape.getFillColor());
		convexShape.setOutlineColor(shape.getOutlineColor());
		convexShape.setOutlineThickness(shape.getOutlineThickness());
		convexShape.setPointCount(size);

		// Adapt transform properties
		convexShape.setPosition(shape.getPosition());
		convexShape.setRotation(shape.getRotation());
		convexShape.setScale(shape.getScale());
		convexShape.setOrigin(shape.getOrigin());

		// Adapt texture properties
		convexShape.setTexture(shape.getTexture());
		convexShape.setTextureRect(shape.getTextureRect());

		for (unsigned int i = 0; i < size; ++i)
		{
			convexShape.setPoint(i, shape.getPoint(i));
		}

		return convexShape;
	}
开发者ID:Psykoangel,项目名称:cpp_projects_repo,代码行数:29,代码来源:Shapes.cpp


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