diff options
Diffstat (limited to 'src/model/Map.cpp')
-rw-r--r-- | src/model/Map.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/model/Map.cpp b/src/model/Map.cpp index a5b5ee9..b7b40f5 100644 --- a/src/model/Map.cpp +++ b/src/model/Map.cpp @@ -31,20 +31,22 @@ namespace RPGEdit { namespace Model { -Position Map::getEntityPosition(const Entity *entity, uint64_t time) const { +Position<float> Map::getEntityPosition(const Entity *entity, uint64_t time) const { const EntityState &state = entityStates.at(entity); + Position<float> p(state.position); + if (state.transitionEnd) if (time <= state.transitionStart) - return state.position; + return p; else if (time >= state.transitionEnd) - return state.position + state.direction; + return p + state.direction; else - return state.position.translate(state.direction, - float(time-state.transitionStart)/ - float(state.transitionEnd-state.transitionStart)); + return p.translate(state.direction, + float(time-state.transitionStart)/ + float(state.transitionEnd-state.transitionStart)); else - return state.position; + return p; } bool Map::moveEntity(Entity *entity, Direction dir, uint64_t start, uint64_t end) { @@ -55,7 +57,7 @@ bool Map::moveEntity(Entity *entity, Direction dir, uint64_t start, uint64_t end entity->setDirection(dir); - Position pos = state.position + dir; + Position<int> pos = state.position + dir; if (getCollisionAt(pos.x, pos.y) == BLOCKED) return false; @@ -69,7 +71,7 @@ bool Map::moveEntity(Entity *entity, Direction dir, uint64_t start, uint64_t end return true; } -void Map::moveEntityTo(Entity *entity, Position pos) { +void Map::moveEntityTo(Entity *entity, Position<int> pos) { EntityState &state = entityStates.at(entity); setCollisionAt(state.position.x, state.position.y, EMPTY); @@ -110,7 +112,7 @@ std::unique_ptr<Map> Map::load(__attribute__((unused)) const std::string &name) } } - map->addEntity("square", Model::Position{6, 6}); + map->addEntity("square", Model::Position<int>{6, 6}); return map; } |