Sign in to follow this  
kiketom

New Map structure

Recommended Posts

Is correct this map structure??
class Map
{
	private:
		
		
	public:
		vector<Layer*> vectorLayers;	
		// class constructor
		Map();
		// class destructor
		~Map();
		


};


class Layer
{
	public:
		int numRowsLayer; // 
		int numColsLayer; // 

		// class constructor
		Layer();
		// class destructor
		~Layer();

		SDL_Surface *imageTiles;

		vector<Tile*> vectorTiles;
		
};


class Tile
{
	private:
		bool walkable;
		int imageNumber;
	public:
		// class constructor
		Tile();
		// class destructor
		~Tile();
		
		void SetWalkable(bool value) { walkable = value; };
		bool IsWalkable() { return walkable; };
		
		void SetImageNumber(int number) { imageNumber = number; }; 
		int GetImageNumber() { return imageNumber; };
};


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Looks ok, but you may want to split the SDL surface (view) from the Layer class (game data). This would let you write a "DrawMap" functions that uses SDL, and a "LoadGameData" function that is independent of SDL completely. The "DrawMap" class would be responsible for rendering/caching the various layers (and various game objects/characters), hiding all this crap from the game logic.

Share this post


Link to post
Share on other sites
Ok, i will change the "SDL_Surface *imageTiles" in the Layer to a char[] that contains the name of the image file.

And i'm implementing a Map.Save() function with the TinyXML library.



bool Map::Save()
{
char docxml[10000] =
"<?xml version=\"1.0\" ?>"
"<map>";


for (int i=0; i<vectorLayers.size(); i++)
{
strcat(docxml,"<layer>");
for(int iRows= 0; iRows<vectorLayers[i]->GetRowsLayer(); iRows++)
{
for(int iColumns = 0; iColumns <vectorLayers[i]->GetColsLayer(); iColumns ++)
{
char cadena[500];
sprintf(cadena, "<tile imageIndex=%d walkable=%d></tile>",vectorLayers[i]->vectorTiles[(iRows* vectorLayers[i]->GetColsLayer()) + iColumns]->GetImageNumber(),vectorLayers[i]->vectorTiles[(iRows* vectorLayers[i]->GetColsLayer()) + iColumns]->IsWalkable()?1:0 );
strcat(docxml,cadena);
}
}
strcat(docxml,"</layer>");
}

strcat(docxml,"</map>");


TiXmlDocument doc( "map.xml" );
doc.Parse( docxml);
doc.SaveFile();
return true;
}

Share this post


Link to post
Share on other sites

struct sTile {
std::vector<int> tiles;
bool walkable;
};

sTile map[100][100];



You dont have to add semi-colons to the closing bracket of a function definition. =)

Share this post


Link to post
Share on other sites
You are telling me that change

vector<Tile*> vectorTiles; in the Layer class

with this??? [oh]


struct sTile {
std::vector<int> tiles;
bool walkable;
};

sTile map[100][100];



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this