Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* screen dimensions (window size) */
- sf::Vector2i screen_dimensions(1280, 1024);
- /* font */
- sf::Font font;
- if (!font.loadFromFile("fonts/arial.ttf"))
- {
- std::cout << "Error loading font\n";
- }
- auto tile_size = sf::Vector2f(64, 64);
- auto viewport_width = screen_dimensions.x / tile_size.x;
- auto viewport_height = screen_dimensions.y / tile_size.y;
- /* the default view */
- sf::View main(window_.getDefaultView());
- /* view that's always centered on the player */
- sf::View center;
- center.reset(sf::FloatRect(0, 0, screen_dimensions.x, screen_dimensions.y));
- center.setCenter(sf::Vector2f(screen_dimensions.x / 2, screen_dimensions.y / 2));
- sf::Text text;
- text.setFont(font);
- text.setCharacterSize(18);
- text.setFillColor(sf::Color::Black);
- sf::Text text2;
- text2.setFont(font);
- text2.setCharacterSize(18);
- text2.setFillColor(sf::Color::Black);
- sf::RectangleShape tile;
- tile.setSize(tile_size);
- tile.setOutlineThickness(1.f);
- tile.setOutlineColor(sf::Color::Black);
- while (window_.isOpen())
- {
- /* handle window events */
- window_.HandleInput();
- /* clear */
- this->window_.clear(sf::Color::Black);
- /* set the main view */
- window_.setView(main);
- for (int col = 0; col < 20; ++col)
- {
- for (int row = 0; row < 16; ++row)
- {
- sf::RectangleShape square(tile);
- square.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
- text.setString(sf::String("X " + std::to_string((int)(row * tile_size.y))));
- text.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
- text2.setString(sf::String("Y " + std::to_string((int)(col * tile_size.x))));
- text2.setPosition(sf::Vector2f(col * tile_size.x, (row * tile_size.y) + 25));
- window_.draw(square);
- window_.draw(text);
- window_.draw(text2);
- }
- }
- /* set the center view */
- window_.setView(center);
- for (int col = 20; col < 40; ++col)
- {
- for (int row = 0; row < 16; ++row)
- {
- sf::RectangleShape square(tile);
- square.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
- text.setString(sf::String("X " + std::to_string((int)(row * tile_size.y))));
- text.setPosition(sf::Vector2f(col * tile_size.x, row * tile_size.y));
- text2.setString(sf::String("Y " + std::to_string((int)(col * tile_size.x))));
- text2.setPosition(sf::Vector2f(col * tile_size.x, (row * tile_size.y) + 25));
- window_.draw(square);
- window_.draw(text);
- window_.draw(text2);
- }
- }
- /* display all drawn stuff */
- window_.display();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement