Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <iostream>
- const int hexRadius = 10;
- const int spaceBetweenHexes = 2;
- const sf::Vector2f drawingStartCoords = sf::Vector2f(20, 20);
- const int height = 24;
- const int width = 25;
- int board[height][width];
- int main()
- {
- for (int i = 0; i < height; i++)
- for (int j = 0; j < width; j++)
- board[i][j] = 1;
- sf::RenderWindow window(sf::VideoMode(600, 600), "Hex!");
- sf::CircleShape hex(hexRadius, 6);
- hex.setFillColor(sf::Color::White);
- float vectorMoveX = hex.getRadius()*sqrt(3) + spaceBetweenHexes;
- float vectorMoveY = hex.getRadius() * 2 - hex.getRadius() / 2 + spaceBetweenHexes;
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- window.clear();
- hex.setPosition(drawingStartCoords);
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width; j++)
- {
- if(board[i][j]==1)
- window.draw(hex);
- hex.move(vectorMoveX, 0);
- }
- hex.move(-(vectorMoveX)*width, 0);
- if (i%2==0)
- hex.move(vectorMoveX/2, vectorMoveY);
- else
- hex.move(-vectorMoveX/2, vectorMoveY);
- }
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment