summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-02-06 19:18:33 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-02-06 19:18:33 +0000
commit819c303db467086d714ad663b285b44cde6329cf (patch)
treec32af1bb58379bfc790fd27fe2e4889ffab36df5 /src/map.cpp
parent5ec4143bde0fd67c7aca841804a5d165c794bdf0 (diff)
downloadMana-819c303db467086d714ad663b285b44cde6329cf.tar.gz
Mana-819c303db467086d714ad663b285b44cde6329cf.tar.bz2
Mana-819c303db467086d714ad663b285b44cde6329cf.tar.xz
Mana-819c303db467086d714ad663b285b44cde6329cf.zip
Mostly making map tile data dynamically allocated.
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp30
1 files changed, 25 insertions, 5 deletions
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;
+}