aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
m---------lib/TestNLTmxMap0
-rw-r--r--src/main/cpp/Map.cpp3
-rw-r--r--src/main/cpp/Subconscious.cpp27
-rw-r--r--src/main/cpp/Tile.cpp11
-rw-r--r--src/main/cpp/WorldScene.cpp14
-rw-r--r--src/main/headers/Scene.hpp14
-rw-r--r--src/main/headers/Tile.hpp11
-rw-r--r--src/main/headers/WorldScene.hpp4
9 files changed, 65 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 173963b..5e9850a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,8 @@
**/*~
**/*.swp
+tags
+
## Gradle
target
*/target
diff --git a/lib/TestNLTmxMap b/lib/TestNLTmxMap
new file mode 160000
+Subproject e8190d51d2141c5414e25f7bb285b12eaaa9ef3
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);
}
diff --git a/src/main/headers/Scene.hpp b/src/main/headers/Scene.hpp
index 19a32dd..2183d63 100644
--- a/src/main/headers/Scene.hpp
+++ b/src/main/headers/Scene.hpp
@@ -6,22 +6,26 @@
class Scene
{
public:
- constexpr static float MAX_ZOOM = 10;
- constexpr static float MIN_ZOOM = .1;
+ enum Type
+ {
+ WORLD, MENU
+ };
+
+ const Type type;
+
+ Scene() = delete;
virtual void render() = 0;
virtual void resize(const sf::Event::SizeEvent &size) = 0;
virtual void click(const sf::Event::MouseButtonEvent &click) {}
virtual void keyPress(const sf::Event::KeyEvent &event) {}
- virtual void zoom(float factor) {}
- virtual void pan(int dx, int dy) {};
protected:
float _zoom = 1;
sf::RenderWindow &_window;
- Scene(sf::RenderWindow &window) : _window(window) {}
+ Scene(sf::RenderWindow &window, Type _type) : type(_type), _window(window) {}
};
#endif
diff --git a/src/main/headers/Tile.hpp b/src/main/headers/Tile.hpp
index 7292fde..919badc 100644
--- a/src/main/headers/Tile.hpp
+++ b/src/main/headers/Tile.hpp
@@ -1,6 +1,8 @@
#ifndef TILE_HPP
#define TILE_HPP
+#include "Actor.hpp"
+
struct Tile
{
enum Type
@@ -12,6 +14,15 @@ struct Tile
const int x, y;
Tile(Type _type, int _x, int _y) : type(_type), x(_x), y(_y) {}
+
+ Actor* actor() { return _actor; }
+ bool actor(Actor *actor);
+
+ void clearActor() { _actor = nullptr; }
+
+private:
+ Actor *_actor = nullptr;
+
};
#endif
diff --git a/src/main/headers/WorldScene.hpp b/src/main/headers/WorldScene.hpp
index 09f3120..ec12930 100644
--- a/src/main/headers/WorldScene.hpp
+++ b/src/main/headers/WorldScene.hpp
@@ -10,8 +10,8 @@
class WorldScene : public Scene
{
public:
- constexpr static int ZOOM_MIN = 1;
- constexpr static int ZOOM_MAX = 100;
+ constexpr static float MAX_ZOOM = 10;
+ constexpr static float MIN_ZOOM = 1/2.0;
constexpr static int DEFAULT_TILE_SIZE_PX = 20;
WorldScene(sf::RenderWindow &window);