Advertisement
AI_UBI

XO SFML Help

Mar 6th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2.  
  3. void make_grid(sf::RenderTexture *text, const sf::Vector2f &size, const sf::Vector2f &cell_size)
  4. {
  5.     for (unsigned x = 0; x < size.x; ++x)
  6.     {
  7.         for (unsigned y = 0; y < size.y; ++y)
  8.         {
  9.             sf::RectangleShape cell(cell_size-sf::Vector2f(2,2)); //Начало нанокостыля.
  10.            
  11.             cell.setPosition(sf::Vector2f(x*cell_size.x+1, y*cell_size.y+1)); //Нано-костыль дабы не рисовать снаружи еще один рект.
  12.             cell.setOutlineThickness(1);
  13.             cell.setOutlineColor(sf::Color::Black);
  14.             cell.setFillColor(sf::Color(0, 0, 0, 0));
  15.            
  16.             text->draw(cell);
  17.         }
  18.     }
  19. }
  20.  
  21. int main()
  22. {
  23.     const sf::Vector2f grid_size(4,4); //Количество и размер ячеек.
  24.     const sf::Vector2f cell_size(64, 64);
  25.  
  26.     sf::RenderTexture FT;
  27.     FT.create(grid_size.x*cell_size.x, grid_size.y*cell_size.y);
  28.  
  29.     make_grid(&FT, grid_size, cell_size); //Делаем кастомное поле.
  30.  
  31.     sf::RenderWindow window(sf::VideoMode(grid_size.x*cell_size.x, grid_size.y*cell_size.y), "XO");
  32.  
  33.     sf::Sprite sprite_bg;
  34.    
  35.     sprite_bg.setTexture(FT.getTexture()); //Выне за вайл, смысла передергивать бэкграунд каждый раз нету.
  36.  
  37.     while (window.isOpen())
  38.     {
  39.         sf::Event event;
  40.         while (window.pollEvent(event))
  41.         {
  42.             if (event.type == sf::Event::Closed)
  43.                 window.close();
  44.         }
  45.  
  46.         window.clear(sf::Color(192, 192, 192));
  47.  
  48.         window.draw(sprite_bg);
  49.  
  50.         window.display();
  51.     }
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement