Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SFML/Graphics.hpp"
- #include "SFML/Window.hpp"
- struct Scene
- {
- sf::RectangleShape body;
- sf::CircleShape tire[2];
- sf::ConvexShape roof;
- };
- /*
- +--------------------------->
- | __________ proporcje
- | / | ^ 0.3
- | +----/----------+ |
- | | | | carHeight 0.5
- | +---------------+ |
- | O O V 0.2
- | <--------------->
- | carLength
- |
- V
- */
- Scene createScene()
- {
- Scene s;
- int xpos = 200;
- int ypos = 100;
- int carLength = 150;
- int carHeight = 50;
- float rP = 0.3;
- float bP = 0.5;
- float tP = 0.2;
- s.body.setSize( sf::Vector2f(carLength, bP*carHeight));
- s.body.setPosition({static_cast<float>(xpos), ypos+rP*carHeight});
- s.tire[0].setRadius(tP/2 * carHeight);
- s.tire[1].setRadius(tP/2 * carHeight);
- s.tire[0].setPosition({static_cast<float>(xpos + 0.2*carLength), ypos + (rP+bP)*carHeight });
- s.tire[1].setPosition({static_cast<float>(xpos + 0.7*carLength), ypos + (rP+bP)*carHeight});
- s.roof.setPointCount(4);
- s.roof.setPoint(0, sf::Vector2f(xpos+0.4*carLength, ypos + rP*carHeight));
- s.roof.setPoint(1, sf::Vector2f(xpos+0.5*carLength, ypos ));
- s.roof.setPoint(2, sf::Vector2f(xpos+carLength, ypos ));
- s.roof.setPoint(3, sf::Vector2f(xpos+carLength, ypos + rP*carHeight));
- return s;
- }
- void drawScene(sf::RenderWindow & win, const Scene & scene)
- {
- win.draw(scene.body);
- win.draw(scene.tire[0]);
- win.draw(scene.tire[1]);
- win.draw(scene.roof);
- }
- int main() {
- sf::RenderWindow window(sf::VideoMode(sf::Vector2u(200, 200)), "SFML works!");
- sf::CircleShape shape(100.f);
- shape.setFillColor(sf::Color::Green);
- while (window.isOpen()) {
- sf::Event event;
- while (window.pollEvent(event)) {
- if (event.type == sf::Event::Closed) {
- window.close();
- }
- }
- window.clear();
- window.draw(shape);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment