#include "WorldScene.hpp" WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window, Scene::Type::WORLD) { _tileSize = DEFAULT_TILE_SIZE_PX; } void WorldScene::render() { sf::RectangleShape rect; rect.setSize(sf::Vector2f(_tileSize, _tileSize)); rect.setFillColor(sf::Color::Green); // negative thickness to make the outline toward inside rect.setOutlineThickness(-.5); rect.setOutlineColor(sf::Color::Black); for (const Tile &tile : map.tiles()) { rect.setPosition(tile.x * _tileSize, tile.y * _tileSize); _window.draw(rect); } } void WorldScene::resize(const sf::Event::SizeEvent &size) { auto oldView = _window.getView(); sf::View resizedView(oldView.getCenter(), sf::Vector2f(size.width, size.height) / _zoom); _window.setView(resizedView); } void WorldScene::zoom(float factor) { _zoom += factor; if (_zoom < MIN_ZOOM) { _zoom = MIN_ZOOM; return; } if (_zoom > MAX_ZOOM) { _zoom = MAX_ZOOM; return; } sf::View view = _window.getView(); view.setSize(static_cast(_window.getSize()) / _zoom); _window.setView(view); } void WorldScene::pan(int dx, int dy) { sf::View view = _window.getView(); view.setCenter( view.getCenter().x + dx, view.getCenter().y + dy ); _window.setView(view); }