Advertisement
AI_UBI

XO SFML Help

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