diff options
Diffstat (limited to 'src/model/Map.cpp')
-rw-r--r-- | src/model/Map.cpp | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/model/Map.cpp b/src/model/Map.cpp index b7b40f5..749b25f 100644 --- a/src/model/Map.cpp +++ b/src/model/Map.cpp @@ -57,13 +57,9 @@ bool Map::moveEntity(Entity *entity, Direction dir, uint64_t start, uint64_t end entity->setDirection(dir); - Position<int> pos = state.position + dir; - - if (getCollisionAt(pos.x, pos.y) == BLOCKED) + if (isBlocked(state.position + dir)) return false; - setCollisionAt(pos.x, pos.y, BLOCKED); - state.transitionStart = start; state.transitionEnd = end; state.direction = dir; @@ -74,12 +70,11 @@ bool Map::moveEntity(Entity *entity, Direction dir, uint64_t start, uint64_t end void Map::moveEntityTo(Entity *entity, Position<int> pos) { EntityState &state = entityStates.at(entity); - setCollisionAt(state.position.x, state.position.y, EMPTY); - setCollisionAt(pos.x, pos.y, BLOCKED); + removeEntityPosition(state.position, entity); + addEntityPosition(pos, entity); state.position = pos; state.transitionStart = state.transitionEnd = 0; - } void Map::finishEntityTransition(Entity *entity) { @@ -98,17 +93,17 @@ std::unique_ptr<Map> Map::load(__attribute__((unused)) const std::string &name) for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { if (4 <= i && i < 12 && 4 <= j && j < 12) { - map->setTileAt(0, i, j, 1); - map->setCollisionAt(i, j, EMPTY); + map->setTileAt(0, Position<int>{i, j}, 1); + map->setCollisionAt(Position<int>{i, j}, CollisionType::EMPTY); } else { - map->setTileAt(0, i, j, 0); + map->setTileAt(0, Position<int>{i, j}, 0); } if (4 <= i && i < 12 && j == 8) - map->setTileAt(1, i, j, 2); + map->setTileAt(1, Position<int>{i, j}, 2); else - map->setTileAt(1, i, j, 0); + map->setTileAt(1, Position<int>{i, j}, 0); } } |