Piotoru

main.cpp

Dec 23rd, 2023
1,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include "SFML/Graphics.hpp"
  2. #include "SFML/Window.hpp"
  3.  
  4. struct Scene
  5. {
  6.   sf::RectangleShape body;
  7.   sf::CircleShape tire[2];
  8.   sf::ConvexShape roof;
  9. };
  10.  
  11. /*
  12. +--------------------------->
  13. |           __________                 proporcje
  14. |          /         |     ^              0.3
  15. |    +----/----------+     |
  16. |    |               |     |  carHeight   0.5
  17. |    +---------------+     |
  18. |       O        O         V              0.2
  19. |    <--------------->
  20. |        carLength
  21. |
  22. V
  23. */
  24.  
  25. Scene createScene()
  26. {
  27.   Scene s;
  28.  
  29.   int xpos = 200;
  30.   int ypos = 100;
  31.  
  32.   int carLength = 150;
  33.   int carHeight = 50;
  34.  
  35.   float rP = 0.3;
  36.   float bP = 0.5;
  37.   float tP = 0.2;
  38.  
  39.   s.body.setSize( sf::Vector2f(carLength, bP*carHeight));
  40.   s.body.setPosition({static_cast<float>(xpos), ypos+rP*carHeight});
  41.  
  42.   s.tire[0].setRadius(tP/2 * carHeight);
  43.   s.tire[1].setRadius(tP/2 * carHeight);
  44.  
  45.   s.tire[0].setPosition({static_cast<float>(xpos + 0.2*carLength), ypos + (rP+bP)*carHeight });
  46.   s.tire[1].setPosition({static_cast<float>(xpos + 0.7*carLength), ypos + (rP+bP)*carHeight});
  47.  
  48.   s.roof.setPointCount(4);
  49.   s.roof.setPoint(0, sf::Vector2f(xpos+0.4*carLength, ypos + rP*carHeight));
  50.   s.roof.setPoint(1, sf::Vector2f(xpos+0.5*carLength, ypos ));
  51.   s.roof.setPoint(2, sf::Vector2f(xpos+carLength, ypos ));
  52.   s.roof.setPoint(3, sf::Vector2f(xpos+carLength, ypos + rP*carHeight));
  53.  
  54.  
  55.   return s;
  56. }
  57.  
  58. void drawScene(sf::RenderWindow & win, const Scene & scene)
  59. {
  60.   win.draw(scene.body);
  61.   win.draw(scene.tire[0]);
  62.   win.draw(scene.tire[1]);
  63.   win.draw(scene.roof);
  64. }
  65.  
  66. int main() {
  67.   sf::RenderWindow window(sf::VideoMode(sf::Vector2u(200, 200)), "SFML works!");
  68.   sf::CircleShape shape(100.f);
  69.   shape.setFillColor(sf::Color::Green);
  70.  
  71.   while (window.isOpen()) {
  72.     sf::Event event;
  73.     while (window.pollEvent(event)) {
  74.       if (event.type == sf::Event::Closed) {
  75.         window.close();
  76.       }
  77.     }
  78.     window.clear();
  79.     window.draw(shape);
  80.     window.display();
  81.   }
  82.   return 0;
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment