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


C++ CircleShape::setPosition方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: exibeHud

/*
 *  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

示例7: update

	void update(sf::Time timeChange)
	{
		sf::Vector2f p1Movement(0, 0);
		sf::Vector2f p2Movement(0, 0);


		if (p1MovingUp)
			p1Movement.y -= paddleSpeed;
		if (p1MovingDown)
			p1Movement.y += paddleSpeed;
		if (p2MovingUp)
			p2Movement.y -= paddleSpeed;
		if (p2MovingDown)
			p2Movement.y += paddleSpeed;

		p1Paddle.move(p1Movement * timeChange.asSeconds());
		p2Paddle.move(p2Movement * timeChange.asSeconds());


		// Check collision
		if (ball.getPosition().y < 0 || ball.getPosition().y > 480){
			ballMovement.y *= -1;
		}
		if (ball.getGlobalBounds().intersects(p1Paddle.getGlobalBounds()) || ball.getGlobalBounds().intersects(p2Paddle.getGlobalBounds())){
			ballMovement.x *= -1;
		}



		// Scoring
		if (ball.getPosition().x > 600){
			// P1 scores
			ball.setPosition(300, 240);
			p1Score++;
			p1ScoreText.setString(std::to_string(p1Score));
		}
		else if (ball.getPosition().x < 0){
			// P2 scores
			ball.setPosition(300, 240);
			p2Score++;
			p2ScoreText.setString(std::to_string(p2Score));
		}

		ball.move(ballMovement * timeChange.asSeconds());


	}
开发者ID:minhoolee,项目名称:id-Tech-Files,代码行数:47,代码来源:Main.cpp

示例8: update

void update(EntityFixture &fixture, const sf::Time &delta) {
    playerUpdater->update(delta);
    velocitiesUpdater->update(delta);
    walker->update(delta);
    poseUpdater->update(delta);
    xformHistorian->update(delta);

    dot.setPosition(fixture.GetInput().getCursorPosition());
}
开发者ID:RolandMQuiros,项目名称:StoriesFromDelAbismo,代码行数:9,代码来源:PlayerTest.cpp

示例9: update

void ColorPalette::update(const sf::Time& dt) {
	if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
		double x = Settings::mouse_position.x;
		double y = Settings::mouse_position.y;

		if((angular[0]*x+linear[0]-y)<=0 &&
			(angular[1]*x+linear[1]-y)>=0 &&
			(angular[2]*x+linear[2]-y)<=0) {
			rgb_c.setPosition(x, y);
			identify(rgb, x, y);
			refresh();
		} else if((angular[3]*x+linear[3]-y)<=0 &&
			(angular[4]*x+linear[4]-y)>=0 &&
			(angular[5]*x+linear[5]-y)>=0) {
			bw_c.setPosition(x, y);
		}
	}
}
开发者ID:RenatoGeh,项目名称:TryAngle,代码行数:18,代码来源:ColorPalette.hpp

示例10:

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

示例11: 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

示例12: plot

void ColorPalette::plot(const sf::VertexArray& shape) {
	double l = ColorPalette::dist(shape[0].position.x, shape[0].position.y,
			shape[1].position.x, shape[1].position.y);

	double da = l*(color.r)/255;
	double db = l*(color.g)/255;

	double x = (linear[1]-linear[2]+da-db)/(angular[2]-angular[1]);
	double y = angular[1]*x+linear[1]+da;

	rgb_c.setPosition(x, y);
}
开发者ID:RenatoGeh,项目名称:TryAngle,代码行数:12,代码来源:ColorPalette.hpp

示例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: 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

示例15: cambiar_posicion_objectos

    void Game::cambiar_posicion_objectos(){

        int x_player;
        int y_player;
        int x_obj;
        int y_obj;

        while(true){

            x_player = rand() % 14;
            y_player = rand() % 10;

            x_obj = rand() % 14;
            y_obj = rand() % 10;

            if(Game::tabla_de_movimientos[y_obj][x_obj] == true & Game::tabla_de_movimientos[y_player][x_player] == true){
                break;
            }
        }

        mPlayerObj.setPosition(x_obj * 50, y_obj * 50);
        mPlayer.setPosition(x_player * 50, y_player * 50);
    }
开发者ID:camuschino,项目名称:SFML,代码行数:23,代码来源:main.cpp


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