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

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

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

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



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

示例1: checkCircleCollision

/*
	Name:	checkCircleCollision
	Desc:	given to circles, it will check to see if they are colliding.
	Args:	p_circle1,	the first circle
			p_circle2,	the second circle to check against.
	Rtrn:	bool,	if the two are colliding
*/
bool Game::checkCircleCollision(const sf::CircleShape &p_circle1, const sf::CircleShape &p_circle2)
{
	float xDistance = p_circle1.getPosition().x - p_circle2.getPosition().x;
	float yDistance = p_circle1.getPosition().y - p_circle2.getPosition().y;

	return sqrt((xDistance * xDistance) + (yDistance * yDistance)) < p_circle1.getRadius() + p_circle2.getRadius();
}
开发者ID:Resinderate,项目名称:TimTamGame,代码行数:14,代码来源:Game.cpp


示例2: losango

/*
 *  Mostra na tela os indicadores básicos do jogo:
 *  vidas restantes, HP e pontuação.
 */
void Jogo::exibeHud()
{
    float x = 0.10 * janela.getSize().x;
    float y = 0.15 * janela.getSize().y;

    /* Desenha vidas extras da nave */
    static sf::CircleShape losango(20.0, 4);
    for (int i = 0; i < nave->getVidas(); i++) {
        double deltaX = 2.5 * losango.getRadius();
        losango.setPosition(x + (i * deltaX), y);
        janela.draw(losango); 
    }
    /* Desenha caixa da lifebar */
    y += 3.0 * losango.getRadius();
    static sf::RectangleShape caixa({200.0, 10.0});
    caixa.setPosition(x, y);
    caixa.setFillColor(sf::Color::Blue);
    janela.draw(caixa);

    /* Desenha lifebar com parcial do HP */
    float k = (float) nave->getHP() / nave->getHPMax();
    sf::RectangleShape lifebar({k * caixa.getSize().x,
                                    caixa.getSize().y});
    lifebar.setPosition(x, y);
    lifebar.setFillColor(k > 0.25 ? sf::Color::Green : sf::Color::Red);
    janela.draw(lifebar);

    /* Imprime pontuação (e, se for o caso, mensagem de pausa) */
    y += 2.5 * lifebar.getSize().y;
    sf::String str = "Score: " + std::to_string(nave->getScore());
    if (pausado) str += " (pausa)";
    sf::Text texto(str, fonte, 20);
    texto.setPosition(x, y);
    janela.draw(texto);
}
开发者ID:Turtledorm,项目名称:river-raid,代码行数:39,代码来源:jogo.cpp


示例3: collisionCircle

bool Engine::collisionCircle(sf::FloatRect box1, sf::CircleShape circle)
{
   int d2 = (box1.left-circle.getPosition().x)*(box1.left-circle.getPosition().x) + (box1.top-circle.getPosition().y)*(box1.top-circle.getPosition().y);
   if (d2>pow(circle.getRadius(),2))
      return false;
   else
      return true;
}
开发者ID:WeHaveCookie,项目名称:SoulSpark,代码行数:8,代码来源:Engine.cpp


示例4: set_circle

void set_circle(sf::CircleShape& circle, const float value, const float norm_radius,
				const sf::Vector2f& position, const sf::Color& color)
{
	
	const float radius{sqrt_value_tot_radius(value, norm_radius)};
	
	circle.setRadius(radius);
	circle.setOrigin(radius, radius);
	circle.setPosition(position);
	circle.setFillColor(color);
	
}
开发者ID:janderkkotlarski,项目名称:GUI,代码行数:12,代码来源:Top_Down_V0-2.cpp


示例5: drawParticles

void drawParticles(sf::RenderWindow &window, sf::CircleShape &particle_shape, b2ParticleSystem *particle_system)
{
	for(int i = 0; i < particle_system->GetParticleCount(); i++) //loops through all the particles
	{
		b2Vec2 pos = particle_system->GetPositionBuffer()[i]; //gets the position of the current particle

		if( &pos != NULL ) //if the particle exists
		{
			particle_shape.setPosition( pos.x, pos.y );
			window.draw( particle_shape );
		}
	}
}
开发者ID:niems,项目名称:Roboprototype,代码行数:13,代码来源:robobuild2.cpp


示例6: Ball

 Ball(float mX, float mY)
 {
     shape.setPosition(mX, mY);
     shape.setRadius(defRadius);
     shape.setFillColor(defColor);
     shape.setOrigin(defRadius, defRadius);
 }
开发者ID:Boza-s6,项目名称:cppcon2014,代码行数:7,代码来源:p04.cpp


示例7: initialize

void Particles::initialize() {
  int displayxi = int(displayx); 
  int displayyi = int(displayy);
  int radiusi = int(radius);
  int wallwidthi = int(wallwidth);
  srand(time(NULL));
    
  for( int i = 0; i<Nparticles; i++ ) {
    float tempR = rand() % ((displayyi-24)/2);
    float tempAngle = rand() % 360;
    float tempX = -tempR*sin(tempAngle*conv);
    float tempY = tempR*cos(tempAngle*conv);
    sf::Vector2f temp(tempX, tempY);
    sf::Vector2f placeParticles = temp + centerofmap;
   
    particles.setPosition( placeParticles );
    
    sf::Vector2f currentParticle = particles.getPosition();
    sf::Vector2f tempPos(0,0);
    sf::Vector2f disVec(0,0);
    float distance = 0;

    // Need to check if particles overlap during initialization
    // if it does overlap, just move it by some amount
    // We do not need to check if there is just one particle
    if( i==0 ) {
      storeParticles.push_back( particles );
    }
    else { 
      for( it = storeParticles.begin(); it != storeParticles.end(); it++ ) {
	tempPos = (*it).getPosition();
	disVec = currentParticle - tempPos;
	
	distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );

	if( distance < 2.2*radius ) deleted++;

	while( distance < 2.2*radius ){
	  (particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
	  
	  currentParticle = particles.getPosition();
	  tempPos = (*it).getPosition();
	  disVec = currentParticle - tempPos;
	  distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );
	  if( i>=2 ) {
	    for( bit=storeParticles.begin(); bit != it; bit++ ){
	      tempPos = (*bit).getPosition();
	      disVec = currentParticle - tempPos;
	      distance = sqrt( pow(disVec.x,2)+pow(disVec.y,2));
	      if( distance < 2.2*radius ){
		(particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
	      }
	    }
	  }
	} 
      }
      storeParticles.push_back(particles);    
    }
  } 
}
开发者ID:freddyox,项目名称:brown-dev,代码行数:60,代码来源:test.cpp


示例8: gameWindow

	Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
	{
		ball.setFillColor(sf::Color::Cyan);
		ball.setPosition(100.0, 100.0);
		ball.setRadius(10.f);

		p1Paddle.setFillColor(sf::Color::Green);
		p1Paddle.setPosition(10.0, 100.0);
		p1Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p2Paddle.setFillColor(sf::Color::Red);
		p2Paddle.setPosition(580.0, 100.0);
		p2Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p1MovingUp = false;
		p1MovingDown = false;
		p2MovingUp = false;
		p2MovingDown = false;

		ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
		font.loadFromFile("arial.ttf");

		p1ScoreText.setPosition(150, 10);
		p1ScoreText.setFont(font);
		p1ScoreText.setString(std::to_string(p1Score));
		p1ScoreText.setColor(sf::Color::Red);
		p1ScoreText.setCharacterSize(24);

		p2ScoreText.setPosition(450, 10);
		p2ScoreText.setFont(font);
		p2ScoreText.setString(std::to_string(p2Score));
		p2ScoreText.setColor(sf::Color::Red);
		p2ScoreText.setCharacterSize(24);
	}
开发者ID:minhoolee,项目名称:id-Tech-Files,代码行数:34,代码来源:Main.cpp


示例9: refresh

void ColorPalette::refresh(void) {
	selected.setFillColor(color);
	label.setColor(color);

	label.setString(ColorPalette::interpret(color, str));

	rgb_c.setOutlineColor(Utility::Color::getInverseColor(color));
	bw_c.setOutlineColor(Utility::Color::getInverseColor(color));
}
开发者ID:RenatoGeh,项目名称:TryAngle,代码行数:9,代码来源:ColorPalette.hpp


示例10: setPosition

void Unit::setPosition(float x, float y) {
	if(_isLoaded) {
		_circle.setPosition(x,y);
		_sprite.setPosition(x,y);
	}
	else {
		_circle.setPosition(x,y);
	}
}
开发者ID:ttang1,项目名称:BitGame,代码行数:9,代码来源:Unit.hpp


示例11:

Stone (float x, float y, float a, float b)
{
    velocity.x = x;
    velocity.y = y;
    s.setRadius(radius);
    s.setOrigin(radius,radius);
    s.setFillColor(sf::Color::Black);
    s.setPosition(a,b);

}
开发者ID:nsalv,项目名称:VariousProjects,代码行数:10,代码来源:stone.hpp


示例12: init

static void init(sf::RenderWindow &window)
{
	window.setMouseCursorVisible(false);
	window.setVerticalSyncEnabled(true);

	crosshair.setFillColor(sf::Color(0, 0, 0, 0));
	crosshair.setOutlineColor(sf::Color(0, 0, 0));
	crosshair.setOutlineThickness(2.0f);

	srand(static_cast<unsigned>(time(0)));
}
开发者ID:Movingforward,项目名称:WSU,代码行数:11,代码来源:game.cpp


示例13: Ball

    // Costruttore: prende come parametri la posizione iniziale
    // della pallina, sotto forma di due `float`.
    Ball(float mX, float mY)
    {
        // SFML usa un sistema di coordinate avente l'origine
        // posizionata nell'angolo in alto a sinistra della
        // finestra.
        // {Info: coordinate system}

        shape.setPosition(mX, mY);
        shape.setRadius(defRadius);
        shape.setFillColor(defColor);
        shape.setOrigin(defRadius, defRadius);
    }
开发者ID:SuperV1234,项目名称:itcpp2015,代码行数:14,代码来源:p02.cpp


示例14: set_select_state

 // Draw a ring around the object to show it's selected
 inline void set_select_state(bool select)
 {
     select_state = select;
     if (select)
     {
         circ.setOutlineColor(sf::Color::Green);
         circ.setOutlineThickness(OBJECT_SIZE/5);
     }
     else
     {
         circ.setOutlineColor(sf::Color::Black);
         circ.setOutlineThickness(OBJECT_SIZE/10);
     }
 }
开发者ID:dvbuntu,项目名称:ogre,代码行数:15,代码来源:ogre_obj.hpp


示例15: Polygons

    Polygons():
            _polygons(),
            __polygonsVect()
    {
        _polygons.setRadius(50);
        _polygons.setFillColor(sf::Color::Red);

            for(int i = 3; i < 9;i++)
            {
                _polygons.setPointCount(i);
                _polygons.setPosition(100.0 + (i*99) , 200.0);
                __polygonsVect.push_back(_polygons);
            }

    }
开发者ID:xeloni,项目名称:ProjetsClion,代码行数:15,代码来源:polygons.hpp


示例16: bounceStone

void bounceStone(std::vector<Stone>& stones){
    sf::Vector2f loc = s.getPosition();
    sf::Vector2f stonePos;
    bool collide = 0;
    std::vector<sf::Vector2f> Pos;
    for (int i=0; i<stones.size(); i++){
        stonePos = stones[i].s.getPosition();
        Pos.push_back(stonePos);
    }

    //comparing x and y positions of each stone


        //determines the distance between the x and y coordinates of each stone

    for(int i=0; i<Pos.size(); i++){
    float d = sqrt(pow((loc.x-Pos[i].x),2)+pow((loc.y-Pos[i].y),2));
        if (d<=80 && loc!=Pos[i]){

            float newVelX1 = stones[i].velocity.x;
            float newVelY1 = stones[i].velocity.y;
            float newVelX2 = velocity.x;
            float newVelY2 = velocity.y;

            stones[i].velocity.x = newVelX2;
            stones[i].velocity.y = newVelY2;
            velocity.x = newVelX1;
            velocity.y = newVelY1;
        }
    }
}
开发者ID:nsalv,项目名称:VariousProjects,代码行数:31,代码来源:stone.hpp


示例17: RespawnApple

void World::RespawnApple() {
	_msgCallback("Respawning Apple");
	int maxX = _windowSize.x / _blockSize - 2;
	int maxY = _windowSize.y / _blockSize - 2;
	_item = sf::Vector2i(rand() % maxX + 1, rand() % maxY + 1);
	_appleShape.setPosition(_item.x * _blockSize, _item.y * _blockSize);
}
开发者ID:DForshner,项目名称:CPPExperiments,代码行数:7,代码来源:RetroSnakeDemo.cpp


示例18: update

 void update()
 {
     // Le classi shape di SFML hanno un metodo `move` che
     // prende come parametro un vettore `float` di offset.
     // {Info: ball movement}
     shape.move(velocity);
 }
开发者ID:SuperV1234,项目名称:itcpp2015,代码行数:7,代码来源:p02.cpp


示例19: print

    // We define this function to print the current values that were updated by the on...() functions above.
    void print()
    {
        // Clear the current line
        std::cout << '\r';

        // Print out the orientation. Orientation data is always available, even if no arm is currently recognized.
        std::cout << '[' << std::string(roll_w, '*') << std::string(18 - roll_w, ' ') << ']'
                  << '[' << std::string(pitch_w, '*') << std::string(18 - pitch_w, ' ') << ']'
                  << '[' << std::string(yaw_w, '*') << std::string(18 - yaw_w, ' ') << ']'<< std::endl;
		if(color_input == true)
		{	shape.setFillColor(sf::Color((roll_w*10.75), ((270+pitch_w)*10.75), ((90 +yaw_w)*10.75)));
		}	
		
        if (onArm) {
            // Print out the currently recognized pose and which arm Myo is being worn on.

            // Pose::toString() provides the human-readable name of a pose. We can also output a Pose directly to an
            // output stream (e.g. std::cout << currentPose;). In this case we want to get the pose name's length so
            // that we can fill the rest of the field with spaces below, so we obtain it as a string using toString().
            std::string poseString = currentPose.toString();

            std::cout << '[' << (whichArm == myo::armLeft ? "L" : "R") << ']'
                      << '[' << poseString << std::string(14 - poseString.size(), ' ') << ']';
        } else {
            // Print out a placeholder for the arm and pose when Myo doesn't currently know which arm it's on.
            std::cout << "[?]" << '[' << std::string(14, ' ') << ']';
        }

        std::cout << std::flush;
    }
开发者ID:BruceJohnJennerLawso,项目名称:myohack,代码行数:31,代码来源:mhaaaaaaaaaaaaaaaaaaaaackkkk.cpp


示例20: update

    void update()
    {
        // We need to keep the ball "inside the window".
        // The most common (and probably best) way of doing this, and 
        // of dealing with any kind of collision detection, is moving
        // the object first, then checking if it's intersecting 
        // something.
        // If the test is positive, we simply respond to the collision
        // by altering the object's position and/or velocity.

        // Therefore, we begin by moving the ball.
        shape.move(velocity);

        // After the ball has moved, it may be "outside the window".
        // We need to check every direction and respond by changing 
        // the velocity.

        // If it's leaving towards the left, we need to set
        // horizontal velocity to a positive value (towards the right).
        if(left() < 0) velocity.x = defVelocity;

        // Otherwise, if it's leaving towards the right, we need to
        // set horizontal velocity to a negative value (towards the 
        // left).
        else if(right() > wndWidth) velocity.x = -defVelocity;

        // The same idea can be applied for top/bottom collisions.
        if(top() < 0) velocity.y = defVelocity;
        else if(bottom() > wndHeight) velocity.y = -defVelocity;
    }
开发者ID:luckytina,项目名称:cppcon2014,代码行数:30,代码来源:p03.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ sf::Clock类代码示例发布时间:2022-05-31
下一篇:
C++ sf::Archive类代码示例发布时间: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