Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. /* screen dimensions (window size) */
  2. sf::Vector2i screen_dimensions(1280, 1024);
  3.  
  4. /* font */
  5. sf::Font font;
  6. if (!font.loadFromFile("fonts/arial.ttf"))
  7. {
  8. std::cout << "Error loading font\n";
  9. }
  10.  
  11. auto tile_size = sf::Vector2f(64, 64);
  12. auto viewport_width = screen_dimensions.x / tile_size.x;
  13. auto viewport_height = screen_dimensions.y / tile_size.y;
  14.  
  15. /* the default view */
  16. sf::View main(window_.getDefaultView());
  17.  
  18. /* view that's always centered on the player */
  19. sf::View center;
  20. center.reset(sf::FloatRect(0, 0, screen_dimensions.x, screen_dimensions.y));
  21. center.setCenter(sf::Vector2f(screen_dimensions.x / 2, screen_dimensions.y / 2));
  22.  
  23. sf::Text text;
  24. text.setFont(font);
  25. text.setCharacterSize(18);
  26. text.setFillColor(sf::Color::Black);
  27.  
  28. sf::Text text2;
  29. text2.setFont(font);
  30. text2.setCharacterSize(18);
  31. text2.setFillColor(sf::Color::Black);
  32.  
  33. sf::RectangleShape tile;
  34. tile.setSize(tile_size);
  35. tile.setOutlineThickness(1.f);
  36. tile.setOutlineColor(sf::Color::Black);
  37.  
  38. while (window_.isOpen())
  39. {
  40. /* handle window events */
  41. window_.HandleInput();
  42.  
  43. /* clear */
  44. this->window_.clear(sf::Color::Black);
  45.  
  46. /* set the main view */
  47. window_.setView(main);
  48.  
  49. for (int col = 0; col < 20; ++col)
  50. {
  51. for (int row = 0; row < 16; ++row)
  52. {
  53. sf::RectangleShape square(tile);
  54. square.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
  55.  
  56. text.setString(sf::String("X " + std::to_string((int)(row * tile_size.y))));
  57. text.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
  58.  
  59. text2.setString(sf::String("Y " + std::to_string((int)(col * tile_size.x))));
  60. text2.setPosition(sf::Vector2f(col * tile_size.x, (row * tile_size.y) + 25));
  61.  
  62. window_.draw(square);
  63.  
  64. window_.draw(text);
  65. window_.draw(text2);
  66. }
  67. }
  68.  
  69. /* set the center view */
  70. window_.setView(center);
  71.  
  72. for (int col = 20; col < 40; ++col)
  73. {
  74. for (int row = 0; row < 16; ++row)
  75. {
  76. sf::RectangleShape square(tile);
  77. square.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
  78.  
  79. text.setString(sf::String("X " + std::to_string((int)(row * tile_size.y))));
  80. text.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
  81.  
  82. text2.setString(sf::String("Y " + std::to_string((int)(col * tile_size.x))));
  83. text2.setPosition(sf::Vector2f(col * tile_size.x, (row * tile_size.y) + 25));
  84.  
  85. window_.draw(square);
  86.  
  87. window_.draw(text);
  88. window_.draw(text2);
  89. }
  90. }
  91.  
  92. /* display all drawn stuff */
  93. window_.display();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement