From 879c2c04d9c3879f871cfe79f9b25fd23c5184b4 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 11 Jun 2015 11:38:49 -0400 Subject: Wrote EntityManager --- src/map.cpp | 151 ------------------------------------------------------------ 1 file changed, 151 deletions(-) delete mode 100644 src/map.cpp (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp deleted file mode 100644 index e3725b2..0000000 --- a/src/map.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "map.h" -#include -#include -#include -#include "entityfactory.h" -#include "entity.h" -#include "game.h" -#include "consts.h" - -Map::Map(int id) -{ - this->id = id; - mapdata = (int*) calloc(1, sizeof(int)); -} - -Map::Map(const Map& map) -{ - mapdata = (int*) malloc(MAP_WIDTH*MAP_HEIGHT*sizeof(int)); - memcpy(mapdata, map.mapdata, MAP_WIDTH*MAP_HEIGHT*sizeof(int)); - - id = map.id; - title = map.title; - adjacents = map.adjacents; - entities = map.entities; -} - -Map::Map(Map&& map) : Map() -{ - swap(*this, map); -} - -Map::~Map() -{ - free(mapdata); -} - -Map& Map::operator= (Map map) -{ - swap(*this, map); - - return *this; -} - -void swap(Map& first, Map& second) -{ - std::swap(first.mapdata, second.mapdata); - std::swap(first.title, second.title); - std::swap(first.adjacents, second.adjacents); - std::swap(first.id, second.id); - std::swap(first.entities, second.entities); -} - -int Map::getID() const -{ - return id; -} - -const int* Map::getMapdata() const -{ - return mapdata; -} - -std::string Map::getTitle() const -{ - return title; -} - -void Map::createEntities(std::list>& entities) const -{ - for (auto data : this->entities) - { - auto entity = EntityFactory::createNamedEntity(data.name, data.items); - entity->position = data.position; - - entities.push_back(entity); - } -} - -bool Map::operator==(const Map& other) const -{ - return id == other.id; -} - -bool Map::operator!=(const Map& other) const -{ - return id != other.id; -} - -Map::MoveType Map::moveTypeForShort(std::string str) -{ - if (str == "wrap") return MoveType::Wrap; - if (str == "warp") return MoveType::Warp; - if (str == "reverseWarp") return MoveType::ReverseWarp; - - return MoveType::Wall; -} - -Map::MoveDir Map::moveDirForShort(std::string str) -{ - if (str == "right") return MoveDir::Right; - if (str == "up") return MoveDir::Up; - if (str == "down") return MoveDir::Down; - - return MoveDir::Left; -} - -static const Map::Adjacent defaultAdjacent {}; -const Map::Adjacent& Map::getAdjacent(MoveDir dir) const -{ - if (adjacents.count(dir) > 0) - { - return adjacents.at(dir); - } else { - return defaultAdjacent; - } -} - -bool Map::moveTypeTakesMap(MoveType type) -{ - switch (type) - { - case MoveType::Wall: return false; - case MoveType::Wrap: return false; - case MoveType::Warp: return true; - case MoveType::ReverseWarp: return true; - } -} - -void Map::setMapdata(int* mapdata) -{ - free(this->mapdata); - this->mapdata = mapdata; -} - -void Map::setTitle(std::string title) -{ - this->title = title; -} - -void Map::setAdjacent(MoveDir dir, MoveType type, int map) -{ - Adjacent& cur = adjacents[dir]; - cur.type = type; - if (map != -1) cur.map = map; -} - -void Map::addEntity(EntityData& data) -{ - entities.push_back(data); -} - -- cgit 1.4.1