コード例 #1
0
ファイル: main.cpp プロジェクト: camuschino/SFML
    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);

    }
コード例 #2
0
ファイル: stone.hpp プロジェクト: nsalv/VariousProjects
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;
        }
}
コード例 #3
0
ファイル: p08.cpp プロジェクト: luckytina/cppcon2014
 float x() const noexcept        { return shape.getPosition().x; }
コード例 #4
0
	// (0,0) é no topo da esquerda
	float x()				{ return shape.getPosition().x; }
コード例 #5
0
ファイル: main.cpp プロジェクト: Draguld/orbite
int		main()
{
	sf::Clock			clock;
	double				s = 0;
	
	double				viewZoom = 1.0f;

	srand(time(0));

	for (u32 i = 0; i < PN; i++)
	{
		particule[i]._px = rand() % WINX;
		particule[i]._py = rand() % WINY;
		if (INITIAL_SPEED_ACTIVATE)
		{
			particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
			particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
		}
		else
		{
			particule[i]._mx = 0;
			particule[i]._my = 0;
		}
		particule[i]._mass = PAR_MASS;
		particule[i]._color = PCOLOR;
	}

	planet.setPosition(sf::Vector2f(WINX/2, WINY/2));
	planet.setOrigin(sf::Vector2f(10.0f, 10.0f));
	planet.setFillColor(sf::Color::Blue);

	win.create(sf::VideoMode(WINX, WINY), "ORBITE");
	win.setFramerateLimit(MAXFPS);
	clock.restart();
	while (win.isOpen())
	{
		s = clock.restart().asSeconds();
		s *= SPEED;

		sf::View view = win.getDefaultView();
		view.zoom(viewZoom);

		while (win.pollEvent(eve))
		{
			if (eve.type == sf::Event::Closed)
				win.close();
			if (eve.type == sf::Event::KeyPressed)
			{
				if (eve.key.code == sf::Keyboard::Add)
					viewZoom -= 0.25f;
				else if (eve.key.code == sf::Keyboard::Subtract)
					viewZoom += 0.25f;
				else if (eve.key.code == sf::Keyboard::Space)
				{
					trace.clear();
					for (u32 i = 0; i < PN; i++)
					{
						particule[i]._px = rand() % WINX;
						particule[i]._py = rand() % WINY;
						if (INITIAL_SPEED_ACTIVATE)
						{
							particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
							particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
						}
						else
						{
							particule[i]._mx = 0;
							particule[i]._my = 0;
						}
						particule[i]._mass = PAR_MASS;
						particule[i]._color = PCOLOR;
					}		
				}
			}
		}
		
		planet.setPosition((sf::Vector2f)sf::Mouse::getPosition(win));
		for (u32 i = 0; i < PN; i++)
		{
			particule[i].updateToPosition(planet.getPosition(), PL_MASS, s);
			part[i].position = sf::Vector2f(particule[i]._px, particule[i]._py);
			part[i].color = particule[i]._color;
			if (ACTIVATE_ORBIT_TRACE)
			{
				sf::Vertex cpy = part[i];
				trace.append(cpy);
			}
		}
		win.setView(view);
		win.clear(sf::Color::Black);
		win.draw(planet);
		win.draw(part);
		win.draw(trace);
		win.display();
	}
	return (0);
}
コード例 #6
0
ファイル: main.cpp プロジェクト: stuffjunkgames/breakout
sf::Vector2f collide(sf::CircleShape ball, sf::RectangleShape block)
{
    sf::Vector2f ball_center = ball.getPosition() + sf::Vector2f(ball.getRadius(), ball.getRadius());
    sf::Vector2f block_center = block.getPosition() + sf::Vector2f(block.getSize().x/2, block.getSize().y/2);

    sf::Vector2f diff = ball_center - block_center;

    // Not intersecting
    if(abs(diff.x) > block.getSize().x/2 + ball.getRadius() || abs(diff.y) > block.getSize().y/2 + ball.getRadius())
    {
        return sf::Vector2f(0,0);
    }
    std::cout << diff.x << ", " << diff.y << std::endl;

    // hit edge of block (top/bottom)
    if(abs(diff.x) <= PADDLE_WIDTH/2)
    {
        if(diff.y <= 0)
        {
            return sf::Vector2f(0,-1);
        }
        else if(diff.y > 0)
        {
            return sf::Vector2f(0,1);
        }
    }
    // hit edge of block (left/right)
    else if(abs(diff.y) <= PADDLE_HEIGHT/2)
    {
        if(diff.x <= 0)
        {
            return sf::Vector2f(-1,0);
        }
        else if(diff.x > 0)
        {
            return sf::Vector2f(1,0);
        }
    }

    float distance = getDistance(ball_center, block.getPosition());
    if(distance <= ball.getRadius())
    {
        return (ball_center - block.getPosition()) / distance;
    }
    sf::Vector2f block_corner = block.getPosition() + sf::Vector2f(block.getSize().x,0);
    distance = getDistance(ball_center, block_corner);
    if(distance <= ball.getRadius())
    {
        return (ball_center - block_corner) / distance;
    }
    block_corner = block.getPosition() + sf::Vector2f(0, block.getSize().y);
    distance = getDistance(ball_center, block_corner);
    if(distance <= ball.getRadius())
    {
        return (ball_center - block_corner) / distance;
    }
    block_corner = block.getPosition() + block.getSize();
    distance = getDistance(ball_center, block_corner);
    if(distance <= ball.getRadius())
    {
        return (ball_center - block_corner) / distance;
    }

    // Not intersecting, even in the corners
    return sf::Vector2f(0,0);
}
コード例 #7
0
ファイル: ogre_obj.hpp プロジェクト: dvbuntu/ogre
 // Get the current position of this unit
 // For now the position of the circle
 inline sf::Vector2f get_position() const
 {
     return circ.getPosition();
 }