Exemplo n.º 1
0
 Ball(float mX, float mY)
 {
     shape.setPosition(mX, mY);
     shape.setRadius(defRadius);
     shape.setFillColor(defColor);
     shape.setOrigin(defRadius, defRadius);
 }
Exemplo n.º 2
0
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);    
    }
  } 
}
Exemplo n.º 3
0
	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);
	}
Exemplo n.º 4
0
/*
	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();
}
Exemplo n.º 5
0
/*
 *  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);
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
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));
}
Exemplo n.º 8
0
void Unit::setPosition(float x, float y) {
	if(_isLoaded) {
		_circle.setPosition(x,y);
		_sprite.setPosition(x,y);
	}
	else {
		_circle.setPosition(x,y);
	}
}
Exemplo n.º 9
0
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);

}
Exemplo n.º 10
0
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)));
}
Exemplo n.º 11
0
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);
	
}
Exemplo n.º 12
0
    // 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);
    }
Exemplo n.º 13
0
 // 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);
     }
 }
Exemplo n.º 14
0
    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);
            }

    }
Exemplo n.º 15
0
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;
        }
    }
}
Exemplo n.º 16
0
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);
}
Exemplo n.º 17
0
 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);
 }
    // 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;
    }
Exemplo n.º 19
0
    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;
    }
Exemplo n.º 20
0
	// Atualiza o objeto movendo com a velocidade atual;
	void update () { 
		shape.move (velocity); 

		// Pra manter a bola dentro da tela, precisamos testar se está nas 
		// extremidades da tela e inverter sua velocidade
		if (left() < 0 || right() > windowWidth) velocity.x *= -1;
		if (top() < 0 || bottom() > windowHeight) velocity.y *= -1;
	}
Exemplo n.º 21
0
    TestBox(bool isCollidable) :
        sg::Entity(isCollidable)
    {

        r0.setSize(sf::Vector2f(100.0f, 50.0f));
        r0.setOrigin(50.0f, 25.0f);
        this->addDrawable(r0, false);
        bs.addShape(r0);
        r1.setRadius(40.0f);
        r1.setOrigin(40.0f, 40.0f);
        r1.move(100.0f, 0.0f);
        r1.scale(2.0f, 1.0f);
        this->addDrawable(r1, false);
        bs.addShape(r1);
        r2.setSize(sf::Vector2f(250.0f, 10.0f));
        r2.setOrigin(125.0f, 5.0f);
        r2.rotate(-90.0f);
        this->addDrawable(r2, false);
        bs.addShape(r2);
        r3.setRadius(40.0f);
        r3.setOrigin(40.0f, 40.0f);
        r3.move(-100.0f, 0.0f);
        this->addDrawable(r3, false);
        bs.addShape(r3);
        //bs.rotate(-45.0f);
        this->addTransformable(bs);
        //this->rotate(45.0f);

    }
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());
}
Exemplo n.º 23
0
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);
		}
	}
}
Exemplo n.º 24
0
    void Game::update() {

            posicion_jugable_x = mPlayer.getPosition().x;
            posicion_jugable_y = mPlayer.getPosition().y;

            this->movement.y = 0.f;
            this->movement.x = 0.f;

            if (this->mIsMovingUp & this->mIsMovingUpRel & (posicion_jugable_y > 0) & movimiento_valido(0, -1)) {

                this->movement.y -= 50.f;
                this->mIsMovingUpRel = 0;
            }

            if (this->mIsMovingDown &  this->mIsMovingDownRel & (posicion_jugable_y < 450) & movimiento_valido(0, 1)) {

                this->movement.y += 50.f;
                this->mIsMovingDownRel = 0;
            }

            if (this->mIsMovingLeft & this->mIsMovingLeftRel & (posicion_jugable_x  > 0) & movimiento_valido(-1, 0)) {

                this->movement.x -= 50.f;
                this->mIsMovingLeftRel = 0;

            }

            if (this->mIsMovingRight & this->mIsMovingRightRel & (posicion_jugable_x < 650) & movimiento_valido(1, 0)) {

                this->movement.x += 50.f;
                this->mIsMovingRightRel = 0;
            }

            if(mPlayer.getPosition() == mPlayerObj.getPosition()) {

                this->mIsMapGenerate = true;
                Game::generacion_mapa();
            }

            mPlayer.move(this->movement);

    }
Exemplo n.º 25
0
	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());


	}
Exemplo n.º 26
0
void bounce(){
    sf::Vector2f Pos = s.getPosition();

        if (Pos.x >= 960 || Pos.x <=40){
            velocity.x= -velocity.x;
        }

        if (Pos.y >=960 || Pos.y <=40){
            velocity.y = -velocity.y;
        }
}
    // onPose() is called whenever the Myo detects that the person wearing it has changed their pose, for example,
    // making a fist, or not making a fist anymore.
    void onPose(myo::Myo* myo, uint64_t timestamp, myo::Pose pose)
    {
        currentPose = pose;

        // Vibrate the Myo whenever we've detected that the user has made a fist.
        if (pose == myo::Pose::waveIn) {
            myo->vibrate(myo::Myo::vibrationMedium);
			std::cout << "RGB Colour (" << (float)shape.getFillColor().r << " , " << (float)shape.getFillColor().g << " , " << (float)shape.getFillColor().b << ")" << std::endl;
			if(color_input == true)
			{	color_input = false; 
			}
			else
			{	color_input = true;
			}
		}
		else if(pose == myo::Pose::waveOut)
		{	//myo->vibrate(myo::Myo::vibrationMedium);		// this proved to be a bit of a distraction
			INPUT ip;
			ip.type = INPUT_MOUSE;
			ip.mi.dx = 0; 
			ip.mi.dy = 0;
			ip.mi.time = 0.2;
			ip.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
			SendInput(1, &ip, sizeof(INPUT));
			ip.mi.dwFlags = MOUSEEVENTF_RIGHTUP; // KEYEVENTF_KEYUP for key release
			SendInput(1, &ip, sizeof(INPUT));
		}
		else if((pose == myo::Pose::fist)||(pose == myo::Pose::thumbToPinky))
		{	//myo->vibrate(myo::Myo::vibrationMedium);
			INPUT ip;
			ip.type = INPUT_MOUSE;
			ip.mi.dx = 0; 
			ip.mi.dy = 0;
			ip.mi.time = 0.2;
			ip.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
			SendInput(1, &ip, sizeof(INPUT));
			ip.mi.dwFlags = MOUSEEVENTF_LEFTUP; // KEYEVENTF_KEYUP for key release
			SendInput(1, &ip, sizeof(INPUT));

		}	
    }
Exemplo n.º 28
0
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);
}
Exemplo n.º 29
0
    cerclesTransparents():
        _mesCercles(),
        __vectCercles()
    {
        sf::Vector2u tailleWindow = _window.getSize();
        unsigned int hauteur = tailleWindow.y;
        unsigned int largeur = tailleWindow.x;
        float rayon = 400;

        for(int i = 0 ; i < 10; i++)
        {
            _mesCercles.setOrigin(rayon, rayon);
            _mesCercles.setPosition(400,400);
            _mesCercles.setRadius(rayon);
            _mesCercles.setFillColor(sf::Color(0.0, 0.0 + (25*i) , 255 - (25*i), 127));
            rayon -= 25;
            __vectCercles.push_back(_mesCercles);
        }

        cout << "Taille du vect --> " <<  __vectCercles.size() << endl;
    }
Exemplo n.º 30
0
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 );
		}
	}
}