From 819c303db467086d714ad663b285b44cde6329cf Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 6 Feb 2005 19:18:33 +0000 Subject: Mostly making map tile data dynamically allocated. --- src/map.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index b913beae..d2b1590e 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -79,6 +79,17 @@ Tile::Tile(): } +Map::Map(): + width(200), height(200) +{ + tiles = new Tile[width * height]; +} + +Map::~Map() +{ + delete[] tiles; +} + bool Map::load(char *mapFile) { FILE *file = fopen(mapFile, "r"); @@ -125,15 +136,15 @@ bool Map::load(char *mapFile) { void Map::setWalk(int x, int y, bool walkable) { if (walkable) { - tiles[x][y].flags |= TILE_WALKABLE; + tiles[x + y * width].flags |= TILE_WALKABLE; } else { - tiles[x][y].flags &= ~TILE_WALKABLE; + tiles[x + y * width].flags &= ~TILE_WALKABLE; } } bool Map::getWalk(int x, int y) { - bool ret = (tiles[x][y].flags & TILE_WALKABLE) != 0; + bool ret = (tiles[x + y * width].flags & TILE_WALKABLE) != 0; if (ret) { // Check for colliding into a being @@ -152,12 +163,12 @@ bool Map::getWalk(int x, int y) { void Map::setTile(int x, int y, int layer, int id) { - tiles[x][y].layers[layer] = id; + tiles[x + y * width].layers[layer] = id; } int Map::getTile(int x, int y, int layer) { - return tiles[x][y].layers[layer]; + return tiles[x + y * width].layers[layer]; } int Map::getWidth() @@ -169,3 +180,12 @@ int Map::getHeight() { return height; } + +PATH_NODE *Map::findPath(int startX, int startY, int destX, int destY) +{ + // Return when destination not walkable + if (!getWalk(destX, destY)) return NULL; + + // No path found + return NULL; +} -- cgit v1.2.3-60-g2f50