diff options
Diffstat (limited to 'src/main/cpp')
-rw-r--r-- | src/main/cpp/Map.cpp | 3 | ||||
-rw-r--r-- | src/main/cpp/Subconscious.cpp | 27 | ||||
-rw-r--r-- | src/main/cpp/Tile.cpp | 11 | ||||
-rw-r--r-- | src/main/cpp/WorldScene.cpp | 14 |
4 files changed, 41 insertions, 14 deletions
diff --git a/src/main/cpp/Map.cpp b/src/main/cpp/Map.cpp index 6d3ee01..3cb1b9d 100644 --- a/src/main/cpp/Map.cpp +++ b/src/main/cpp/Map.cpp @@ -24,5 +24,6 @@ const std::vector<Tile>& Map::tiles() const bool Map::moveActor(Tile &from, Tile &to) { - // TODO + to.actor(from.actor()); + from.clearActor(); } diff --git a/src/main/cpp/Subconscious.cpp b/src/main/cpp/Subconscious.cpp index 542e580..9765f2f 100644 --- a/src/main/cpp/Subconscious.cpp +++ b/src/main/cpp/Subconscious.cpp @@ -34,17 +34,29 @@ void Subconscious::run() case sf::Event::KeyPressed: switch (event.key.code) { case sf::Keyboard::Up: - _currentScene->pan(0, 10); + if (_currentScene->type == Scene::Type::WORLD) { + static_cast<WorldScene*>(_currentScene)->pan(0, 10); + } break; + case sf::Keyboard::Down: - _currentScene->pan(0, -10); + if (_currentScene->type == Scene::Type::WORLD) { + static_cast<WorldScene*>(_currentScene)->pan(0, -10); + } break; + case sf::Keyboard::Left: - _currentScene->pan(10, 0); + if (_currentScene->type == Scene::Type::WORLD) { + static_cast<WorldScene*>(_currentScene)->pan(10, 0); + } break; + case sf::Keyboard::Right: - _currentScene->pan(-10, 0); + if (_currentScene->type == Scene::Type::WORLD) { + static_cast<WorldScene*>(_currentScene)->pan(-10, 0); + } break; + default: break; } @@ -71,7 +83,11 @@ void Subconscious::run() // // std::cout << std::fixed << std::setprecision(3) // << event.mouseWheelScroll.delta << std::endl; - _currentScene->zoom(event.mouseWheelScroll.delta/10.0); + + if (_currentScene->type == Scene::Type::WORLD) { + static_cast<WorldScene*>(_currentScene)->zoom(event.mouseWheelScroll.delta/10.0); + } + break; /*** Window Events ***/ @@ -82,6 +98,7 @@ void Subconscious::run() case sf::Event::Resized: _currentScene->resize(event.size); break; + default: break; } diff --git a/src/main/cpp/Tile.cpp b/src/main/cpp/Tile.cpp new file mode 100644 index 0000000..9fc436a --- /dev/null +++ b/src/main/cpp/Tile.cpp @@ -0,0 +1,11 @@ +#include "Tile.hpp" + +bool Tile::actor(Actor *actor) +{ + if (_actor != nullptr) { + return false; + } + + _actor = actor; + return true; +} diff --git a/src/main/cpp/WorldScene.cpp b/src/main/cpp/WorldScene.cpp index cefeda4..c152db8 100644 --- a/src/main/cpp/WorldScene.cpp +++ b/src/main/cpp/WorldScene.cpp @@ -1,6 +1,6 @@ #include "WorldScene.hpp" -WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window) +WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window, Scene::Type::WORLD) { _tileSize = DEFAULT_TILE_SIZE_PX; } @@ -12,6 +12,7 @@ void WorldScene::render() 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); @@ -24,7 +25,7 @@ void WorldScene::render() void WorldScene::resize(const sf::Event::SizeEvent &size) { auto oldView = _window.getView(); - sf::View resizedView(oldView.getCenter(), sf::Vector2f(size.width, size.height)); + sf::View resizedView(oldView.getCenter(), sf::Vector2f(size.width, size.height) / _zoom); _window.setView(resizedView); } @@ -35,19 +36,16 @@ void WorldScene::zoom(float factor) if (_zoom < MIN_ZOOM) { _zoom = MIN_ZOOM; + return; } if (_zoom > MAX_ZOOM) { _zoom = MAX_ZOOM; + return; } sf::View view = _window.getView(); - - view.setSize( - _window.getSize().x * 1 / _zoom, - _window.getSize().y * 1 / _zoom - ); - + view.setSize(static_cast<sf::Vector2f>(_window.getSize()) / _zoom); _window.setView(view); } |