diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-06 19:18:33 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-02-06 19:18:33 +0000 |
commit | 819c303db467086d714ad663b285b44cde6329cf (patch) | |
tree | c32af1bb58379bfc790fd27fe2e4889ffab36df5 /src | |
parent | 5ec4143bde0fd67c7aca841804a5d165c794bdf0 (diff) | |
download | mana-client-819c303db467086d714ad663b285b44cde6329cf.tar.gz mana-client-819c303db467086d714ad663b285b44cde6329cf.tar.bz2 mana-client-819c303db467086d714ad663b285b44cde6329cf.tar.xz mana-client-819c303db467086d714ad663b285b44cde6329cf.zip |
Mostly making map tile data dynamically allocated.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/astar.cpp | 18 | ||||
-rw-r--r-- | src/astar.h | 7 | ||||
-rw-r--r-- | src/gui/minimap.cpp | 16 | ||||
-rw-r--r-- | src/gui/minimap.h | 5 | ||||
-rw-r--r-- | src/map.cpp | 30 | ||||
-rw-r--r-- | src/map.h | 26 |
7 files changed, 62 insertions, 41 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 96d2d574..9e4aff80 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,7 @@ tmw_SOURCES = sound/sound.cpp \ gui/itemcontainer.cpp \ gui/listbox.cpp \ gui/login.cpp \ + gui/minimap.cpp \ gui/npc.cpp \ gui/npc_text.cpp \ gui/ok_dialog.cpp \ diff --git a/src/astar.cpp b/src/astar.cpp index f3e8acb0..d121ca1f 100644 --- a/src/astar.cpp +++ b/src/astar.cpp @@ -6,6 +6,10 @@ #define WALKABLE 0 #define NOT_WALKABLE 1 +#define NOT_STARTED 0 +#define FOUND 1 +#define NOT_FOUND 2 + // path-related constants const int numberPeople = 1; int onClosedList = 10; @@ -470,17 +474,3 @@ PATH_NODE *find_path(int pathfinderID, int s_x, int s_y, int e_x, int e_y) // Path not found return NULL; } - -void ReadPath(int pathfinderID) -{ - // If a path exists, read the path data from the pathbank. - // Set pathLocation to 1st step - pathLocation = 1; - while (pathLocation<pathLength) { - int a = path_bank[pathLocation * 2 - 2]; - int b = path_bank[pathLocation * 2 - 1]; - pathLocation = pathLocation + 1; - // Draw dotted path - whichList[a][b] = 3; - } -} diff --git a/src/astar.h b/src/astar.h index fe4820e0..fbe45aae 100644 --- a/src/astar.h +++ b/src/astar.h @@ -4,14 +4,7 @@ #include "map.h" #include "being.h" -#define NOT_STARTED 0 -#define FOUND 1 -#define NOT_FOUND 2 - PATH_NODE *find_path(int pathfinderID, int startingX, int startingY, int targetX, int targetY); -/** Read the path data */ -void ReadPath(int pathfinderID); - #endif diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index a1104b8a..a58ed83c 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -18,7 +18,7 @@ * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $IdS + * $Id$ */ #define MINIMAP_W 100 @@ -52,11 +52,12 @@ void Minimap::draw(gcn::Graphics *graphics) getAbsolutePosition(x, y); - if ( (mapBackground->w != getWidth()) || (mapBackground->h != getHeight()) ) + if ((mapBackground->w != getWidth()) || (mapBackground->h != getHeight())) { SDL_FreeSurface(mapBackground); - mapBackground = SDL_AllocSurface(SDL_SWSURFACE, getWidth(), getHeight(), - (screen->format->BytesPerPixel*8), 0, 0, 0, 0); + mapBackground = SDL_AllocSurface(SDL_SWSURFACE, + getWidth(), getHeight(), + (screen->format->BytesPerPixel * 8), 0, 0, 0, 0); Uint32 mapColor = SDL_MapRGB(screen->format, 52, 149, 210); SDL_Rect sourceRect; sourceRect.x = sourceRect.y = 0; @@ -75,10 +76,11 @@ void Minimap::draw(gcn::Graphics *graphics) screenRect.h = getHeight(); screenRect.x = x; screenRect.y = y; - if ( mapBackground ) SDL_BlitSurface(mapBackground, NULL, screen, &screenRect); + if (mapBackground) + SDL_BlitSurface(mapBackground, NULL, screen, &screenRect); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); graphics->setColor(gcn::Color(209, 52, 61)); - graphics->fillRectangle(gcn::Rectangle(player_node->x /2, + graphics->fillRectangle(gcn::Rectangle(player_node->x / 2, player_node->y / 2, 3, 3)); -}
\ No newline at end of file +} diff --git a/src/gui/minimap.h b/src/gui/minimap.h index 08a39fb6..9e3792b9 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -43,8 +43,9 @@ class Minimap : public Window { * Draws the minimap. */ void draw(gcn::Graphics *graphics); - - // The Alpha-Blended Surface for the background transluency effect. + + private: + /** The Alpha-Blended Surface for the background transluency effect. */ SDL_Surface *mapBackground; }; 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; +} @@ -24,6 +24,8 @@ #ifndef _TMW_MAP_H #define _TMW_MAP_H +#include "being.h" + // Tile flags #define TILE_WALKABLE 1 #define TILE_ANIMATED 2 @@ -47,7 +49,17 @@ class Map { public: /** - * Loads a map file + * Constructor. + */ + Map(); + + /** + * Destructor. + */ + ~Map(); + + /** + * Loads a map file. */ bool load(char *mapFile); @@ -81,12 +93,14 @@ class Map */ int getHeight(); + /** + * Find a path from one location to the next. + */ + PATH_NODE *findPath(int startX, int startY, int destX, int destY); + private: - const static int width = 200; - const static int height = 200; - Tile tiles[width][height]; - char tileset[20]; - char bg_music[20]; + int width, height; + Tile *tiles; }; extern Map tiledMap; |