コード例 #1
0
ファイル: Sun.cpp プロジェクト: PietPtr/Solex
void Sun::draw(DrawData drawData)
{
    RenderWindow* window = drawData.window;
    double zoom = drawData.zoom;
    Vector2i viewPos = drawData.viewPos;


    CircleShape sun;
    int r = radius / zoom;
    r = r < 2 ? 2 : r;
    sun.setRadius(r);
    sun.setPointCount(1024);
    sun.setPosition(globalToDrawCoords(viewPos, Vector2i(0, 0), zoom));
    sun.setOrigin(Vector2f(r, r));
    sun.setFillColor(Color(200, 200, 0));
    window->draw(sun);

    for (int i = 0; i < moons.size(); i++)
    {
        moons.at(i).draw(window, zoom, viewPos);
    }

    for (int i = 0; i < planets.size(); i++)
    {
        planets.at(i).draw(window, zoom, viewPos);
    }


}
コード例 #2
0
ファイル: p4.cpp プロジェクト: OleksanderPasicznyk/Tutorials
 Ball(float mX, float mY)
 {
     shape.setPosition(mX, mY);
     shape.setRadius(ballRadius);
     shape.setFillColor(Color::Red);
     shape.setOrigin(ballRadius, ballRadius);
 }
コード例 #3
0
ファイル: wrap_CircleShape.cpp プロジェクト: joedrago/love
int w_CircleShape_setRadius(lua_State *L)
{
	CircleShape *c = luax_checkcircleshape(L, 1);
	float r = (float)luaL_checknumber(L, 2);
	c->setRadius(r);
	return 0;
}
コード例 #4
0
ファイル: main2.cpp プロジェクト: FirKys/session_2
	Bullet(Vector2f coord, int who, int test){
		this->test.angle = test;
		this->who = who;
		shape.setPosition(coord);
		shape.setFillColor(Color::Red);
		shape.setRadius(5);
	}
コード例 #5
0
ファイル: p2.cpp プロジェクト: ardraeiss/Tutorials
	// Let's create the Ball constructor.
	// (argument mX -> starting x coordinate)
	// (argument mY -> starting y coordinate)
	Ball(float mX, float mY) 
	{
		// Apply position, radius, color and origin 		 
		// to the CircleShape `shape`.
		shape.setPosition(mX, mY);		
		shape.setRadius(ballRadius);
		shape.setFillColor(Color::Red);
		shape.setOrigin(ballRadius, ballRadius);
	}	
コード例 #6
0
ファイル: GameGraphics.cpp プロジェクト: nitral/plAI-14
void GameGraphics::drawCannonBalls(Time elapsedTime)
{
	for (CannonBallList* cbl = game->cannonBallsManager.registeredCannonBalls; cbl != NULL; cbl=cbl->down)
	{
		CircleShape circle;
		circle.setRadius(CANNON_BALL_RADIUS);
		circle.setFillColor(Color::Yellow);
		circle.setOrigin(CANNON_BALL_RADIUS, CANNON_BALL_RADIUS);
		circle.setPosition(cbl->cannonBall.position);
		game->window.draw(circle);
	}
}
コード例 #7
0
ファイル: Spacecraft.cpp プロジェクト: PietPtr/Perturb
void Spacecraft::draw(RenderWindow* window, double zoom, int index)
{
    CircleShape body;
    body.setPosition(position);
    body.setRadius(zoom);
    window->draw(body);

    //draw prediction;

    drawPrediction(true, index, zoom, window);

    //drawForces(window);
}
コード例 #8
0
ファイル: Bullet.cpp プロジェクト: chmod96/Kurs_SFML
void Bullet::add(Vector2f f,Vector2f pos)
{
	//
	CircleShape c;
	c.setPosition(pos);
	c.setFillColor(color);
	c.setRadius(2);
	
	if(timer.getElapsedTime() >= frequency && (ammunition > 0 || infinite))
	{
		m_bullet.push_back(c);
		factor.push_back(f);

		timer.restart();
		ammunition--;
	}
}
コード例 #9
0
void Crawler::DebugDraw( RenderTarget *target )
{
	if( !dead )
	{

		CircleShape cs;
		cs.setFillColor( Color::Cyan );
		cs.setRadius( 10 );
		cs.setOrigin( cs.getLocalBounds().width / 2, cs.getLocalBounds().height / 2 );
		V2d g = ground->GetPoint( edgeQuantity );
		cs.setPosition( g.x, g.y );

		//owner->window->draw( cs );
		//UpdateHitboxes();
		physBody.DebugDraw( target );
	}
//	hurtBody.DebugDraw( target );
//	hitBody.DebugDraw( target );
}
コード例 #10
0
ファイル: Simulation.cpp プロジェクト: theTI2O/GravityLaw
void Simulation::testons()
{
    Event event;
    while(m_window.pollEvent(event))
    {
        if(event.type == Event::Closed)
            m_window.close();

        if(event.type == Event::MouseButtonReleased)//Si on clique, on ajoute un corps
        {
            if(event.mouseButton.button == Mouse::Left)
            {
                Vector2i mousePosition = Mouse::getPosition(m_window);

                m_test.setPosition(mousePosition.x, mousePosition.y);

            }
        }
    }

    //données:
    CircleShape cercle;
    CircleShape base;

    base.setPosition(390, 390);
    base.setRadius(10);
    base.setFillColor(Color::Red);



    double x(0), y(0), rayon(5);
    //int color[3];

    m_test.getPosition(x, y);

    m_window.clear(Color::Black);

    cercle.setPosition((int)x-rayon, (int)y-rayon);
    cercle.setRadius(rayon);
    cercle.setFillColor(Color::White);






    double yb(400), xb(400);


    double coefdir = (yb - y) / (xb - x);
    double angle = atan(coefdir);
    if(x>xb)
    {
        angle = (angle+3.14);
        while(angle > 2*3.14)
        {
            angle -= 2*3.14;
        }
    }
    double angleD = angle*(360/(2*3.14));



    RectangleShape vectorA;
    vectorA.setSize(Vector2f(50, 1));
    vectorA.setPosition(x, y);
    vectorA.setRotation(angleD);

    RectangleShape vectorX;
    vectorX.setSize(Vector2f(50*cos(angle), 1));
    vectorX.setPosition(x, y);
    vectorX.setFillColor(Color::Green);

    RectangleShape vectorY;
    vectorY.setSize(Vector2f(1, 50*sin(angle)));
    vectorY.setPosition(x, y);
    vectorY.setFillColor(Color::Green);


    m_window.draw(base);
    m_window.draw(cercle);
    m_window.draw(vectorA);
    m_window.draw(vectorX);
    m_window.draw(vectorY);



    m_affichageAux->setString("Angle: " + to_string(angleD));
    m_window.draw(*m_affichageAux);

    m_window.display();
}
コード例 #11
0
ファイル: main.cpp プロジェクト: in0x/go_on_proto
int main(int argc, char** argv)
{
	RenderWindow window(sf::VideoMode(W_WIDTH,W_HEIGHT),"Hello",sf::Style::Close);
		
	View view{ FloatRect{0,0,V_WIDTH,V_HEIGHT} };
	View defaultView = View{ FloatRect{ 0,0, 1600, 1200 } };

	//window.setView(view);

	Physics physics{ {0.f, 9.8f}, 10.f };

	//LightMap lights{view};
	LightMap lights{ defaultView };

	auto playerLight = lights.createLight("../assets/lightmask.png", 400, 370, 3.f);

	//lights.createLight("../assets/lightmask.png", 200, 100, 3.f);

	Clock clock;

	physics.spawnStaticBox(40.f, 60.f, 800.f, 40.f);
	physics.spawnStaticBox(80.f, 110.f, 800.f, 40.f);
	
	auto pPlayerBody = physics.spawnDynamicCircle(3.f, 400.f, 0.f);
	
	Texture tex;
	tex.loadFromFile("../assets/tile.png");
	tex.setSmooth(true);

	Shader blendShader;

	if (!blendShader.loadFromFile("../src/test.frag", Shader::Fragment))
		std::cout << "Failed to load blend fragment shader" << std::endl;

	Texture playerTex;
	playerTex.loadFromFile("../assets/player.png");
	playerTex.setSmooth(true);

	sf::Event ev;

	Texture worldTex;
	worldTex.create(W_WIDTH, W_HEIGHT);
	Sprite displaySprite;

	Font font;
	font.loadFromFile("../assets/kenney_bold.ttf");

	Text framerate;
	framerate.setFont(font);
	framerate.setCharacterSize(40);
	framerate.setPosition(1100, 200);
	framerate.setColor(sf::Color::White);

	while (window.isOpen())
	{
		while (window.pollEvent(ev))
		{
			if (ev.type == Event::Closed)
			{
				window.close();
			}

			if (ev.type == Event::KeyPressed)
			{
				if (ev.key.code == sf::Keyboard::Left)
				{	
					if (pPlayerBody->GetLinearVelocity().x - (MS_X / 100) > -(2 * MS_X / 100))
						pPlayerBody->ApplyForceToCenter({-MS_X, 0.f},true);
					else
						pPlayerBody->ApplyForceToCenter({ -(2 * MS_X / 100) - pPlayerBody->GetLinearVelocity().x , 0.f }, true);
				}

				if (ev.key.code == sf::Keyboard::Right)
				{
					if (pPlayerBody->GetLinearVelocity().x + (MS_X / 100) < (2 * MS_X / 100))
						pPlayerBody->ApplyForceToCenter({ MS_X, 0.f }, true);
					else
						pPlayerBody->ApplyForceToCenter({ (2 * MS_X / 100) - pPlayerBody->GetLinearVelocity().x , 0.f }, true);
				}

				if (ev.key.code == sf::Keyboard::Space)
				{
					if (pPlayerBody->GetLinearVelocity().y + (MS_X / 100)  < (2 * MS_X / 100))
						pPlayerBody->ApplyForceToCenter({ 0.f, -MS_X * 2 }, true);
					//else
						//pPlayerBody->ApplyForceToCenter({ 0.f, (3 * MS_X / 100) - pPlayerBody->GetLinearVelocity().y }, true);
				}
			}

			if (ev.type == Event::JoystickButtonPressed)
			{
				std::cout << ev.joystickButton.button << std::endl;
			}

			if (ev.type == Event::JoystickMoved)
			{
				std::cout << ev.joystickMove.axis << std::endl;
			}
		}

		physics.step(1.f / 30.f);
		
		window.clear();

		auto playerPos = pPlayerBody->GetPosition();
		view.setCenter(SCALE * playerPos.x, SCALE * playerPos.y);
		//window.setView(view);

		auto lightSize = playerLight->getSprite().getTexture()->getSize();

		// 3.f is the player body radius
		playerLight->setPosition(
			playerPos.x * SCALE - lightSize.x - 3.f * SCALE * 2
			, playerPos.y * SCALE - lightSize.y - 3.f * SCALE * 2);

		auto bodyIt = physics.getBodyList();

		//lights.updateView(view);
		lights.render();

		while (bodyIt != nullptr)
		{
			auto pos = bodyIt->GetPosition();

			if (bodyIt->GetType() == b2_dynamicBody)
			{
				CircleShape sprite;
							
				sprite.setTexture(&playerTex);

				auto playerShape = *(b2CircleShape*)(bodyIt->GetFixtureList()->GetShape());

				sprite.setRadius(playerShape.m_radius * SCALE);
				
				sprite.setOrigin(playerShape.m_radius * SCALE, playerShape.m_radius * SCALE);
				
				sprite.setPosition(SCALE * pos.x, SCALE * pos.y);

				sprite.setRotation(bodyIt->GetAngle() * 180 / b2_pi);
				
				window.draw(sprite);
			}

			else // ground
			{
				RectangleShape sprite;
				
				sprite.setSize({800.f, 40.f});
				
				sprite.setOrigin(400, 20);

				sprite.setPosition(pos.x * SCALE, pos.y * SCALE);

				sprite.setRotation(bodyIt->GetAngle() * 180 / b2_pi);

				sprite.setTexture(&tex);

				window.draw(sprite);
			}
			
			bodyIt = bodyIt->GetNext();
		}

		window.draw(Sprite{ lights.getLightMapTexture() }, BlendMultiply);

		float frameTime = 1.f / clock.getElapsedTime().asSeconds();
		clock.restart();
		framerate.setString(std::to_string((int)frameTime) + " fps");

		window.draw(framerate);

		window.display();
	}
}