malcin

Untitled

Jan 11th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3.  
  4. const int hexRadius = 10;
  5. const int spaceBetweenHexes = 2;
  6. const sf::Vector2f drawingStartCoords = sf::Vector2f(20, 20);
  7.  
  8. const int height = 24;
  9. const int width = 25;
  10. int board[height][width];
  11.  
  12. int main()
  13. {
  14.     for (int i = 0; i < height; i++)
  15.         for (int j = 0; j < width; j++)
  16.                 board[i][j] = 1;
  17.        
  18.  
  19.     sf::RenderWindow window(sf::VideoMode(600, 600), "Hex!");
  20.    
  21.     sf::CircleShape hex(hexRadius, 6);
  22.     hex.setFillColor(sf::Color::White);
  23.  
  24.     float vectorMoveX = hex.getRadius()*sqrt(3) + spaceBetweenHexes;
  25.     float vectorMoveY = hex.getRadius() * 2 - hex.getRadius() / 2 + spaceBetweenHexes;
  26.  
  27.     while (window.isOpen())
  28.     {
  29.        
  30.         sf::Event event;
  31.         while (window.pollEvent(event))
  32.         {
  33.             if (event.type == sf::Event::Closed)
  34.                 window.close();
  35.         }
  36.  
  37.         window.clear();
  38.        
  39.  
  40.         hex.setPosition(drawingStartCoords);
  41.         for (int i = 0; i < height; i++)
  42.         {
  43.             for (int j = 0; j < width; j++)
  44.             {
  45.                 if(board[i][j]==1)
  46.                     window.draw(hex);
  47.                 hex.move(vectorMoveX, 0);
  48.             }
  49.             hex.move(-(vectorMoveX)*width, 0);
  50.             if (i%2==0)
  51.                 hex.move(vectorMoveX/2, vectorMoveY);
  52.             else
  53.                 hex.move(-vectorMoveX/2, vectorMoveY);
  54.         }
  55.  
  56.         window.display();
  57.     }
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment