示例#1
0
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);
	
}
示例#2
0
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);
}
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;
}
示例#4
0
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);
}
示例#5
0
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;
}
示例#6
0
  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;
		}
	}
示例#7
0
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;
}
	void move(std::vector<Snake>& snakes) {
	
		
		int size = snake.size();
		sf::Vector2f t,old=snake[size-1];
		
		
		if (inventory!=NULL) {
			inventory->setPosition(snake[size-1]+sf::Vector2f(15,15));
		};
		if (has_eaten) {
			snake.push_back(snake[size-1]+movedir);
			has_eaten=false;
		} else
			
			//this shit's retarded yo - beware or refactor.
			for (int i = size-1 ; i >=0 ; i--) {
				if (i==size-1) {
					snake[size-1]+=movedir;
					
				//collisions and frags
					for (int sn=0;sn <snakes.size();sn++) {
						for (int y=0;y<=snakes[sn].snake.size();y++) {
							//If we're going through ourselves and we're at the head,skip collission
							if ((snakes[sn].id==id) && (y==size-1)) continue;
							if (sf::FloatRect(snakes[sn].snake[y],sf::Vector2f(20,20)).contains(snake[size-1]+movedir)) {
								
								//std::cout << std::to_string(id) << " crash " << std::to_string(snake2.id) << " " <<  std::to_string(y) << "\n";
							
								if (id!=snakes[sn].id) {snakes[sn].score+=1;}
								else score--;
								reset();
								return;
							};
						}
					};
				}
				else {
					t=snake[i];
					snake[i]=old;
					old=t;
				};
				
				//wrap-around
				if (snake[i].x<-15) 
					snake[i].x=XRES-30;
				else if (snake[i].x>XRES)
					snake[i].x=-15;
				
				if (snake[i].y<-15) 
					snake[i].y=YRES-30;
				else if (snake[i].y>YRES)
					snake[i].y=-15;	
			};
	};
示例#9
0
文件: shape.cpp 项目: erik/blocks
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);

}
示例#10
0
文件: Shape.cpp 项目: eolhing/aSFML
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));
        }
    }
}
示例#11
0
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);
            }
        });
    }
}
示例#12
0
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));
    }
}
示例#13
0
void TestEntity::move(float dt)
{
    x += dx*dt;
    y += dy*dt;
    if (x < -(this->shape->maxSize))
    {
        x = WINDOW_X + shape->maxSize;
    }
    else if (x > WINDOW_X + this->shape->maxSize)
    {
        x = -(this->shape->maxSize);
    }
    if (y < -(this->shape->maxSize))
    {
        y = WINDOW_Y + shape->maxSize;
    }
    else if (y > WINDOW_Y + this->shape->maxSize)
    {
        y = -(this->shape->maxSize);
    }
    graphics.SetPosition(x, y);
}
示例#14
0
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);
}
示例#15
0
void TEALShow::OrientedBox( sf::Shape &s, sf::Color col)
{
	AddTransformedRectanglePoints( s.getLocalBounds(), s.getTransform(), col );
}
示例#16
0
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);
}
示例#17
0
	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;
	}
示例#18
0
void TEALShow::AABB( sf::Shape &s, sf::Color col)
{
	Box( s.getGlobalBounds(), col);
}
示例#19
0
void Game::setTextures(sf::Shape& shape, std::string name)
{
    shape.setTexture(&textureManager.getRef(name));
}
	bool collide(sf::Shape& obj) {
		sf::FloatRect head(snake[snake.size()-1],sf::Vector2f(30,30));
		return head.intersects(obj.getGlobalBounds());
	};
示例#21
0
	bool ICollisionSystem::Intersection(sf::Shape& theMovingShape, sf::Shape& theOtherShape, sf::Vector2f& theMinimumTranslation)
	{
		//Exit if either shape is empty;
		if(theMovingShape.getPointCount()==0 || theOtherShape.getPointCount()==0)
			return false;
		//Variables
		std::vector<sf::Vector2f> anAxes;
		Uint32 anIndex;
		sf::Vector2f anSmallestAxis;
		double anOverlap=std::numeric_limits<double>::max();
		Uint32 anMovingPointCount=theMovingShape.getPointCount();
		Uint32 anOtherPointCount=theOtherShape.getPointCount();
		sf::Vector2f anPointA, anPointB;
		//Axes for this object.
		for(anIndex=0;anIndex<anMovingPointCount-1;++anIndex)
		{
      anPointA=theMovingShape.getPoint(anIndex);
      anPointB=theMovingShape.getPoint(anIndex+1);
      anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		}
    anPointA=theMovingShape.getPoint(anMovingPointCount-1);
    anPointB=theMovingShape.getPoint(0);
		anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		//Axes for other object.
		for(anIndex=0;anIndex<theOtherShape.getPointCount()-1;++anIndex)
		{
      anPointA=theOtherShape.getPoint(anIndex);
      anPointB=theOtherShape.getPoint(anIndex+1);
      anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		}
    anPointA=theOtherShape.getPoint(anOtherPointCount-1);
    anPointB=theOtherShape.getPoint(0);
		anAxes.push_back(NormalizeVector(sf::Vector2f(anPointB.y - anPointA.y, -(anPointB.x - anPointA.x))));
		for(anIndex=0;anIndex<anAxes.size();++anIndex)
		{
			float anMinA, anMaxA, anMinB, anMaxB;
			// ... project the points of both OBBs onto the axis ...
			ProjectOntoAxis(theMovingShape,anAxes[anIndex], anMinA, anMaxA);
			ProjectOntoAxis(theOtherShape,anAxes[anIndex], anMinB, anMaxB);
			// ... and check whether the outermost projected points of both OBBs overlap.
			// If this is not the case, the Seperating Axis Theorem states that there can be no collision between the rectangles
			if(!((anMinB<=anMaxA)&&(anMaxB>=anMinA)))
			{
				return false;
			}
		  double o;
      if(anMinB<=anMaxA)
        o=anMaxA-anMinB;
      else
        o=anMaxB-anMinA;
      if(o<anOverlap)
      {
        anSmallestAxis=anAxes[anIndex];
        anOverlap=o;
      }
		}
		theMinimumTranslation=anSmallestAxis;
    theMinimumTranslation*=(float)anOverlap;
		return true;
	}
示例#22
0
sf::Vector2f center(const sf::Shape& s)
{
    auto bb = s.getGlobalBounds();
    return {bb.left + 0.5f * bb.width, bb.top + 0.5f * bb.height};
}
示例#23
0
bool TrackChunk::collidesWith(const sf::Shape &shape) const{
    bg::model::ring<sf::Vector2f> ring;
    for (std::size_t i=0; i<shape.getPointCount(); ++i)
        bg::append(ring, shape.getTransform().transformPoint(shape.getPoint(i)));
    return bg::intersects(ring, m_points);
}