diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/Direction.hpp | 8 | ||||
-rw-r--r-- | src/model/Entity.hpp | 23 | ||||
-rw-r--r-- | src/model/Map.cpp | 6 | ||||
-rw-r--r-- | src/model/Map.hpp | 5 |
4 files changed, 38 insertions, 4 deletions
diff --git a/src/model/Direction.hpp b/src/model/Direction.hpp index c1cb269..db288f6 100644 --- a/src/model/Direction.hpp +++ b/src/model/Direction.hpp @@ -27,9 +27,17 @@ #pragma once +namespace RPGEdit { + +namespace Model { + enum Direction { NORTH, EAST, SOUTH, WEST, }; + +} + +} diff --git a/src/model/Entity.hpp b/src/model/Entity.hpp index 518ce5f..a61ae21 100644 --- a/src/model/Entity.hpp +++ b/src/model/Entity.hpp @@ -63,10 +63,31 @@ public: return dir; } - void move(float newX, float newY) { + void moveTo(float newX, float newY) { x = newX; y = newY; } + + void move(Direction direction, float amount = 1) { + dir = direction; + + switch (direction) { + case NORTH: + y -= amount; + break; + + case EAST: + x += amount; + break; + + case SOUTH: + y += amount; + break; + + case WEST: + x -= amount; + } + } }; } diff --git a/src/model/Map.cpp b/src/model/Map.cpp index 9cbe880..48f5669 100644 --- a/src/model/Map.cpp +++ b/src/model/Map.cpp @@ -45,10 +45,10 @@ std::shared_ptr<Map> Map::load(__attribute__((unused)) const std::string &name) } } - std::shared_ptr<Entity> square(new Entity("square")); - square->move(6, 6); + map->playerEntity.reset(new Entity("square")); + map->playerEntity->moveTo(6, 6); - map->entities.push_back(square); + map->entities.push_back(map->playerEntity); return map; } diff --git a/src/model/Map.hpp b/src/model/Map.hpp index e01d9c4..5d6ba01 100644 --- a/src/model/Map.hpp +++ b/src/model/Map.hpp @@ -46,6 +46,7 @@ private: size_t width, height; std::unique_ptr<uint32_t[]> tiles; + std::shared_ptr<Entity> playerEntity; mutable std::deque<std::shared_ptr<Entity>> entities; @@ -66,6 +67,10 @@ public: return entities; } + Entity & getPlayerEntity() const { + return *playerEntity; + } + size_t getWidth() const { return width; } |